Skip to main content

Redis-based cross-process data sharing and caching library

Project description

gpdatacached

General-Purpose Data Cached

License: MIT Python Development Status

A Redis-based cross-process data sharing and caching library for Python. Any process that can reach the same Redis instance can share live, mutable, typed data structures — scalars, lists, dicts, sets — with reference semantics, lifecycle control, and optional distributed locking.

Read this in another language: 简体中文


Why

Sharing mutable state across processes is painful. multiprocessing.Manager is single-process-bottlenecked; raw Redis forces you to (de)serialize everything by hand and gives you no type safety, no reference tracking, no TTL cascades. gpdatacached gives you a dict-like API on top of Redis with:

  • Typed objects — store int, str, datetime, list, dict, set, … and get the same type back.
  • Live containersns["tags"].append("x") mutates Redis directly; no read-modify-write races on the whole structure.
  • Reference sharing — bind the same container under multiple names inside a namespace; the data is stored once.
  • Lifecycle control — per-object permanent / ttl / sliding-window cache modes, with cascade propagation to owned subtrees.
  • Background GC — reclaims expired and orphaned anonymous objects.
  • Opt-in distributed locking — serialize writes across processes with obj.lock().
  • Optional extensions — cache pydantic BaseModel records and pandas Series / DataFrame (see Extensions).

Install

pip install gpdatacached

Optional extras:

pip install "gpdatacached[pandas]"   # pandas DataFrame / Series support

Requirements: Python ≥ 3.10, Redis ≥ 5.0.


Quick Start

from gpdatacached import GPDCDomain, GPDCDomainConfig

config = GPDCDomainConfig(
    redis_host="127.0.0.1",
    redis_port=6379,
    redis_password="secret",
)
domain = GPDCDomain("mydomain", config)
ns = domain.ensure_namespace("analytics")

# Scalars read back as native Python values.
ns["counter"] = 42
assert ns["counter"] == 42

# Containers are live Redis-backed objects.
ns["tags"] = ["a", "b", "c"]
ns["tags"].append("d")
ns["tags"].pop(0)
assert ns["tags"].value == ["b", "c", "d"]

# Lifecycle control.
ns["temp"] = "x"
ns.get_object("temp").expire_in(60)   # requires cache_mode="ttl"

domain.close()

Core Concepts

GPDCDomain ── GPDCNamespace ── GPDCDataObject (scalar | container)
Concept Role
Domain Configuration root + Redis connection pool + lock/GC defaults.
Namespace Logical isolation space; behaves like a MutableMapping. Cross-namespace references are unsupported by design.
Data Object A named, typed value. Scalars return native Python values on read; containers return live objects.

Cache modes: permanent (default, never expires), ttl (fixed expiry), sliding (refreshed on every mutation).


Documentation

📖 Full documentation index — the entry point to all guides and references below.

  • Overview — design purpose, philosophy, and end-to-end architecture (start here to understand the library as a whole).
  • API Reference — complete public API reference.
  • Lifecycle Management — how object creation, expiry, refresh, and deletion work, including anonymous and reference objects (read this to set correct expectations).
  • Extensibility — the type system explained, with worked examples for adding your own scalar and container types (codecs, object classes, registration).
  • Performance Guide — usage patterns that degrade performance (sliding TTL overuse, deep nesting, unnecessary GC/locking) and their recommended alternatives. Read before putting GPDC on a hot path.
  • Multi-Process Locking — when to lock, performance impact, recommended usage, deadlock avoidance, and GC interaction.

Extensions

Optional built-in extensions under gpdatacached.extensions:

  • Pydantic Support — cache pydantic BaseModel records. Two storage modes: scalar (atomic JSON) for scalar-only models, container (Redis hash) for models needing field-level access or nested list/dict/set fields. Pydantic is a core dependency; no extra install needed.
  • Pandas Support — cache pandas Series / DataFrame as live objects. Online selective accessors (.iloc, .loc, df[col]) for one-shot subset reads; .value for full restore; extend for appends. Requires pip install "gpdatacached[pandas]".

Running Tests

The test suite expects a local Redis instance reachable at 127.0.0.1:6379 with password 123456:

  • Linux — run Redis directly on the host.
  • Windows — run Redis inside WSL; it will be reachable at localhost / 127.0.0.1 from the Windows side.

⚠️ Some tests flush the Redis database (FLUSHDB). Always use a dedicated Redis instance for testing — never point the tests at a production database.

Run the suite with:

pytest

You can edit the Redis settings in tests/conftest.py to point at a different instance, but this is not recommended — running a dedicated throwaway test Redis is usually cheaper and safer.


License

MIT © Linnet Codes

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

gpdatacached-0.1.0.tar.gz (163.1 kB view details)

Uploaded Source

Built Distribution

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

gpdatacached-0.1.0-py3-none-any.whl (67.8 kB view details)

Uploaded Python 3

File details

Details for the file gpdatacached-0.1.0.tar.gz.

File metadata

  • Download URL: gpdatacached-0.1.0.tar.gz
  • Upload date:
  • Size: 163.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gpdatacached-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac9f1df11f3cd7b0891366aea6312adf242ec5f96d77e634c1de2a719905bcbf
MD5 193e492e0ea0eb8c7c6dfe0be15a6a95
BLAKE2b-256 d83fda71cf767a16a0dc19e9cfc05e48b25d93bf6e6be2c059cc85c3e134b59f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpdatacached-0.1.0.tar.gz:

Publisher: python-publish.yml on LinnetCodes/gpdatacached

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gpdatacached-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gpdatacached-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 67.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gpdatacached-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06ddc7b612ff8e26a7627bf197cd437620f7f440cca9d2145727b68fbced8a98
MD5 f16d431a861a16645bb78e3964937576
BLAKE2b-256 13c3c0b9abb342077f1f4e6263dc4f5001c1585a7e6a03ceb462b5fd7820cb08

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpdatacached-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on LinnetCodes/gpdatacached

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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