Skip to main content

fastapi-redis-session

CI

A redis-based session backend for Fastapi apps

Install

pip install -U fastapi-redis-session

Requires Python 3.12 or newer.

The public API is async-only and uses redis.asyncio.

Development

uv sync --group dev
uv run pytest

Use

from typing import Any

from fastapi import Depends, FastAPI, Request, Response

from fastapi_redis_session import deleteSession, getSession, getSessionId, getSessionStorage, setSession, SessionStorage

app = FastAPI(title=__name__)


@app.post("/setSession")
async def _setSession(
    request: Request, response: Response, sessionStorage: SessionStorage = Depends(getSessionStorage)
):
    sessionData = await request.json()
    await setSession(response, sessionData, sessionStorage)


@app.get("/getSession")
async def _setSession(session: Any = Depends(getSession)):
    return session


@app.post("/deleteSession")
async def _deleteSession(
    sessionId: str = Depends(getSessionId), sessionStorage: SessionStorage = Depends(getSessionStorage)
):
    await deleteSession(sessionId, sessionStorage)
    return None

getSession is an async dependency, and setSession / deleteSession must be awaited inside async route handlers.

Migration notes

  • SessionStorage now uses redis.asyncio.Redis.
  • Session access is no longer exposed through sync magic methods; use the async helper functions or awaitable storage methods instead.
  • Existing code that called setSession(...) or deleteSession(...) without await must be updated.

Config

Deafult Config

  • url of Redis: redis://localhost:6379/0
  • name of sessionId: ssid
  • generator function of sessionId: lambda :uuid.uuid4().hex
  • expire time of session in redis: 6 hours

Custom Config

from fastapi_redis_session.config import basicConfig
basicConfig(
    redisURL="redis://localhost:6379/1",
    sessionIdName="sessionId",
    sessionIdGenerator=lambda: str(random.randint(1000, 9999)),
    expireTime=timedelta(days=1),
    )

Metadata

Release files for fastapi-redis-session 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-redis-session 0.3.1
File Size Uploaded Provenance Actions
fastapi_redis_session-0.3.1.tar.gz 6.2 kB Without provenance Details for fastapi_redis_session-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-redis-session 0.3.1
File Interpreter ABI Platform Actions
fastapi_redis_session-0.3.1-py3-none-any.whl Python 3 none any Details for fastapi_redis_session-0.3.1-py3-none-any.whl

Total release size: 10.9 kB

Release files / fastapi_redis_session-0.3.1.tar.gz

Download URL fastapi_redis_session-0.3.1.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
80b2448b2cb93023a494752495afe42b60f5cec9bbca2846023f2365225cce6b
BLAKE2b-256 checksum
How to use checksums
c0f16ccf1a2bc37e611279ee1978cdeb1f974a9c2242658911b579651c109429
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / fastapi_redis_session-0.3.1-py3-none-any.whl

Download URL fastapi_redis_session-0.3.1-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
54e90d4bb03b826e67c2b798154da166811f1c03e327d3e891ad6b062f034b42
BLAKE2b-256 checksum
How to use checksums
a776819740367e9f20c1c3f7b50a9f0632849eb7f0dc4f51ab7c392dc67875fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for fastapi-redis-session 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page