← Back to projects
Open Source · PyPI · v0.1.1 · Early Release
sqlmodel-cache
Open source project in active development. Transparent Redis caching for SQLModel. First version published on PyPI, CI and tests in place.
PyPI
sqlmodel-cache
Version
v0.1.1
License
MIT
The problem

SQLModel doesn't natively offer a caching mechanism for session lookups. To cache session.get() results with Redis, you had to write repetitive boilerplate code, hard to maintain and error-prone.

The solution

A single __cache_config__ declaration on the model automatically enables caching for all session.get() calls. Per-model configurable TTL, sync and async support, interchangeable Redis transport.

# pip install sqlmodel-cache

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

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

# cache miss → DB, cache hit → Redis
hero = session.get(Hero, 1)
Current status

Early release v0.1.1 published on PyPI. CI via GitHub Actions with automated tests on every push. Documentation on GitHub Pages. Sync and async support. Temporarily paused. Active development to resume.

Stack
PythonRedisSQLModelPyPIGitHub ActionsMkDocspytest