library for persisting and caching data
Project description
persista
Overview
persista is a lightweight Python library that provides simple, consistent building blocks for
persisting and caching data. It offers a uniform key-value store interface backed by multiple
storage engines (in-memory, SQLite, DuckDB, LMDB, Redis, PostgreSQL) with both sync and async
APIs, plus TTL caching and HTTP fetch utilities.
Quick Links:
Why persista?
Storage backends have different APIs, and switching between them (e.g. moving from an in-memory
store in tests to Redis or PostgreSQL in production) usually means rewriting code. persista
solves this with a single, consistent BaseStore interface:
Store and retrieve values:
>>> from persista.store import InMemoryStore
>>> store = InMemoryStore()
>>> store.set("user:1", {"name": "Alice"})
>>> store.get("user:1")
{'name': 'Alice'}
Swap the backend without changing the calling code:
>>> import tempfile
>>> from pathlib import Path
>>> from persista.store import SQLiteStore
>>> with tempfile.TemporaryDirectory() as tmpdir:
... with SQLiteStore(Path(tmpdir).joinpath("data.sqlite")) as store:
... store.set("user:1", {"name": "Alice"})
... store.get("user:1")
...
{'name': 'Alice'}
Cache expensive calls with a TTL:
>>> from persista.cache import cached
>>> @cached(ttl=60)
... def slow_call(x: int) -> int:
... return x**2
...
>>> slow_call(4)
16
See the documentation for detailed examples.
Features
persista provides a comprehensive set of utilities for persisting and caching data:
🗄️ Key-Value Stores
A consistent BaseStore / AsyncBaseStore interface for storing dict values under string keys:
- Uniform API across backends:
get,get_many,set,set_many,delete,filter, iteration - Sync backends:
InMemoryStore,SQLiteStore,DuckDBStore,LmdbStore,RedisStore,PostgresStore - Async backends:
AsyncInMemoryStore,AsyncSQLiteStore,AsyncRedisStore,AsyncPostgresStore - Typed variants (
TypedSQLiteStore,TypedPostgresStore, ...) and pickle-backed variants (PickleLmdbStore,PickleRedisStore,AsyncPickleRedisStore) for non-dict values - Configurable conflict handling on writes (
"raise","skip","overwrite")
⏱️ TTL Caching
Time-to-live caching for functions and values, with sync and async variants:
TTLCacheandAsyncTTLCachefor explicit cache instancescached/async_cacheddecorators for caching function calls- Shared default caches via
get_ttl_cache/get_async_ttl_cache
🌐 HTTP Utilities
Helpers to fetch HTTP responses with automatic retries, built on top of requests or httpx:
fetch_response(sync,requests) andfetch_response_async(async,httpx)
Installation
We highly recommend installing persista in
a virtual environment
to avoid dependency conflicts.
Using uv (recommended)
uv is a fast Python package installer and resolver:
uv pip install persista
Install with specific optional dependencies:
uv pip install persista[redis,httpx] # with Redis and httpx support
Using pip
Alternatively, you can use pip:
pip install persista
Install with specific optional dependencies:
pip install persista[redis,httpx] # with Redis and httpx support
Requirements
- Python: 3.10 or higher
- Core dependencies:
coola
Optional dependencies, enabled per-backend:
| Extra | Enables |
|---|---|
aiosqlite |
Async SQLite store |
duckdb |
DuckDB store |
faker |
Test data generation helpers |
httpx |
Async HTTP fetch utilities |
lmdb |
LMDB store |
psycopg |
PostgreSQL store |
redis |
Redis store |
requests |
Sync HTTP fetch utilities |
rich |
Rich-formatted output |
urllib3 |
urllib3-based HTTP utilities |
For detailed installation instructions, see the documentation.
Contributing
Contributions are welcome! We appreciate bug fixes, feature additions, documentation improvements, and more. Please check the contributing guidelines for details on:
- Setting up the development environment
- Code style and testing requirements
- Submitting pull requests
Whether you're fixing a bug or proposing a new feature, please open an issue first to discuss your changes.
API Stability
:warning: Important: As persista is under active development, its API is not yet stable and may
change between releases. We recommend pinning a specific version in your project’s dependencies to
ensure consistent behavior.
License
persista is licensed under BSD 3-Clause "New" or "Revised" license available in LICENSE
file.
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 persista-0.0.1a1.tar.gz.
File metadata
- Download URL: persista-0.0.1a1.tar.gz
- Upload date:
- Size: 45.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
303f252cc04b00c0544c86eec2f989bb6a68e984a97c5326a089993c80671006
|
|
| MD5 |
5701c203c0031241c8570a9520e083d2
|
|
| BLAKE2b-256 |
3af933a65330f4ab18a76764892212eb0c985707501535cd41371785e1dfe45e
|
File details
Details for the file persista-0.0.1a1-py3-none-any.whl.
File metadata
- Download URL: persista-0.0.1a1-py3-none-any.whl
- Upload date:
- Size: 73.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
070dd654261fe671813205f29cba7c73d916b3a28fa24df6ffcfd83c5cb31031
|
|
| MD5 |
b6acc9a19c92c1a3ec332e93980c282c
|
|
| BLAKE2b-256 |
13782934c8165ad0036781bd34199a0172b409f139e11b68bbbad2d629d43d01
|