Skip to main content

Agraffe, build API with ASGI in Serverless services (e.g AWS lambda, Google Cloud Functions and Azure Functions).

Project description

icon

PyPI version Test

Agraffe, build API with ASGI in Serverless services (e.g AWS lambda, Google Cloud Functions and Azure Functions).

Support Services

  • Google Cloud Functions
    • Python 3.7, 3.8, 3.9, 3.10, 3.11(preview)
  • AWS lambda (with API Gateway HTTP API or REST API, or with Function URL)
    • Python 3.7, 3.8, 3.9
  • Azure Functions
    • Python 3.7, 3.8, 3.9, 3.10(preview)

Requirements

Python 3.7+

Installation

$ pip install agraffe

Example

Create it

  • Create a file main.py with:
import contextlib

from 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)
# or, for on GCP
from agraffe.services.google_cloud_functions import HttpCycle

def entry_point(request):
    return Agraffe(app, HttpCycle)(request=request)

Deploy it

  • Deploy the api with:
$ 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.

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

agraffe-0.7.0.tar.gz (52.3 kB view details)

Uploaded Source

Built Distribution

agraffe-0.7.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file agraffe-0.7.0.tar.gz.

File metadata

  • Download URL: agraffe-0.7.0.tar.gz
  • Upload date:
  • Size: 52.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for agraffe-0.7.0.tar.gz
Algorithm Hash digest
SHA256 fc1cb578bb9bc8290cb9f7317babe61d20fb794a73b49f7087743fe26d5ac13a
MD5 db46f6c17251ea4d681013f50f5ceea9
BLAKE2b-256 31fd78580ea1c8aee2e8a4eac948014bd5fe439a40bfee4f89ebd3603bd670f3

See more details on using hashes here.

File details

Details for the file agraffe-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: agraffe-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for agraffe-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bc70168854801fa3d8c5cefc9f17515d17a6b938c61894667e98714d804e3cc
MD5 2947c5ae5ba92d6daef240da954582b8
BLAKE2b-256 2e07f1d20063815b7cbf7a9cd85c946c7f8d2328e353b219ca20ff67e5b9c2af

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