a micro server
Project description
Simple-Starlette
一个简单的微服务api框架,基于 starlette
框架实现:
- 支持定义
cbv
,fbv
视图 - 请求参数添加类型注解,传参自动校验
- 自定义报错 , 全局报错/错误码 统一处理
- 更方便的定义
websocket
api - 提供请求内全局
g
对象 - 提供
include
划分不同接口,类似flask.blueprint
- orm工具:
sqlalchemy.db
, 使用async.io
特性,提供连接配置,开箱即用 - 缓存工具:
Memory Cache
,Redis Cache
, 适应不同业务场景 http_client
工具: 封装requests,如果业务需要接入第三方api时,有很大帮助token-auth
工具: 提供标准的jwt
鉴权模式simple-api-doc
工具:- 开发阶段提供类似swagger在线文档,方便前后端协作
- 不同于swagger,它对业务代码结构完全无影响,只需要在开发阶段正常定义接口参数等,访问文档页面就会自定生成
安装
使用 pip
直接安装
pip install simple-starlette
example
from simple_starlette.args import QueryParams
from simple_starlette import SimpleStarlette, Request
from simple_starlette.responses import Response, ResTypeEnum
app = SimpleStarlette(__name__)
@app.route("/test")
class Index:
class SomeQuery(QueryParams):
arg1: int
arg2: int
async def get(self, request: Request, q: SomeQuery):
return Response({"arg1": q.arg1, "arg2": q.arg2}, ResTypeEnum.JSON)
if __name__ == "__main__"
app.run()
# curl http://localhost:9091/test?arg1=hello&arg2=world
# response: {"arg1":"hello", "arg2":"world"}
查看更多实例: example usage
LICENSE
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
simple_starlette-2.2.0.tar.gz
(42.5 kB
view details)
File details
Details for the file simple_starlette-2.2.0.tar.gz
.
File metadata
- Download URL: simple_starlette-2.2.0.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 318d5344b93b91cd907ebd9b94164cdabdf6c91b20641f1bf31876c739fddac9 |
|
MD5 | f5ecd0569007b806c2332cf788732c44 |
|
BLAKE2b-256 | fa4a87e39e171e6e259a96f12b3c5b915537e264c172ab2b6cc5e74a784b8c58 |