Skip to main content

FastAPI/Starlette library for authentication, throttling, caching.

Project description

WebTool

Well-Architected FastAPI/Starlette library for authentication, throttling, caching, logging, and utilities.

Requirements

  • Python 3.11+

Installation

pip install webkit
poetry add webkit

Features

Authentication

JWT token management system with Redis-backed refresh tokens.

from webtool.auth import JWTService
from webtool.cache import RedisCache

cache_client = RedisCache("redis://localhost:6379/0")
jwt_service = JWTService(cache_client)


async def get_token():
    access_token = jwt_service.create_access_token({"sub": 123, "scope": ["write"]})
    refresh_token = await jwt_service.create_refresh_token({"sub": 123}, access_token)
    return access_token, refresh_token

Throttling

Rate limiting system for FastAPI/Starlette applications.

from webtool.throttle import limiter
from fastapi import FastAPI

app = FastAPI()


@app.get("/api/resource")
@limiter(max_requests=50, interval=3600, scope=["user"])
@limiter(max_requests=10, interval=3600, scope=["anno"])
async def get_resource():
    return {"status": "success"}

MsgPack Response

MessagePack-based response.

from webtool.utils import MsgSpecJSONResponse
from fastapi import FastAPI

app = FastAPI(
    default_response_class=MsgSpecJSONResponse,
)


@app.get("/api/resource")
async def get_resource():
    return {"status": "success"}

License

This project is licensed under the Apache-2.0 License.

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

webtool-0.0.4.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

webtool-0.0.4-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file webtool-0.0.4.tar.gz.

File metadata

  • Download URL: webtool-0.0.4.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.1.0

File hashes

Hashes for webtool-0.0.4.tar.gz
Algorithm Hash digest
SHA256 040acfed14bf3ecbc930d33cdce654d4998ebb45f7c713442919df79a00037b1
MD5 ce32d5fffc2bd58882fc82da061f816f
BLAKE2b-256 ad78b205abdf2f5876317a493e5264c163d03ab28f36e7e9972343455ae00ba5

See more details on using hashes here.

File details

Details for the file webtool-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: webtool-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.1.0

File hashes

Hashes for webtool-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7ac7a2792f1bb7e97fc80be9afcb44acc83fca82c4a0dc64e385f13d840a1259
MD5 dcd554464992522eb57ce416d4c2acb6
BLAKE2b-256 985c7a7c014618d2b3a5e69a1ecdd75da3caf8abf76c52b9ba147a1e429afa65

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