# WebTool(Alpha)
<img src="https://github.com/ds5105119/webtool/workflows/CI/badge.svg">
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/ds5105119/webtool",
"name": "webtool",
"maintainer": "IIH",
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": "ds5105119@gmail.com",
"keywords": "fastapi, starlette, throttle, cache, utils",
"author": "IIH",
"author_email": "ds5105119@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a7/4e/b2a48bcae291fa0bd74159fbbf3f4d49a975d4127bb8bd937f451860d4cb/webtool-0.0.13.tar.gz",
"platform": null,
"description": "# WebTool(Alpha)\n<img src=\"https://github.com/ds5105119/webtool/workflows/CI/badge.svg\">\n\nWell-Architected FastAPI/Starlette library for JWT authentication, throttling, caching, logging, and utilities.\n\n## Requirements\n\n- Python 3.11+\n\n## Installation\n\n```shell\npip install webtool\n```\n\n```shell\npoetry add webtool\n```\n\n## Features\n\n### Authentication\nJWT token management system with Redis-backed refresh tokens.\n\n```python\nfrom webtool.auth import JWTService\nfrom webtool.cache import RedisCache\n\ncache_client = RedisCache(\"redis://localhost:6379/0\")\njwt_service = JWTService(cache_client)\n\n\nasync def get_token():\n access, refresh = jwt_service.create_token({\"sub\": 123, \"scope\": [\"write\"]})\n return access, refresh\n```\n\n### Throttling\nRate limiting system for FastAPI/Starlette applications.\n\n```python\nfrom fastapi import FastAPI\nfrom starlette.middleware import Middleware\nfrom webtool.auth import JWTService\nfrom webtool.cache import RedisCache\nfrom webtool.throttle import limiter, LimitMiddleware, JWTBackend\n\ncache = RedisCache(\"redis://127.0.0.1:6379/0\")\njwt_backend = JWTBackend(JWTService(cache, secret_key=\"test\"))\n\napp = FastAPI(\n middleware=[\n Middleware(\n LimitMiddleware,\n cache=cache,\n auth_backend=jwt_backend,\n ),\n ],\n)\n\n\n@app.get(\"/api/resource\")\n@limiter(max_requests=50, interval=3600, scopes=[\"user\"])\n@limiter(max_requests=10, interval=3600, scopes=[\"anno\"])\nasync def get_resource():\n return {\"status\": \"success\"}\n```\n\n### MsgPack Response\nMessagePack-based response.\n\n```python\nfrom webtool.utils import MsgSpecJSONResponse\nfrom fastapi import FastAPI\n\napp = FastAPI(\n default_response_class=MsgSpecJSONResponse,\n)\n\n\n@app.get(\"/api/resource\")\nasync def get_resource():\n return {\"status\": \"success\"}\n```\n\n## License\n\nThis project is licensed under the Apache-2.0 License.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "FastAPI/Starlette library for authentication, throttling, caching.",
"version": "0.0.13",
"project_urls": {
"Homepage": "https://github.com/ds5105119/webtool",
"Repository": "https://github.com/ds5105119/webtool"
},
"split_keywords": [
"fastapi",
" starlette",
" throttle",
" cache",
" utils"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4ba880ae044769323129c617736791125778f0180a4e22261010f602d20874b4",
"md5": "c48eda5aa6933558ade07220ec33d713",
"sha256": "2a9bbe52ee118891c71c9dd14eb074150bb9080053034cfc1e476eccbfb522ab"
},
"downloads": -1,
"filename": "webtool-0.0.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c48eda5aa6933558ade07220ec33d713",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 31542,
"upload_time": "2024-12-20T14:02:42",
"upload_time_iso_8601": "2024-12-20T14:02:42.583742Z",
"url": "https://files.pythonhosted.org/packages/4b/a8/80ae044769323129c617736791125778f0180a4e22261010f602d20874b4/webtool-0.0.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a74eb2a48bcae291fa0bd74159fbbf3f4d49a975d4127bb8bd937f451860d4cb",
"md5": "4cc2c87536201c6a37440096303796cf",
"sha256": "391abee73a458f9f0d8a89b73d722b849dd16d650ffd717e1c24aa14e6c33fc9"
},
"downloads": -1,
"filename": "webtool-0.0.13.tar.gz",
"has_sig": false,
"md5_digest": "4cc2c87536201c6a37440096303796cf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 25467,
"upload_time": "2024-12-20T14:02:43",
"upload_time_iso_8601": "2024-12-20T14:02:43.724815Z",
"url": "https://files.pythonhosted.org/packages/a7/4e/b2a48bcae291fa0bd74159fbbf3f4d49a975d4127bb8bd937f451860d4cb/webtool-0.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-20 14:02:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ds5105119",
"github_project": "webtool",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "webtool"
}