Python SDK for Inngest
Project description
Serverless event-driven queues, background jobs, and scheduled jobs for Python.
Works with any framework and platform.
Inngest Python SDK
🚧 Currently in alpha! Not guaranteed to be production ready! 🚧
Supported frameworks:
- Fast API
- Flask
- Tornado
Usage
Basic (no steps)
This is a minimal example of an Inngest function. It's missing some of our features but it's a good starting point.
import flask
import inngest.flask
import requests
@inngest.create_function(
fn_id="find_person",
trigger=inngest.TriggerEvent(event="app/person.find"),
)
async def fetch_person(
*,
event: inngest.Event,
step: inngest.Step,
**_kwargs: object,
) -> dict:
person_id = event.data["person_id"]
res = requests.get(f"https://swapi.dev/api/people/{person_id}")
return res.json()
app = flask.Flask(__name__)
inngest_client = inngest.Inngest(app_id="flask_example")
# Register functions with the Inngest server
inngest.flask.serve(
app,
inngest_client,
[fetch_person],
)
app.run(port=8000)
Step run
The following example registers a function that will:
- Get the person ID from the event
- Fetch the person with that ID
- Fetch the person's ships
- Return a summary dict
@inngest.create_function(
fn_id="find_ships",
trigger=inngest.TriggerEvent(event="app/ships.find"),
)
async def fetch_ships(
*,
event: inngest.Event,
step: inngest.Step,
**_kwargs: object,
) -> dict:
"""
Find all the ships a person has.
"""
person_id = event.data["person_id"]
def _fetch_person() -> dict:
res = requests.get(f"https://swapi.dev/api/people/{person_id}")
return res.json()
# Wrap the function with step.run to enable retries
person = step.run("fetch_person", _fetch_person)
def _fetch_ship(url: str) -> dict:
res = requests.get(url)
return res.json()
ship_names = []
for ship_url in person["starships"]:
# step.run works in loops!
ship = step.run("fetch_ship", lambda: _fetch_ship(ship_url))
ship_names.append(ship["name"])
return {
"person_name": person["name"],
"ship_names": ship_names,
}
Avoiding async functions
Completely avoiding `async`` functions only requires 2 differences:
- Use
step: inngest.StepSyncinstead ofstep: inngest.Step - Use
serve_syncinstead ofserve
@inngest.create_function(
fn_id="find_person",
trigger=inngest.TriggerEvent(event="app/person.find"),
)
def fetch_person(
*,
event: inngest.Event,
step: inngest.StepSync,
**_kwargs: object,
) -> dict:
person_id = event.data["person_id"]
res = requests.get(f"https://swapi.dev/api/people/{person_id}")
return res.json()
app = flask.Flask(__name__)
inngest_client = inngest.Inngest(app_id="flask_example")
inngest.flask.serve_sync(
app,
inngest_client,
[fetch_person],
)
💡 You can mix
asyncand non-asyncfunctions in the same app!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inngest-0.1.0a4.tar.gz.
File metadata
- Download URL: inngest-0.1.0a4.tar.gz
- Upload date:
- Size: 34.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9e2a3e834a01c09c572514126afbbe6e58aab89c92e35b94ad6207c1dcbb118
|
|
| MD5 |
b2366e3e309026b49511e69521f8ac40
|
|
| BLAKE2b-256 |
3c648208061ba754f8bacacee4986f86c98d018bf4fc336348bc60dde628a7b7
|
File details
Details for the file inngest-0.1.0a4-py3-none-any.whl.
File metadata
- Download URL: inngest-0.1.0a4-py3-none-any.whl
- Upload date:
- Size: 41.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a8915b310f473533fff2a289e781c641a063d535c587f3583ebed07f58fbd5d
|
|
| MD5 |
3dd0220a998b8d8c404dd40f1fe358c0
|
|
| BLAKE2b-256 |
e1ba92d7d9cf9e6db9b79e84438e9ae242622ed66e96fa09f5060a8019960e81
|