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.1.5.tar.gz (24.5 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.1.5-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webtool-0.1.5.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for webtool-0.1.5.tar.gz
Algorithm Hash digest
SHA256 60b9de9232654f29724cb22699fb3c489c5fdb2bae6b7cf7877c73d8141a73a1
MD5 82f32e9dd77ef3a7324bd86255cb231d
BLAKE2b-256 1b99078f6a3dcfdc403b81de78456a20091a18a70bc0011486061998f3044039

See more details on using hashes here.

File details

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

File metadata

  • Download URL: webtool-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.2 Linux/6.8.0-1021-azure

File hashes

Hashes for webtool-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ab7fe90a5f4014f2519bf3a770d39380c8e4bbbed005236644d716e450b3d408
MD5 7d50e0ffdb6983c58bbf3f70fdc804de
BLAKE2b-256 8a49ddf7e0f45f6f9e8bf0a661a4ac66e167c8f88e0ab4d43482fd27e503a60b

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