Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Pait is a Python api tool. Pait enables your Python web framework to have type checking, parameter type conversion, interface document generation and can display your documents through Redoc or Swagger (power by inspect, pydantic)
Pait(π tool) - Python Modern API Tools, easier to use web frameworks/write API routing
Documentation: https://so1n.me/pait/
中文文档: https://so1n.me/pait-zh-doc/
Pait is an api tool that can be used in any python web framework, the features provided are as follows:
Pydantic
and inspect
, currently supports Pydantic
V1 and V2 versions).Swagger
,Redoc
,RapiDoc
and Elements
.Note:
mypy check 100%
python version >= 3.8 (support postponed annotations)
pip install pait
from typing import Type
import uvicorn # type: ignore
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
from pait.app.starlette import pait
from pait.field import Body
from pait.openapi.doc_route import add_doc_route
from pait.model.response import JsonResponseModel
from pydantic import BaseModel, Field
class DemoResponseModel(JsonResponseModel):
"""demo post api response model"""
class ResponseModel(BaseModel):
uid: int = Field()
user_name: str = Field()
description: str = "demo response"
response_data: Type[BaseModel] = ResponseModel
@pait(response_model_list=[DemoResponseModel])
async def demo_post(
uid: int = Body.i(description="user id", gt=10, lt=1000),
user_name: str = Body.i(description="user name", min_length=2, max_length=4)
) -> JSONResponse:
return JSONResponse({'uid': uid, 'user_name': user_name})
app = Starlette(routes=[Route('/api', demo_post, methods=['POST'])])
add_doc_route(app)
uvicorn.run(app)
See documentation for more features
Framework | Description |
---|---|
Flask | All features supported |
Sanic | All features supported |
Starlette | All features supported |
Tornado | All features supported |
Django | Coming soon |
If the web framework is not supported(which you are using).
Can be modified sync web framework according to pait.app.flask
Can be modified async web framework according to pait.app.starlette
The main operating principle of Pait
is to convert the function signature of the route function into Pydantic Model
through the reflection mechanism when the program is started,
and then verify and convert the request parameters through Pydantic Model
when the request hits the route.
These two stages are all automatically handled internally by Pait
.
The first stage only slightly increases the startup time of the program, while the second stage increases the response time of the routing, but it only consumes 0.00005(s) more than manual processing.
The specific benchmark data and subsequent optimization are described in #27.
For more complete examples, please refer to example
FAQs
Pait is a Python api tool. Pait enables your Python web framework to have type checking, parameter type conversion, interface document generation and can display your documents through Redoc or Swagger (power by inspect, pydantic)
We found that pait demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.