Skip to main content

FastAPI/Starlette library for authentication, throttling, caching.

Project description

WebTool(Alpha)

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

Requirements

  • Python 3.11+

Installation

pip install webtool
poetry add webtool

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 fastapi import FastAPI
from starlette.middleware import Middleware
from webtool.auth import JWTService
from webtool.cache import RedisCache
from webtool.throttle import limiter, LimitMiddleware, JWTBackend

cache = RedisCache("redis://127.0.0.1:6379/0")
jwt_backend = JWTBackend(JWTService(cache, secret_key="test"))

app = FastAPI(
    middleware=[
        Middleware(
            LimitMiddleware,
            cache=cache,
            auth_backend=jwt_backend,
        ),
    ],
)


@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.6.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

webtool-0.0.6-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webtool-0.0.6.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.5.0-1025-azure

File hashes

Hashes for webtool-0.0.6.tar.gz
Algorithm Hash digest
SHA256 1dc11934a6839796f9cf09379c5a9eb339f96bb744817c3b76b1988fb0e4beff
MD5 5d6c0bc641e54b221d75ba6565a7d9b8
BLAKE2b-256 818db768fd01f602be6b359476544da54745bbd343a766dc2270e2ee5fb29b2f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: webtool-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 25.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.10 Linux/6.5.0-1025-azure

File hashes

Hashes for webtool-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e126f6de7f70ff8c7ea46db5bcb1e9f5b404134e22982accd7c40ba1730c3a20
MD5 5f0492c9f1dbc915d52995adedc0a1fd
BLAKE2b-256 c880e416a78be0f62b477b377adf5428b64a7706469d931fde90582f2e8f214a

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