API Idempotent requests
Project description
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
)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi-idempotent-0.0.3.tar.gz.
File metadata
- Download URL: fastapi-idempotent-0.0.3.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00c35d5b9d82f39036341f8094c2d7fccdb980cd4bc1f6ab5a53f1ac3d1745c9
|
|
| MD5 |
1d07623ede8c21b6ea37f9d1d82ed83b
|
|
| BLAKE2b-256 |
3393b2548a9371a1c8ea3ec55c171fa7bd395928e6a639b90d39937c49897201
|
File details
Details for the file fastapi_idempotent-0.0.3-py3-none-any.whl.
File metadata
- Download URL: fastapi_idempotent-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a71469df0f2aa436599cc4389e48e006a34209f37f6b6d1310bcf55c1f48e16
|
|
| MD5 |
5850657ff7cfaf3aa0130599a5ad57da
|
|
| BLAKE2b-256 |
c739e0431a5092d40337d0c761578c9a7d31085739161d7c9ff9f108ee79e102
|