aiorwlock
Read write lock for asyncio.
What it is and what it does
aiorwlock implements a read-write lock primitive for asyncio-based Python programs. It maintains separate locks for read and write operations: the read lock can be held by multiple concurrent reader tasks simultaneously, while the write lock is exclusive and blocks all other readers and writers. This design improves performance when data is read frequently but modified infrequently, since readers don't block each other.
The package is a direct port of a CPython patch and has been in production use since 2014. It supports a "fast path" mode that skips context switches when you're confident your locked code contains await statements, trading safety for minor performance gains. The default safe mode ensures fairness by allowing waiting tasks to acquire the lock even if the current holder doesn't yield control.
Use it for:
- Cache or configuration store that is read frequently but updated rarely
- Shared data structure in an async web service where reads vastly outnumber writes
- Coordinating access to a resource pool where multiple consumers read status but few modify state
- Implementing reader-writer patterns in async database connection managers
- Protecting mutable state in async event handlers where contention is primarily read-heavy
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides read-write locks for asyncio programs, allowing multiple concurrent readers or a single exclusive writer to synchronize access to shared data.
Yes. aiorwlock is a mature, actively maintained library with zero known vulnerabilities, low install friction, and permissive licensing. Install it if you have asyncio code where read-write contention patterns would benefit from allowing concurrent readers; otherwise a simple asyncio.Lock is sufficient.
Install
aiorwlock on PyPI
pip
pip install aiorwlockuv
uv add aiorwlockpoetry
poetry add aiorwlockInstalling aiorwlock
Before you install
Low install friction with no runtime dependencies. Actively maintained with recent commits and a stable release history since 2014; supports current Python versions (3.9 through 3.14).
License in practice
Licensed under Apache 2.0 (permissive), allowing use in both open-source and proprietary projects with minimal restrictions.
Quickstart
import asyncio
import aiorwlock
async def example():
rwlock = aiorwlock.RWLock()
async with rwlock.reader_lock:
print('reader holds lock')
async with rwlock.writer_lock:
print('writer holds lock')
asyncio.run(example())
Requires Python 3.9 or later. The task that acquires a lock must also release it; acquiring in one task and releasing in another raises RuntimeError.
Verify before relying
- Performance characteristics compared to simple mutual exclusion locks under various read/write ratios
- Thread-safety guarantees or limitations when used across multiple event loops
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 175 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,345,391/month — #4,022 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aiorwlock-1.5.1-py3-none-any.whl
Keywords: aiorwlock, lock, asyncio
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
aiologicaiologic provides thread-aware and async-aware…
permissive · top 5,000 on PyPI
fifolockFifolock provides a low-level building block…
permissive · top 15,000 on PyPI
readerwriterlockProvides reader-writer lock implementations for…
permissive · top 5,000 on PyPI
fastrlockA C-level re-entrant lock for CPython that…
permissive · top 5,000 on PyPI
fastenersProvides cross-platform locks for synchronizing…
permissive · top 5,000 on PyPI
locketLocket provides file-based locks for…
permissive · top 1,000 on PyPI
portalockerPortalocker provides cross-platform file…
permissive · top 1,000 on PyPI
PyMySQLLockProvides distributed locking primitives backed…
permissive · top 15,000 on PyPI
python-dynamodb-lockProvides distributed locking on top of DynamoDB…
permissive · top 15,000 on PyPI
asyncio-poolManages a pool of concurrent asyncio…
permissive · top 15,000 on PyPI