Skip to main content

FastAPI/Starlette library for authentication, throttling, caching.

Project description

WebTool(Alpha)

Well-Architected FastAPI/Starlette library for JWT 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, refresh = jwt_service.create_token({"sub": 123, "scope": ["write"]})
    return access, refresh

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, scopes=["user"])
@limiter(max_requests=10, interval=3600, scopes=["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.8.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

webtool-0.0.8-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webtool-0.0.8.tar.gz
  • Upload date:
  • Size: 25.2 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.8.tar.gz
Algorithm Hash digest
SHA256 33233be5344e475843504c22e8bf1cfc8f9ee55b3b606fd23a17ad93e5832576
MD5 9ec6d213ad1b505955d7cb11591c1875
BLAKE2b-256 9078f056ae8a8e93a97f084fd1195f90701b884372e01786ed58ba387d5e7267

See more details on using hashes here.

File details

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

File metadata

  • Download URL: webtool-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 31.2 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 528c62d3cac1bf4b2d8a214ac317248458606bd47dc1cb57098078cd41d6925a
MD5 dbdd702232c9903d197667f872330ae1
BLAKE2b-256 5b9228fdb55a6aa8b937e49dd4c1c52394387f56f263d7d3a34cd1263fe22923

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