Agraffe,在无服务器服务(例如 AWS lambda、Google Cloud Functions 和 Azure Functions)中使用 ASGI 构建 API。
项目描述
Agraffe,在无服务器服务(例如 AWS lambda、Google Cloud Functions 和 Azure Functions)中使用 ASGI 构建 API。
支持服务
- 谷歌云函数
- AWS lambda(使用 API Gateway HTTP API 和 REST API)
- Azure 函数
要求
蟒蛇 3.7、3.8、3.9
安装
$ pip install agraffe
例子
创造它
- 创建一个文件
main.py
:
from agraffe import Agraffe, Service
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
entry_point = Agraffe.entry_point(app, Service.google_cloud_functions)
# or
from agraffe.services.google_cloud_functions import HttpCycle
def entry_point(request):
return Agraffe(app, HttpCycle)(request=request)
部署它
- 使用以下命令部署 api:
$ gcloud functions deploy {FUNCTION NAME} --entry-point entry_point --runtime python37 --trigger-http --allow-unauthenticated
执照
该项目根据 MIT 许可条款获得许可。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。
源分布
agraffe-0.5.0.tar.gz
(43.1 kB
查看哈希)
内置分布
agraffe-0.5.0-py3-none-any.whl
(7.5 kB
查看哈希)