Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/odd12258053/agraffe
Agraffe, build API with ASGI in Serverless services (e.g AWS lambda, Google Cloud Functions and Azure Functions).
https://github.com/odd12258053/agraffe
asgi async asyncio aws-lambda azure-functions fastapi gcp-cloud-functions python python3 serverless serverless-services starlette web
Last synced: 3 months ago
JSON representation
Agraffe, build API with ASGI in Serverless services (e.g AWS lambda, Google Cloud Functions and Azure Functions).
- Host: GitHub
- URL: https://github.com/odd12258053/agraffe
- Owner: odd12258053
- License: mit
- Created: 2020-09-04T07:15:15.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-12T06:45:41.000Z (over 1 year ago)
- Last Synced: 2024-05-01T19:11:23.935Z (6 months ago)
- Topics: asgi, async, asyncio, aws-lambda, azure-functions, fastapi, gcp-cloud-functions, python, python3, serverless, serverless-services, starlette, web
- Language: Python
- Homepage:
- Size: 317 KB
- Stars: 45
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fastapi - :octocat: agraffe :star: 20+ :fork_and_knife: 1+ - Agraffe, build API with ASGI in Serverless services (e.g AWS lambda, Google Cloud Functions and Azure Functions). (Async)
README
![icon](./resources/icon.png)
[![PyPI version](https://badge.fury.io/py/agraffe.svg)](https://badge.fury.io/py/agraffe)
![Test](https://github.com/odd12258053/agraffe/workflows/Test/badge.svg)Agraffe, build API with ASGI in Serverless services (e.g AWS lambda, Google Cloud Functions and Azure Functions).
## Support Services
- [x] Google Cloud Functions
- Python 3.7, 3.8, 3.9, 3.10, 3.11
- [x] AWS lambda (with API Gateway HTTP API or REST API, or with Function URL)
- Python 3.7, 3.8, 3.9
- [x] Azure Functions
- Python 3.7, 3.8, 3.9, 3.10## Requirements
Python 3.7+
## Installation
```sh
$ pip install agraffe
```## Example
Create it- Create a file `main.py` with:
```python
import contextlibfrom agraffe import Agraffe
from fastapi import FastAPI, Request@contextlib.asynccontextmanager
async def lifespan(app):
yield {'message': 'hello'}app = FastAPI(lifespan=lifespan)
@app.get("/")
def read_root():
return {"Hello": "World"}@app.get("/items/{item_id}")
def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}@app.get("/lifespan")
def lifespan_(request: Request):
return {"count": request.state.message}entry_point = Agraffe.entry_point(app)
```
```python
# or, for on GCP
from agraffe.services.google_cloud_functions import HttpCycledef entry_point(request):
return Agraffe(app, HttpCycle)(request=request)
```Deploy it
- Deploy the api with:
```sh
$ gcloud functions deploy {FUNCTION NAME} --entry-point entry_point --runtime python310 --trigger-http --allow-unauthenticated
```See `/example` for other services.
## License
This project is licensed under the terms of the MIT license.