Skip to main content

Sanic 框架实用API工具集,拥有自动生成文档、参数校验、配置的导入、日志功能的优化等功能,更好的助力接口的开发

Project description

logo

MIT License Python Sanic Code style: black

Sanic-API

让您的sanic服务程序更好的支持API文档、参数校验、日志打印、响应规范等

特性

  • 无需任何多余改动,全自动生成openapi文档,使用更加方便

  • 基于pydantic的参数校验器,让接口的请求及响应更符合你的预期

  • 使用loguru库代替官方logging日志库,并对访问日志进行扩展,支持打印接口耗时、接口参数

  • 使用{code: 0, data: null, msg: ""}样式的接口返回

  • 对接口中的异常进行拦截,及自定义错误码

  • 接口返回样式可自定义配置

截图

路线图

  • 增加一键生成预设项目cli命令

  • 编写详细文档

  • API接口增加请求头、URL路径参数收集和校验:

安装

使用 pip 安装 sanic-api

  pip install sanic-api

使用方法/示例

from sanic import Sanic, text
from sanic_api import init_api

app = Sanic("Sanic-API")


@app.get('/')
async def index(request):
    return text("Sanic-API Example")


def main():
    init_api(app)
    app.run(access_log=True)


if __name__ == '__main__':
    main()

开发

要部署这个项目,请运行

  pip install pdm
  pdm sync

文档

文档

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

sanic-api-0.2.9.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

sanic_api-0.2.9-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file sanic-api-0.2.9.tar.gz.

File metadata

  • Download URL: sanic-api-0.2.9.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sanic-api-0.2.9.tar.gz
Algorithm Hash digest
SHA256 77d357fc54394a565bc1d3cb11083899b9fc8e83f20de958c386d162047b4c40
MD5 d1224f8c844dbcc253b66bd15a9379a2
BLAKE2b-256 b6debb62370e00ad5e27ba09d8fd02d386ae97992b254bd4b0c2894d966624d0

See more details on using hashes here.

File details

Details for the file sanic_api-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: sanic_api-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sanic_api-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 39f97c3f969a7cf39531b30970d835fcd8063b25bc2f26ada7ebad2cad793e72
MD5 2b10366d2d7e6fd769db4553ace31a01
BLAKE2b-256 3193a4a992faf8e0ac6f185bc0245a9c4caf6ecd911e3ce3a95b02f817f69459

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