Skip to main content

Transparent Redis caching for SQLModel

Project description

sqlmodel-cache

CI PyPI

Transparent Redis caching for SQLModel — cache session.get() lookups with a single class attribute.

Installation

pip install sqlmodel-cache
# With async support:
pip install "sqlmodel-cache[async]"

Quick Example

import redis
from sqlmodel import Field, Session, SQLModel, create_engine
from sqlmodel_cache import CacheConfig, SQLModelCache
from sqlmodel_cache.transport import RedisSyncTransport

SQLModelCache.configure(
    transport=RedisSyncTransport(redis.Redis.from_url("redis://localhost:6379")),
    default_ttl=300,
)

class Hero(SQLModel, table=True):
    __cache_config__ = CacheConfig(ttl=600)
    id: int | None = Field(default=None, primary_key=True)
    name: str = ""

engine = create_engine("sqlite:///heroes.db")
SQLModel.metadata.create_all(engine)

with Session(engine) as session:
    hero = session.get(Hero, 1)  # cache miss → queries DB
with Session(engine) as session:
    hero = session.get(Hero, 1)  # cache hit → returns from Redis

Documentation

Full documentation is available at emzelim.github.io/sqlmodel-cache.

License

MIT

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

sqlmodel_cache-0.1.1.tar.gz (522.3 kB view details)

Uploaded Source

Built Distribution

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

sqlmodel_cache-0.1.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file sqlmodel_cache-0.1.1.tar.gz.

File metadata

  • Download URL: sqlmodel_cache-0.1.1.tar.gz
  • Upload date:
  • Size: 522.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sqlmodel_cache-0.1.1.tar.gz
Algorithm Hash digest
SHA256 999fbcc3a6843aac7d19dd99649ccd5e70318e86283699a72898333aaee55738
MD5 888421ce02769b00e7eeb730f607f548
BLAKE2b-256 67a9ca0993891784b59bd594acbef19572fbe1ed6b84c203f0f73f2c03dff080

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlmodel_cache-0.1.1.tar.gz:

Publisher: publish.yml on Emzelim/sqlmodel-cache

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

File details

Details for the file sqlmodel_cache-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sqlmodel_cache-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sqlmodel_cache-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5e781dc38eed86ac6e8394c1c1a5d2646d27c1e233aa69158613709347588040
MD5 5b63a22689576fa77eb2421612cb8737
BLAKE2b-256 df319f67a98394283c674bde861ecc5e9c432188b957a30af23fb889177ad701

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlmodel_cache-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Emzelim/sqlmodel-cache

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