FastAPI/Starlette library for authentication, throttling, caching.
Project description
WebTool
Well-Architected FastAPI/Starlette library for authentication, throttling, caching, logging, and utilities.
Requirements
- Python 3.11+
Installation
pip install webkit
poetry add webkit
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_token = jwt_service.create_access_token({"sub": 123, "scope": ["write"]})
refresh_token = await jwt_service.create_refresh_token({"sub": 123}, access_token)
return access_token, refresh_token
Throttling
Rate limiting system for FastAPI/Starlette applications.
from webtool.throttle import limiter
from fastapi import FastAPI
app = FastAPI()
@app.get("/api/resource")
@limiter(max_requests=50, interval=3600, scope=["user"])
@limiter(max_requests=10, interval=3600, scope=["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.3.tar.gz
(15.3 kB
view details)
Built Distribution
webtool-0.0.3-py3-none-any.whl
(19.5 kB
view details)
File details
Details for the file webtool-0.0.3.tar.gz
.
File metadata
- Download URL: webtool-0.0.3.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 271943ab11b46f5f976a24b6f5f54da753c3e5fdf1cbf9edbb35b404349770b2 |
|
MD5 | df8f8ba7e08c452ebd341b8c07346076 |
|
BLAKE2b-256 | ba3a0f8884135b2ab6683b9711ee7f943dcb76b0ecff2b208c52ec3e21f44186 |
File details
Details for the file webtool-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: webtool-0.0.3-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/24.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b4200ed963a741e212b543ca00bbfd867a7a18239d626b00fcafe76e41da24 |
|
MD5 | afab701ee3afde1a71952d770a4fc216 |
|
BLAKE2b-256 | b91a588b0be3ef2754c5e0552f2e52cae7cf83959532b279f2c6831acbc773c5 |