aioredis_fastapi is an asynchronous redis based session backend for FastAPI powered applications.
Project description
aioredis_fastapi is an asynchronous redis based session backend for FastAPI powered applications.
🚸This repository is under active development, and it is not production-ready.🚸
🛠️ Requirements
aioredis_fastapi requires Python 3.9 or above.
To install Python 3.9, I recommend using pyenv. You can refer to this section of the readme file on how to install poetry and pyenv into your linux machine.
🚨 Installation
With pip
:
python3.9 -m pip install aioredis_fastapi
or by checking out the repo and installing it with poetry:
git clone https://github.com/wiseaidev/aioredis_fastapi.git && cd aioredis_fastapi && poetry install
🚸 Usage
from typing import Any
from fastapi import Depends, FastAPI, Request, Response
from aioredis_fastapi import (
get_session_storage,
get_session,
get_session_id,
set_session,
del_session,
SessionStorage,
)
app = FastAPI(title=__name__)
@app.post("/set-session")
async def _set_session(
request: Request,
response: Response,
session_storage: SessionStorage = Depends(get_session_storage),
):
session_data = await request.json()
await set_session(response, session_data, session_storage)
@app.get("/get-session")
async def _get_session(session: Any = Depends(get_session)):
return session
@app.post("/del-session")
async def _delete_session(
session_id: str = Depends(get_session_id),
session_storage: SessionStorage = Depends(get_session_storage),
):
await del_session(session_id, session_storage)
return None
🚸 Custom Config
from aioredis_fastapi.config import settings
from datetime import timedelta
settings(
redis_url="redis://localhost:6379",
session_id_name="session-id",
session_id_generator=lambda: str(random.randint(1000, 9999)),
expire_time: timedelta(days=1)
)
🎉 Credits
The following projects were used to build and test aioredis_fastapi
.
👋 Contribute
If you are looking for a way to contribute to the project, please refer to the Guideline.
📝 License
This program and the accompanying materials are made available under the terms and conditions of the GNU GENERAL PUBLIC LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aioredis_fastapi-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c992aa0d616c970acc4ad17bcb0857a7d7e79ff4e5559cea983749c8705b7e91 |
|
MD5 | b92a3a3a55923214a82ef9c6cb6855ea |
|
BLAKE2b-256 | f53e1f93f949e6647b858bffe053dbcd8aa976f7e8399fb4f41136e77adb85a1 |