Mid-execution distributed locking with zero boilerplate.
Project description
caesura 📜
Mid-execution distributed locking with zero boilerplate.
Standard distributed locks force you to wrap your entire function in a with block, even if you need heavy parsing or database lookups just to find out what needs locking. caesura lets you safely acquire locks mid-execution: yield signals exactly where the blocking I/O happens, and the decorator manages teardown—even on crash.
uv add caesura
Why
| Concept | Standard Context Managers | caesura |
|---|---|---|
| Lock Boundary | The entire function. | Exactly where it matters. |
| Deadlock Prevention | Manual ordering required. | Mathematically guaranteed via tuples. |
| Infrastructure Coupling | High (imports Redis/Postgres). | Zero (accepts any context manager). |
| Type Visibility | Lost behind the wrapper. | See-through: signature & return preserved. |
Usage
import caesura
@caesura.serialize
def process_webhook(payload):
parsed_data = heavy_json_parse(payload) # lock-free work first
yield redis.lock(f"user:{parsed_data.user_id}") # hand the lock to the decorator
db.update_balance(parsed_data.user_id) # resumes safely locked
return True # locks released on return — or on crash — via Python's ExitStack
Deadlock Prevention
Yield multiple resources as a tuple. caesura sorts them by their name (falling back to str()) and acquires them in an identical, deterministic order across all workers — making deadlocks mathematically impossible.
@caesura.serialize
def transfer_funds(sender_id, receiver_id):
yield (redis.lock(sender_id), redis.lock(receiver_id)) # sorted before acquiring
db.execute_transfer(sender_id, receiver_id)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file caesura-1.0.0.tar.gz.
File metadata
- Download URL: caesura-1.0.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d41b379cf22abcb34a5166ae21b59ffa3cb3c67829390b1628b5b4e3ddbb67b
|
|
| MD5 |
d9320f2de88ac0789d66e4642344c314
|
|
| BLAKE2b-256 |
dc9f50f774dc5ede5d97e0e527ad36124d34ad2be5b81bfdf47f8417410a571d
|
File details
Details for the file caesura-1.0.0-py3-none-any.whl.
File metadata
- Download URL: caesura-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ee0aa8882b3eb6a10c79034e4142dc8c98cd19917be5116aebcacbe96452b5d
|
|
| MD5 |
eebf7388def16e5ff0156c7a30d1fe97
|
|
| BLAKE2b-256 |
c9a54073f0de7edea2fc9eacd902215bb36430b03cf20b43fda1a770b21d11df
|