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:

  • Cache and AsyncCache for explicit cache instances
  • cached / async_cached decorators for caching function calls
  • Shared default caches via get_cache / get_async_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.3a0.tar.gz (50.4 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.3a0-py3-none-any.whl (81.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: persista-0.0.3a0.tar.gz
  • Upload date:
  • Size: 50.4 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

Hashes for persista-0.0.3a0.tar.gz
Algorithm Hash digest
SHA256 67b6f01e7efd1d0ab8a9bdb9a7314d19614f38ec01f98bd148bf3c7ada8a017c
MD5 37096d4eddd19b8c5d82e34afa89229d
BLAKE2b-256 bc80c40e49b01321b60008cf627bf24fded63c6c20d5cf6efe2fd01cd9c8c752

See more details on using hashes here.

File details

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

File metadata

  • Download URL: persista-0.0.3a0-py3-none-any.whl
  • Upload date:
  • Size: 81.1 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

Hashes for persista-0.0.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf24ed66c8bc30955fcf9d7ff4882da90437b5208e2049248bb2885c4ee30ef2
MD5 4dcec21b3888936c9b7c0a4fc908bc90
BLAKE2b-256 9e90606b318a0596a04c0aae846f4cfb1f1ea27750a03c9818deac012ec05a2d

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