skillfed

portalocker

Cross-platform file locking, with Redis, PID-file and bounded-semaphore locks

portalocker Permissive license BSD-3-Clause Active 325 v4.1.0 released

Install

portalocker on PyPI

pip

pip install portalocker

uv

uv add portalocker

poetry

poetry add portalocker

Package 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

Development Status :: 6 - MatureIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsNatural Language :: EnglishOperating System :: MacOSOperating System :: MacOS :: MacOS XOperating System :: MicrosoftOperating System :: Microsoft :: WindowsOperating System :: POSIXOperating System :: POSIX :: BSDOperating System :: POSIX :: BSD :: FreeBSDOperating System :: POSIX :: BSD :: NetBSDOperating System :: POSIX :: BSD :: OpenBSDOperating System :: POSIX :: LinuxOperating System :: POSIX :: SunOS/SolarisOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: ImplementationProgramming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: SystemTopic :: System :: Distributed ComputingTopic :: System :: FilesystemsTopic :: System :: MonitoringTyping :: Typed

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...

Read as markdown · JSON record · Source repository · Docs

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
file locking cross-platformpython file lockdistributed locks redispid file lockingexclusive shared locksconcurrent file accessmultiprocess file synchronization

Similar packages