Skip to main content

library for persisting and caching data

Project description

persista

CI Nightly Tests Nightly Package Tests Codecov
Documentation Documentation
Code style: black Doc style: google Ruff try/except style: tryceratops
PYPI version Python BSD-3-Clause
Downloads Monthly downloads

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:

  • TTLCache and AsyncTTLCache for explicit cache instances
  • cached / async_cached decorators 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) and fetch_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

persista-0.0.1.tar.gz (45.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

persista-0.0.1-py3-none-any.whl (73.6 kB view details)

Uploaded Python 3

File details

Details for the file persista-0.0.1.tar.gz.

File metadata

  • Download URL: persista-0.0.1.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":"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}

File hashes

Hashes for persista-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ace2858049868948b8baba192b9d4bac610796ab8f65fe93bea76cf26a8f39b8
MD5 26d71d09d9182b99b8ead997333599be
BLAKE2b-256 ec8f546032608fe911792299ae40dbd470dc62be59d7727738fac8258025ad71

See more details on using hashes here.

File details

Details for the file persista-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: persista-0.0.1-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":"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}

File hashes

Hashes for persista-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5930f204589d156a1842430413b85254902f5e9ecb893a5df1f20109b14c4b2c
MD5 91f01fbabb1ccddde78949a87cff903c
BLAKE2b-256 cb2a9337ffc4bf4cc08be4b4d871af5a6bb5494188711c325a488085e528a309

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page