fastrlock
Fast, re-entrant optimistic lock implemented in Cython
What it is and what it does
FastRLock is a Cython-implemented re-entrant lock that serves as a drop-in replacement for threading.RLock. It optimizes for the common case where only one thread holds the lock by avoiding actual lock acquisition until a second thread contends for it, exploiting the GIL to make ownership checks atomic without system-level synchronization overhead.
The package provides both a Python API (compatible with threading.RLock) and a direct Cython C-API for use from other Cython modules. Benchmarks show it can be faster than stdlib RLock in single-threaded scenarios and under light contention, though performance relative to modern Python 3.4+ stdlib implementations varies by CPython version and optimization level. The Cython interface consistently outperforms the Python API by avoiding call overhead.
Use it for:
- Replace threading.RLock in latency-sensitive single-threaded or lightly-contended code paths where lock overhead matters.
- Use the Cython C-API from other Cython extensions to avoid Python call overhead in critical sections.
- Embed in libraries like Lupa that require fast, re-entrant synchronization primitives across multiple threads.
- Benchmark-driven optimization where profiling shows threading.RLock as a bottleneck in acquire/release-heavy workloads.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A C-level re-entrant lock for CPython that replaces threading.RLock with faster acquire/release cycles through optimistic locking and Cython implementation.
Yes, if you are optimizing a Cython codebase or have profiled threading.RLock as a bottleneck and target Python versions where it remains faster than stdlib. No, if you are on Python 3.4+ and using only the Python API—stdlib RLock is likely as fast or faster. The Cython API is the strongest use case. Install friction is moderate due to compilation, but wheels cover most platforms.
Install
fastrlock on PyPI
pip
pip install fastrlockuv
uv add fastrlockpoetry
poetry add fastrlockInstalling fastrlock
Before you install
Medium install friction due to compiled C extensions requiring platform-specific wheels. The package maintains broad wheel coverage across Python 2.7 through 3.11+ and multiple architectures (x86_64, i686, aarch64, arm64, Windows). Last release was 605 days ago; repository is not archived and remains active.
License in practice
MIT-style permissive license allows commercial and private use with minimal restrictions, typical for low-friction adoption in production systems.
Quickstart
from fastrlock import rlock
lock = rlock()
with lock:
# critical section
pass
Requires a C compiler and Python development headers at install time; pre-built wheels available for common platforms but source builds may fail without build tools.
Verify before relying
- Whether performance gains over threading.RLock remain significant in Python 3.4+ versions where stdlib RLock was substantially optimized.
- Current test coverage and whether the package is actively maintained beyond wheel rebuilds for new Python versions.
- Compatibility guarantees with CPython implementations other than CPython (PyPy, etc.).
Package facts
| License | MIT style (permissive) |
| Python support | not specified |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 605 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,221,732/month — #4,201 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: fastrlock-0.8.3-cp27-cp27m-manylinux_2_5_i686.manylinux1_i686.whl; fastrlock-0.8.3-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl; fastrlock-0.8.3-cp27-cp27mu-manylinux_2_5_i686.manylinux1_i686.whl; fastrlock-0.8.3-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl; fastrlock-0.8.3-cp310-cp310-macosx_11_0_universal2.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_24_i686.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_24_x86_64.whl; fastrlock-0.8.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl; fastrlock-0.8.3-cp310-cp310-musllinux_1_1_aarch64.whl; fastrlock-0.8.3-cp310-cp310-musllinux_1_1_x86_64.whl; fastrlock-0.8.3-cp310-cp310-win_amd64.whl; fastrlock-0.8.3-cp311-cp311-macosx_11_0_universal2.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_24_i686.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_24_x86_64.whl; fastrlock-0.8.3-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl; fastrlock-0.8.3-cp311-cp311-musllinux_1_1_aarch64.whl; fastrlock-0.8.3-cp311-cp311-musllinux_1_1_x86_64.whl; fastrlock-0.8.3-cp311-cp311-win_amd64.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
redlock-pyImplements Redis-based distributed locks using…
permissive · top 15,000 on PyPI
aiorwlockProvides read-write locks for asyncio programs,…
permissive · top 5,000 on PyPI
fastenersProvides cross-platform locks for synchronizing…
permissive · top 5,000 on PyPI
filelockProvides a platform-independent file locking…
permissive · top 100 on PyPI
redlockImplements the RedLock algorithm to provide…
permissive · top 15,000 on PyPI
locketLocket provides file-based locks for…
permissive · top 1,000 on PyPI
python-redis-lockProvides a Redis-backed distributed lock with a…
permissive · top 5,000 on PyPI
python-dynamodb-lockProvides distributed locking on top of DynamoDB…
permissive · top 15,000 on PyPI
PyMySQLLockProvides distributed locking primitives backed…
permissive · top 15,000 on PyPI
gilknockerMeasures GIL contention within a specific code…
unclear · top 5,000 on PyPI