Skip to main content

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.

Metadata

Release files for agraffe 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agraffe 0.7.0
File Size Uploaded
agraffe-0.7.0.tar.gz 52.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agraffe 0.7.0
File Interpreter ABI Platform
agraffe-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.2 kB

Release files / agraffe-0.7.0.tar.gz

Download URL agraffe-0.7.0.tar.gz
Size 52.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fc1cb578bb9bc8290cb9f7317babe61d20fb794a73b49f7087743fe26d5ac13a
BLAKE2b-256 checksum
How to use checksums
31fd78580ea1c8aee2e8a4eac948014bd5fe439a40bfee4f89ebd3603bd670f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release files / agraffe-0.7.0-py3-none-any.whl

Download URL agraffe-0.7.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bc70168854801fa3d8c5cefc9f17515d17a6b938c61894667e98714d804e3cc
BLAKE2b-256 checksum
How to use checksums
2e07f1d20063815b7cbf7a9cd85c946c7f8d2328e353b219ca20ff67e5b9c2af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page