--- id: portalocker version: "4.1.0" license: BSD-3-Clause license_treatment: permissive maintenance: active --- # portalocker — Cross-platform file locking, with Redis, PID-file and bounded-semaphore locks License: permissive · Maintenance: active · Popularity: top 1,000 on PyPI ## Install pip install portalocker uv add portalocker poetry add portalocker ## Description ############################################ 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 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. 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. [View on SkillFed](https://skillfed.io/packages/portalocker) · [View on PyPI](https://pypi.org/project/portalocker/)