Skip to main content

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)

Project description

Python Modern API Tools, fast to code


Documentation: https://so1n.me/pait/

中文文档: https://so1n.me/pait-zh-doc/


pait

Pait is an api tool that can be used in any python web framework (currently only flask, starlette, sanic, tornado are supported, other frameworks will be supported once Pait is stable).

Note:

mypy check 100%

test coverage 95%+ (exclude api_doc)

python version >= 3.7 (support postponed annotations)

The following code does not specify, all default to use the starlette framework.

Feature

  • Parameter checksum automatic conversion (parameter check depends on Pydantic)
  • Parameter dependency verification
  • Automatically generate openapi files
  • Swagger, Redoc route
  • gRPC Gateway route
  • TestClient support, support response result verification
  • Support for plugin extensions, such as the Mock plugin

Installation

pip install pait

Simple Example

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, add_doc_route
from pait.field import Body
from pait.model.response import PaitResponseModel
from pydantic import BaseModel, Field


class DemoResponseModel(PaitResponseModel):
    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)

How to used in other web framework?

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

IDE Support

While pydantic will work well with any IDE out of the box.

Full example

For more complete examples, please refer to example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pait-0.8.0.1.tar.gz (84.1 kB view details)

Uploaded Source

Built Distribution

pait-0.8.0.1-py3-none-any.whl (117.0 kB view details)

Uploaded Python 3

File details

Details for the file pait-0.8.0.1.tar.gz.

File metadata

  • Download URL: pait-0.8.0.1.tar.gz
  • Upload date:
  • Size: 84.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.7.3 Linux/5.10.0-amd64-desktop

File hashes

Hashes for pait-0.8.0.1.tar.gz
Algorithm Hash digest
SHA256 0673124636bcb932c7a0366cafaa97a67f90cccc0e8469e7f1ec91bd2a4a2068
MD5 8c2ec8c77e3596c07ce3f52466290b0d
BLAKE2b-256 dacd39b3dfbac5f7bda45d8d293b7c5965a66b1ab79714a5e1d027a9ab1fc853

See more details on using hashes here.

File details

Details for the file pait-0.8.0.1-py3-none-any.whl.

File metadata

  • Download URL: pait-0.8.0.1-py3-none-any.whl
  • Upload date:
  • Size: 117.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.7.3 Linux/5.10.0-amd64-desktop

File hashes

Hashes for pait-0.8.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac6af01b69851a1e2d5d69c0e3c43b1d54be730eb982065a52785b6aa2195371
MD5 8fb0c3b0f95c4bbbd9edc5800878d5d4
BLAKE2b-256 34bda96ec50eda5ea96291912b31144979be8dde559511a53a77e3ac80b01fe3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page