portalocker
Cross-platform file locking, with Redis, PID-file and bounded-semaphore locks
Install
portalocker on PyPI
pip
pip install portalockeruv
uv add portalockerpoetry
poetry add portalockerPackage facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 11 days since the last release |
| Last repo commit | |
| First released | |
| Popularity | one of the top 1,000 most-downloaded packages on PyPI (30-day window, as of 2026-08-13) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-13) |
Evidence: portalocker-4.1.0-py3-none-any.whl
Keywords: locking, locks, with, statement, windows, linux, unix
About portalocker
from the package's own PyPI description — quoted content, verbatim
portalocker - Cross-platform locking library
.. image:: https://github.com/wolph/portalocker/actions/workflows/ci.yml/badge.svg?branch=develop :alt: CI Test Status :target: https://github.com/wolph/portalocker/actions/workflows/ci.yml
Overview
Portalocker is a library to provide an easy API to file locking.
Portalocker requires Python 3.10 or later.
An important detail to note is that on Linux and Unix systems the locks are
advisory by default. By specifying the -o mand option to the mount command it
is possible to enable mandatory file locking on Linux. This is generally not
recommended however. For more information about the subject:
- https://en.wikipedia.org/wiki/File_locking
- http://stackoverflow.com/questions/39292051/portalocker-does-not-seem-to-lock
- https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux
Windows and the pywin32 dependency
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Since version 4.0.0, pywin32 is no longer installed automatically on
Windows. Exclusive locks work out of the box without any extra
dependencies...
AI interpretation — verify before relying
AI-generated interpretation of the package facts above; every digit, version, license, or vulnerability id it cites is grounded in the facts already shown on this page
portalocker provides cross-platform file locking with an easy API, supporting exclusive and shared locks on Windows, Linux, Unix, and macOS, plus optional Redis-based distributed locks and PID-file locking for singleton patterns.
Installation is straightforward with low friction—portalocker is a pure Python wheel with no mandatory runtime dependencies. The package is actively maintained (last commit 2026-08-06, released 11 days ago) and classified as Mature. Note that shared locks on Windows require the optional pywin32 dependency, installable via the `win32` extra.
portalocker is licensed under BSD-3-Clause (permissive), allowing commercial and private use with minimal restrictions—only requiring preservation of copyright and license notices.
Usage
import portalocker
with portalocker.Lock('somefile', timeout=1) as fh:
fh.write('data')
Requires Python 3.10 or later. Shared locks on Windows require the optional pywin32 dependency (install via `pip install portalocker[win32]`).
Verdict: portalocker is a mature, actively maintained library with zero known vulnerabilities, low install friction, and permissive licensing. It is well-suited for applications needing cross-platform file locking or distributed locks via Redis. The Python 3.10+ requirement and optional Windows dependency for shared locks are the only considerations.
Needs verification
- Whether the Redis lock feature requires a running Redis server or if it works with the optional fakeredis test dependency in production
- Performance characteristics and scalability limits for high-contention locking scenarios
Similar packages
permissive · top 1,000 on PyPI
pywin32permissive · top 1,000 on PyPI
pybreakerpermissive · top 1,000 on PyPI
Send2Trashpermissive · top 1,000 on PyPI
filelockpermissive · top 100 on PyPI
lockfilepermissive · top 1,000 on PyPI
psutilpermissive · top 1,000 on PyPI
xxhashpermissive · top 1,000 on PyPI
hiredispermissive · top 1,000 on PyPI
poetrypermissive · top 1,000 on PyPI