Panza
Panza is a Python library providing powerful caching and concurrency control for async functions.
Features
- Flexible Caching: Cache results of async functions with SQLite or S3 backends
- Concurrency Control: Limit concurrent executions of async functions
- Easy to Use: Simple decorator-based API
Installation
uv add git+https://github.com/corbt/panza.git
Quick Start
Caching
Panza offers two cache backends: SQLite for local development and S3 for distributed applications.
SQLite Cache
import asyncio
from panza import SQLiteCache
# Create a SQLite cache
cache = SQLiteCache("cache.db")
# Decorate your async function
@cache.cache(id="my_function")
async def fetch_data(param):
# Expensive operation
await asyncio.sleep(1)
return f"Result for {param}"
async def main():
# First call will execute and cache
result1 = await fetch_data("test")
print(result1) # Result for test
# Second call will return from cache
result2 = await fetch_data("test")
print(result2) # Result for test (from cache)
# You can bust the cache for specific parameters
await fetch_data.bust_cache("test")
# Or for the entire function
await fetch_data.bust_cache()
asyncio.run(main())
S3 Cache
from panza import S3Cache
# Create an S3 cache
cache = S3Cache(
"my-bucket/cache-prefix",
auto_create_bucket=True,
region_name="us-west-2"
)
@cache.cache(id="my_function")
async def fetch_data(param):
# Expensive operation
return f"Result for {param}"
Custom Hash Function
You can provide a custom hash function to control how cache keys are generated:
@cache.cache(
id="my_function",
hash_func=lambda param: f"custom_key_{param}"
)
async def fetch_data(param):
# ...
Limiting Concurrency
The limit_concurrency decorator prevents too many instances of a function from running at once:
from panza import limit_concurrency
# Limit to 5 concurrent executions
@limit_concurrency(5)
async def process_item(item):
await asyncio.sleep(1)
return f"Processed {item}"
# With key-based limiting (limit per key)
@limit_concurrency(3, derive_key=lambda user_id, *args, **kwargs: f"user_{user_id}")
async def process_user_data(user_id, data):
await asyncio.sleep(1)
return f"Processed data for user {user_id}"
Combining Features
You can combine caching and concurrency limiting:
from panza import SQLiteCache, limit_concurrency
cache = SQLiteCache("cache.db")
@limit_concurrency(5)
@cache.cache(id="fetch_and_process")
async def fetch_and_process(item_id):
# Expensive operation with limited concurrency and caching
return result
Advanced Usage
Reading from Cache Without Execution
Use .read_cache() to check if a result is cached without executing the function:
@cache.cache(id="expensive_function")
async def expensive_function(param):
await asyncio.sleep(5) # Simulate expensive operation
return f"Computed result for {param}"
# Check cache without executing
cache_hit, result = await expensive_function.read_cache("test")
if cache_hit:
print(f"Found in cache: {result}")
else:
print("Not in cache")
# Optionally execute now
result = await expensive_function("test")
Direct Cache Access
# Set arbitrary values
await cache.set("my_key", "my_value")
# Get values (raises KeyError if not found)
value = await cache.get("my_key")
# Clear the entire cache
await cache.bust_all()
Metadata
Release files for panza 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| panza-0.2.2.tar.gz | 11.0 kB | Without provenance | Details for panza-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| panza-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for panza-0.2.2-py3-none-any.whl |
Total release size: 23.2 kB
Release files / panza-0.2.2.tar.gz
| Download URL | panza-0.2.2.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
297c03e3338e86c205c1fc632754fb3b65193864b146c32bd6bad64c5be5c21f
|
|
BLAKE2b-256 checksum How to use checksums |
384a02a31de07402547144c5e11e0d457bcd8b2cbc135d5697dec4af0099faec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / panza-0.2.2-py3-none-any.whl
| Download URL | panza-0.2.2-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6905cffeb96f92abf122803bc3d49c9a4a15d6cca659e3467a518187445288a3
|
|
BLAKE2b-256 checksum How to use checksums |
b3de082d490ae48a95c6556bed42ece266823f5d748ffea15ae0abdb04e143bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for panza 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.