{"id":21704141,"url":"https://github.com/so1n/pait","last_synced_at":"2025-04-06T05:15:35.835Z","repository":{"id":38961898,"uuid":"281718247","full_name":"so1n/pait","owner":"so1n","description":"Pait(π tool) - Python Modern API Tools, easier to use web frameworks/write API routing","archived":false,"fork":false,"pushed_at":"2024-10-31T15:04:18.000Z","size":4389,"stargazers_count":56,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T04:08:36.534Z","etag":null,"topics":["flask","grpc","openapi","pydantic","python","redoc","sanic","starlette","swagger","tornado","type-hints"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/so1n.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-22T15:43:34.000Z","updated_at":"2025-03-17T00:46:24.000Z","dependencies_parsed_at":"2024-05-21T18:02:54.585Z","dependency_job_id":"4a5dfd1c-2d05-48b4-80e2-ad525a2a04bc","html_url":"https://github.com/so1n/pait","commit_stats":{"total_commits":701,"total_committers":2,"mean_commits":350.5,"dds":"0.0014265335235378318","last_synced_commit":"c0dc695f2381082298df3442795d514b25ab7ec5"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Fpait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Fpait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Fpait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/so1n%2Fpait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/so1n","download_url":"https://codeload.github.com/so1n/pait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247436285,"owners_count":20938533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["flask","grpc","openapi","pydantic","python","redoc","sanic","starlette","swagger","tornado","type-hints"],"created_at":"2024-11-25T21:43:55.293Z","updated_at":"2025-04-06T05:15:35.817Z","avatar_url":"https://github.com/so1n.png","language":"Python","readme":"![](https://cdn.jsdelivr.net/gh/so1n/so1n_blog_photo@master/blog_photo/1652600629491%E6%9C%AA%E5%91%BD%E5%90%8D.jpg)\n\u003cp align=\"center\"\u003e\n    Pait(π tool) - \u003cem\u003ePython Modern API Tools, easier to use web frameworks/write API routing\u003c/em\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://codecov.io/gh/so1n/pait\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/so1n/pait/branch/master/graph/badge.svg?token=NEVM1VODHR\" alt=\"Coverage\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://pypi.org/project/pait/\" target=\"_blank\"\u003e\n        \u003cimg alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/pait\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/pait/\" target=\"_blank\"\u003e\n        \u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/pait\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/so1n/pait/actions?query=event%3Apush+branch%3Amaster\" target=\"_blank\"\u003e\n        \u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/actions/workflow/status/so1n/pait/python-package.yml\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/so1n/pait/releases\" target=\"_blank\"\u003e\n        \u003cimg alt=\"GitHub release (release name instead of tag name)\" src=\"https://img.shields.io/github/v/release/so1n/pait?include_prereleases\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/so1n/pait/actions?query=event%3Apush+branch%3Amaster\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://github.com/so1n/pait/actions/workflows/python-package.yml/badge.svg?event=push\u0026branch=master\" alt=\"Test\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/so1n/pait/tree/master/example\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Support%20framework-Flask%2CSanic%2CStarlette%2CTornado-brightgreen\" alt=\"Support framework\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\n---\n**Documentation**: [https://so1n.me/pait/](https://so1n.me/pait/)\n\n**中文文档**: [https://so1n.me/pait-zh-doc/](https://so1n.me/pait-zh-doc/)\n\n---\n\n# pait\n\nPait is an api tool that can be used in any python web framework, the features provided are as follows:\n- [x] Integrate into the Type Hints ecosystem to provide a safe and efficient API interface coding method.\n - [x] Automatic verification and type conversion of request parameters (depends on `Pydantic` and `inspect`, currently supports `Pydantic` V1 and V2 versions).\n - [x] Automatically generate openapi files and support UI components such as `Swagger`,`Redoc`,`RapiDoc` and `Elements`.\n - [x] TestClient support, response result verification of test cases。\n - [x] Plugin expansion, such as parameter relationship dependency verification, Mock response, etc.。\n - [x] gRPC GateWay (After version 1.0, this feature has been migrated to [grpc-gateway](https://github.com/python-pai/grpc-gateway))\n - [ ] Automated API testing\n - [ ] WebSocket support\n - [ ] SSE support\n\n\u003e Note:\n\u003e\n\u003e - mypy check 100%\n\u003e\n\u003e - python version \u003e= 3.8 (support postponed annotations)\n\n\n\n# Installation\n```Bash\npip install pait\n```\n\n# Simple Example\n```python\nimport uvicorn  # type: ignore\nfrom starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import Route\n\nfrom pait.app.starlette import pait\nfrom pait.field import Body\nfrom pait.openapi.doc_route import add_doc_route\nfrom pydantic import BaseModel, Field\n\n\nclass ResponseModel(BaseModel):\n    \"\"\"demo response\"\"\"\n    uid: int = Field()\n    user_name: str = Field()\n\n\n@pait(response_model_list=[ResponseModel])\nasync def demo_post(\n    uid: int = Body.i(description=\"user id\", gt=10, lt=1000),\n    user_name: str = Body.i(description=\"user name\", min_length=2, max_length=4)\n) -\u003e JSONResponse:\n    return JSONResponse({'uid': uid, 'user_name': user_name})\n\n\napp = Starlette(routes=[Route('/api', demo_post, methods=['POST'])])\nadd_doc_route(app)\nuvicorn.run(app)\n```\nSee [documentation](https://so1n.me/pait/) for more features\n\n# Support Web framework\n\n| Framework | Description            |\n|-----------|------------------------|\n| Flask     | All features supported |\n| Sanic     | All features supported |\n| Starlette | All features supported |\n| Tornado   | All features supported |\n| Django    | Coming soon            |\n\n\nIf the web framework is not supported(which you are using).\n\nCan be modified sync web framework according to [pait.app.flask](https://github.com/so1n/pait/blob/master/pait/app/flask.py)\n\nCan be modified async web framework according to [pait.app.starlette](https://github.com/so1n/pait/blob/master/pait/app/starlette.py)\n\n# Performance\nThe 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,\nand then verify and convert the request parameters through `Pydantic Model` when the request hits the route.\n\nThese two stages are all automatically handled internally by `Pait`.\nThe 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.\nThe specific benchmark data and subsequent optimization are described in [#27](https://github.com/so1n/pait/issues/27).\n\n# Example\nFor more complete examples, please refer to [example](https://github.com/so1n/pait/tree/master/example)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fso1n%2Fpait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fso1n%2Fpait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fso1n%2Fpait/lists"}