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
Release history Release notifications | RSS feed
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.9.tar.gz
(25.2 kB
view details)
Built Distribution
webtool-0.0.9-py3-none-any.whl
(31.2 kB
view details)
File details
Details for the file webtool-0.0.9.tar.gz
.
File metadata
- Download URL: webtool-0.0.9.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e0f50a016a4ddcf334cd3e725dd7e7bff8e59b990b416351148c91ee67e06a8 |
|
MD5 | 8c51e11f57ab88ca8323a30d6f401497 |
|
BLAKE2b-256 | 71f8d6db79fd95c70d483b22df1953e5f2f6eadbaf1901aa5397dcd3288a9921 |
File details
Details for the file webtool-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: webtool-0.0.9-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62040c119c320f69188b074dc8d0e18d40da0510316774375f07e589d6afab49 |
|
MD5 | 10539efde8ad6b44c82a922a9c8f0b17 |
|
BLAKE2b-256 | 68ba14a50ef3310d829b0a195e798ae7ffa05fd9aaf1af8b1104508918c1ea7c |