Skip to main content

A redis-based session backend for Fastapi apps

Project description

fastapi-redis-session

CI

A redis-based session backend for Fastapi apps

Install

pip install -U fastapi-redis-session

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()
    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)
):
    deleteSession(sessionId, sessionStorage)
    return None

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),
    )

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

fastapi-redis-session-0.2.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

fastapi_redis_session-0.2.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-redis-session-0.2.0.tar.gz.

File metadata

  • Download URL: fastapi-redis-session-0.2.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.12 Linux/5.11.0-1022-azure

File hashes

Hashes for fastapi-redis-session-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8c3f2f4c5f5f6ef2f50f93ffd16e449732788f708549befadb54e210ee723e24
MD5 392e53539d23ea25680e8a21c4929ade
BLAKE2b-256 6a37979e0197e112546130f1793fcea16639cc4d9fb13604e78afba29073d3e8

See more details on using hashes here.

File details

Details for the file fastapi_redis_session-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_redis_session-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e9f6f8d4c58fc12938a0902b7669bdfa8536dd82d5393c827bbf661499b8cae
MD5 cc894420f004cf640b1162f83ad623d4
BLAKE2b-256 84f0c0b521a34cdceaded1a57283817977a9ed3333aa7680e699e5a1686d6efc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page