# 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/79/5d/88695cf2f383fdf047bf2f9bfa2a7d8357e6a878430ec56072110f50bafc/webtool-0.1.6.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.1.6",
"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": "111ad32c43c558f4a7a0851525b5d85bcb8cd058245339a8d5cb82e8acfd7249",
"md5": "4ac767b98351297bdd781a9288e511db",
"sha256": "c5fb2bf139f2783b59092abb22fa7c20d9f161b99d54b25e3be885fc9857f047"
},
"downloads": -1,
"filename": "webtool-0.1.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4ac767b98351297bdd781a9288e511db",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 31415,
"upload_time": "2025-03-03T06:39:16",
"upload_time_iso_8601": "2025-03-03T06:39:16.947679Z",
"url": "https://files.pythonhosted.org/packages/11/1a/d32c43c558f4a7a0851525b5d85bcb8cd058245339a8d5cb82e8acfd7249/webtool-0.1.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "795d88695cf2f383fdf047bf2f9bfa2a7d8357e6a878430ec56072110f50bafc",
"md5": "4937c30ceaad5805e7a176f8a09af466",
"sha256": "a16b387f8c4a0f3455865d0f583b2b58b026f58e31e19ddec2aae047e2f2a136"
},
"downloads": -1,
"filename": "webtool-0.1.6.tar.gz",
"has_sig": false,
"md5_digest": "4937c30ceaad5805e7a176f8a09af466",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 24569,
"upload_time": "2025-03-03T06:39:18",
"upload_time_iso_8601": "2025-03-03T06:39:18.486684Z",
"url": "https://files.pythonhosted.org/packages/79/5d/88695cf2f383fdf047bf2f9bfa2a7d8357e6a878430ec56072110f50bafc/webtool-0.1.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-03-03 06:39:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ds5105119",
"github_project": "webtool",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "webtool"
}