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
>>> with InMemoryStore() as store:
... 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 interface for storing dict values under string keys, with both
synchronous and a-prefixed asynchronous methods on every store:
- Uniform API across backends:
get/aget,get_many/aget_many,set/aset,set_many/aset_many,delete/adelete,filter/afilter, iteration - Backends:
InMemoryStore,SQLiteStore,DuckDBStore,LmdbStore,RedisStore,PostgresStore - Typed variants (
TypedSQLiteStore,TypedPostgresStore, ...) and pickle-backed variants (PickleLmdbStore,PickleRedisStore) for non-dict values - Configurable conflict handling on writes (
"raise","skip","overwrite","merge")
⏱️ TTL Caching
Time-to-live caching for functions and values, with sync and async variants:
Cache, with sync and async (a-prefixed) methods, for explicit cache instancescached/async_cacheddecorators for caching function calls- A shared default cache via
get_cache
🌐 HTTP Utilities
Helpers to fetch HTTP responses with automatic retries, built on top of requests or httpx:
fetch_response(sync,requests);get_response/post_response/put_response/patch_response/delete_response/send_request(sync,httpx) and their_asynccounterparts (async,httpx)HttpClient/AsyncHttpClient: class-based wrappers aroundhttpx.Client/httpx.AsyncClientwith the same retries, plus optional response caching via aCache
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 |
Sync/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
⚠️ 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.
Metadata
Release files for persista 0.0.3
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 |
|---|---|---|---|---|
| persista-0.0.3.tar.gz | 69.2 kB | Without provenance | Details for persista-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| persista-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for persista-0.0.3-py3-none-any.whl |
Total release size: 172.2 kB
Release files / persista-0.0.3.tar.gz
| Download URL | persista-0.0.3.tar.gz |
|---|---|
| Size | 69.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a579fe930b82b2ba31351f0df5ed835daf940fcdf2a5b3c4139f3da8873a6fa
|
|
BLAKE2b-256 checksum How to use checksums |
d7fcd1de45aaa2fa4e0a7ad10243b690fa8c010380f19aa1e3d7a8d69af7cca1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / persista-0.0.3-py3-none-any.whl
| Download URL | persista-0.0.3-py3-none-any.whl |
|---|---|
| Size | 103.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d7706030a9214804c62e9cfb3a6f91746cf1a5795c5b8d6b32f2fc814b4373c
|
|
BLAKE2b-256 checksum How to use checksums |
15b085ef42fead66c5b9b998203dee409973a6cdc23d6c9ab0c7e30ec9e5916f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for persista 0.0.3
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.