Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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
>>> 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 instances
  • cached / async_cached decorators 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 _async counterparts (async, httpx)
  • HttpClient/AsyncHttpClient: class-based wrappers around httpx.Client/httpx.AsyncClient with the same retries, plus optional response caching via a Cache

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

: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.

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.3a8.tar.gz (69.2 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.3a8-py3-none-any.whl (103.0 kB view details)

Uploaded Python 3

File details

Details for the file persista-0.0.3a8.tar.gz.

File metadata

  • Download URL: persista-0.0.3a8.tar.gz
  • Upload date:
  • Size: 69.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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

Hashes for persista-0.0.3a8.tar.gz
Algorithm Hash digest
SHA256 c6f503545bd6779743262b02bc28fd46d79be3b18bbd2a4b256f670ed99392c9
MD5 acbc985868324f80789951c1f453429b
BLAKE2b-256 0af532ee53eb273a31f3122de2e53b172c43c9d51d6d9edff129effac12446af

See more details on using hashes here.

File details

Details for the file persista-0.0.3a8-py3-none-any.whl.

File metadata

  • Download URL: persista-0.0.3a8-py3-none-any.whl
  • Upload date:
  • Size: 103.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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

Hashes for persista-0.0.3a8-py3-none-any.whl
Algorithm Hash digest
SHA256 5dfd79d7577d738de761e2b01132b59ecd23ee390d3b641a9561deb38ac036d9
MD5 ed2d2cb86552e0bd2b1f8ee08b356a59
BLAKE2b-256 29da236fa3cb8d1c7b1ed5e45ebc8c0f6831ee81a4fcb8876d44fa49276fb157

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 Sentry Error logging StatusPage Status page