https://github.com/ds5105119/webtool
Well-Architected Python library for JWT authentication, throttling, caching, logging, and utilities.
https://github.com/ds5105119/webtool
cache fastapi jwt msgpack starlette throttle
Last synced: 4 months ago
JSON representation
Well-Architected Python library for JWT authentication, throttling, caching, logging, and utilities.
- Host: GitHub
- URL: https://github.com/ds5105119/webtool
- Owner: ds5105119
- License: apache-2.0
- Created: 2024-11-12T08:58:55.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-20T20:12:53.000Z (7 months ago)
- Last Synced: 2025-12-09T09:27:19.953Z (7 months ago)
- Topics: cache, fastapi, jwt, msgpack, starlette, throttle
- Language: Python
- Homepage: https://ds5105119.github.io/webtool/
- Size: 1.6 MB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# WebTool(Alpha)

Well-Architected FastAPI/Starlette library for JWT authentication, throttling, caching, logging, and utilities.
## Requirements
- Python 3.11+
## Installation
```shell
pip install webtool
```
```shell
poetry add webtool
```
## Features
### Authentication
JWT token management system with Redis-backed refresh tokens.
```python
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.
```python
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.
```python
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.