Sanic 框架实用API工具集,拥有自动生成文档、参数校验、配置的导入、日志功能的优化等功能,更好的助力接口的开发
Project description
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
Release history Release notifications | RSS feed
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.3.0a1.tar.gz
(117.5 kB
view details)
Built Distribution
File details
Details for the file sanic_api-0.3.0a1.tar.gz
.
File metadata
- Download URL: sanic_api-0.3.0a1.tar.gz
- Upload date:
- Size: 117.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91796b15076f2c519edb8daa12ecddb73805686f2469ef3a68c9cc8ec9a4e22b |
|
MD5 | 9094384e3ac1adedb4072a6dd82ecd34 |
|
BLAKE2b-256 | 2d2468a240c59bf130f946b91fe2868108115b112a19c0f0ae1b01f9cdcef7e3 |
File details
Details for the file sanic_api-0.3.0a1-py3-none-any.whl
.
File metadata
- Download URL: sanic_api-0.3.0a1-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bf748a9b0ef29faabddb901b6e238b15971eee1cc34303106d7303a77cc56fe |
|
MD5 | 36efca927611d40333d85bdfde0ed6d6 |
|
BLAKE2b-256 | 6e9c713a99307f7889a59403a0db9959d32b9ba6930bf3d5c12189024563e4d6 |