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

Uploaded Source

Built Distribution

webtool-0.0.7-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webtool-0.0.7.tar.gz
  • Upload date:
  • Size: 25.6 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.7.tar.gz
Algorithm Hash digest
SHA256 c1dbd2eae736c1b1ffbae19aa54026a8379155260661f4ad96914b1d8349e912
MD5 e7a281c98eb9cfb962b17d34ff01427c
BLAKE2b-256 c0563935a892ae75c02fe50145443715d4efbbd94e555878a50c972ee7d67509

See more details on using hashes here.

File details

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

File metadata

  • Download URL: webtool-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 31.5 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 20fbab64829bc71af17527e0b9711237980104b7ede12e23c748a286f7d61cb8
MD5 01d023b3f217dfa4b76768c88c4c3101
BLAKE2b-256 a2b11ca0a19c0bbf86da90373da6147c53338da697dbc4bdc12bb73755e94bdf

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