Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-idempotent-0.0.3.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_idempotent-0.0.3-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

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

Hashes for fastapi-idempotent-0.0.3.tar.gz
Algorithm Hash digest
SHA256 00c35d5b9d82f39036341f8094c2d7fccdb980cd4bc1f6ab5a53f1ac3d1745c9
MD5 1d07623ede8c21b6ea37f9d1d82ed83b
BLAKE2b-256 3393b2548a9371a1c8ea3ec55c171fa7bd395928e6a639b90d39937c49897201

See more details on using hashes here.

File details

Details for the file fastapi_idempotent-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_idempotent-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1a71469df0f2aa436599cc4389e48e006a34209f37f6b6d1310bcf55c1f48e16
MD5 5850657ff7cfaf3aa0130599a5ad57da
BLAKE2b-256 c739e0431a5092d40337d0c761578c9a7d31085739161d7c9ff9f108ee79e102

See more details on using hashes here.

Supported by

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