fastapi-idempotent
How to use package fastapi-idempotent
# Install package using poetry
poetry add fastapi-idempotent
# Using pip
pip install fastapi-idempotent
Set rate limit for FastAPI before starting server
Example code
- main.py
# Import package
from fastapi import FastAPI
from fastapi_idempotent import IdempotentMiddleWare
from core.config import settings # settings is class, where the configuration parameters are saved
from api.responses import JSONResponse
...
# Setup FastAPI
app = FastAPI(
title=settings.PROJECT_NAME,
version=settings.API_VERSION,
openapi_url=f"{settings.API_V1_PATH}/openapi.json",
default_response_class=JSONResponse,
)
Set idempotent for FastAPI
- Using redis storage
# Default idempotent expired is 10800s
app.add_middleware(
IdempotentMiddleWare,
redis_url=settings.IDEMPOTENT_STORAGE_URL, # type: str
)
or
app.add_middleware(
IdempotentMiddleWare,
idempotent_expired=settings.IDEMPOTENT_EXPIRED, # type: int
redis_url=settings.IDEMPOTENT_STORAGE_URL, # type: str
)
- Using memory storage
# Default idempotent expired is 10800s
app.add_middleware(
IdempotentMiddleWare,
testing=True, # type: bool
)
or
app.add_middleware(
IdempotentMiddleWare,
idempotent_expired=settings.IDEMPOTENT_EXPIRED, # type: int
testing=True, # type: bool
)
Release files for fastapi-idempotent 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi-idempotent-0.0.3.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_idempotent-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.5 kB
Release files / fastapi-idempotent-0.0.3.tar.gz
| Download URL | fastapi-idempotent-0.0.3.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00c35d5b9d82f39036341f8094c2d7fccdb980cd4bc1f6ab5a53f1ac3d1745c9
|
|
BLAKE2b-256 checksum How to use checksums |
3393b2548a9371a1c8ea3ec55c171fa7bd395928e6a639b90d39937c49897201
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Release files / fastapi_idempotent-0.0.3-py3-none-any.whl
| Download URL | fastapi_idempotent-0.0.3-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a71469df0f2aa436599cc4389e48e006a34209f37f6b6d1310bcf55c1f48e16
|
|
BLAKE2b-256 checksum How to use checksums |
c739e0431a5092d40337d0c761578c9a7d31085739161d7c9ff9f108ee79e102
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|