skillfed

aiorwlock

Read write lock for asyncio.

aiorwlock v1.5.1 1.3M downloads/30d#4,022 on PyPI175
Permissive license Apache-2.0 Active released

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 aiorwlock

uv

uv add aiorwlock

poetry

poetry add aiorwlock

Installing 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

Development Status :: 5 - Production/StableFramework :: AsyncIOIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9

Tags

asyncio read write lockconcurrent reader writer lockasync rwlockasyncio synchronization primitiveasync mutual exclusionreader writer synchronizationasyncio lock multiple readers
asyncioconcurrencysynchronization

More Software Development packages