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.2a0.tar.gz (47.3 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.2a0-py3-none-any.whl (75.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: persista-0.0.2a0.tar.gz
  • Upload date:
  • Size: 47.3 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.2a0.tar.gz
Algorithm Hash digest
SHA256 03a726e9fbbe6e81865849706e47616def9c756fe9f995fc642fad2d2489d271
MD5 f3034743695990a8aad37dc105caa4bc
BLAKE2b-256 d9e568f02490345b7de67bbb4fa4e6c4f70944560f1e7e2c19a43ca62a9b55e0

See more details on using hashes here.

File details

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

File metadata

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

Hashes for persista-0.0.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 89044d29f1a6b6867248b798d45694b4400744af191cc599aee57dc2aac69a67
MD5 cda385cef6790c60ca56c844ee71ba45
BLAKE2b-256 2054d0a8285e82e0128243cb88abc1e2c8c66f94af4a103dc9c8ee55c43bfd44

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