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

Uploaded Source

Built Distribution

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

webtool-0.0.11-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webtool-0.0.11.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.11.tar.gz
Algorithm Hash digest
SHA256 37f852e311da153dc52c703852b5561828649e57756c16f060cece22988d6fb4
MD5 72d0879420d526d6e0050dcec7bb8115
BLAKE2b-256 27317dc68d1a846826812b826a3bd37a9a93e16891644bafd44af2a004f7c750

See more details on using hashes here.

File details

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

File metadata

  • Download URL: webtool-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 31.7 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 94bdd3586c09618d6f194a49457356b6ce95f39467afda453f4166c7efd1826e
MD5 ab6989bc663103f4a67a8e9a6ce553e8
BLAKE2b-256 fad8e3b88411cceae72f198f39b6f73cd987a4a9e1420a91c4c36ceb5f878a98

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