Skip to main content

Python SDK for Inngest

Project description




Serverless event-driven queues, background jobs, and scheduled jobs for Python.
Add durable functions and workflows to any framework and platform.

Read the documentation and get started in minutes.

pypi versions discord twitter


Inngest Python SDK

Inngest's SDK adds durable functions to Python in a few lines of code. Using this SDK, you can write background jobs as step functions without new queueing infrastructure such as celery.

We currently support the following frameworks (but adding a new framework is easy!):

  • DigitalOcean Functions
  • Django (>=5.0)
  • FastAPI (>=0.110.0)
  • Flask (>=3.0.0)
  • Tornado (>=6.4)

Python 3.10 is the minimum version we support.

Getting started

Quick start guide

Examples

💡 You can mix async and non-async functions in the same app!

Basic (no steps)

This is a minimal example of an Inngest function:

import flask
import inngest.flask
import requests

inngest_client = inngest.Inngest(
    app_id="flask_example",
    is_production=False,
)

@inngest_client.create_function(
    fn_id="find_person",
    trigger=inngest.TriggerEvent(event="app/person.find"),
)
def fetch_person(ctx: inngest.ContextSync) -> dict:
    person_id = ctx.event.data["person_id"]
    res = requests.get(f"https://swapi.dev/api/people/{person_id}", verify=False)
    return res.json()

app = flask.Flask(__name__)

# Register functions with the Inngest server
inngest.flask.serve(
    app,
    inngest_client,
    [fetch_person],
)

app.run(port=8000)

Each function is automatically backed by its own queue. Functions can contain steps, which act as code level transactions. Each step retries on failure, and runs once on success. Function state is automatically managed.

Let's run the function. Send the following event in the local development server (Dev Server UI) and the fetch_person function will run:

{
  "name": "app/person.find",
  "data": {
    "person_id": 1
  }
}

Step run

The following example registers a function that will:

  1. Get the person ID from the event
  2. Fetch the person with that ID
  3. Fetch the person's ships
  4. Return a summary dict
@inngest_client.create_function(
    fn_id="find_ships",
    trigger=inngest.TriggerEvent(event="app/ships.find"),
)
def fetch_ships(ctx: inngest.ContextSync) -> dict:
    """
    Find all the ships a person has.
    """

    person_id = ctx.event.data["person_id"]

    def _fetch_person() -> dict:
        res = requests.get(f"https://swapi.dev/api/people/{person_id}", verify=False)
        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", _fetch_ship, ship_url)

        ship_names.append(ship["name"])

    return {
        "person_name": person["name"],
        "ship_names": ship_names,
    }

Send the following event in the Dev Server UI and the fetch_person function will run:

{
  "name": "app/ships.find",
  "data": {
    "person_id": 1
  }
}

Async function

@inngest_client.create_function(
    fn_id="find_person",
    trigger=inngest.TriggerEvent(event="app/person.find"),
)
async def fetch_person(ctx: inngest.Context) -> dict:
    person_id = ctx.event.data["person_id"]
    async with httpx.AsyncClient(verify=False) as client:
        res = await client.get(f"https://swapi.dev/api/people/{person_id}")
        return res.json()

Sending an event outside a function

Sometimes you want to send an event from a normal, non-Inngest function. You can do that using the client:

inngest_client.send_sync(inngest.Event(name="app/test", data={"person_id": 1}))

If you prefer async then use the send method instead:

await inngest_client.send(inngest.Event(name="app/test", data={"person_id": 1}))

Using in production

The Dev Server is not used in production. Inngest Cloud is used instead.

The INNGEST_EVENT_KEY and INNGEST_SIGNING_KEY environment variables must be set. These secrets establish trust between Inngest Cloud and your app. We also use request signature verification to mitigate man-in-the-middle attacks. You can read more about environment variables in our docs.

Your Inngest client must be in production mode. This is typically done with an environment variable:

inngest_client = inngest.Inngest(
    app_id="my_app",
    is_production=os.getenv("INNGEST_DEV") is None,
)

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

inngest-0.5.19a348.tar.gz (106.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

inngest-0.5.19a348-py3-none-any.whl (147.8 kB view details)

Uploaded Python 3

File details

Details for the file inngest-0.5.19a348.tar.gz.

File metadata

  • Download URL: inngest-0.5.19a348.tar.gz
  • Upload date:
  • Size: 106.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for inngest-0.5.19a348.tar.gz
Algorithm Hash digest
SHA256 6e172eadcafff83f60b966dd1ff27d5bde3b9ead6d6427f9e7fcadf4e885b3e6
MD5 f5e87e734327f6ef5524c8c734a30f87
BLAKE2b-256 73d48e44b1da4145c85f8fe6f5e45185ed0cf1f57ac57a5c583926e5b4ae10a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for inngest-0.5.19a348.tar.gz:

Publisher: inngest.yml on inngest/inngest-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file inngest-0.5.19a348-py3-none-any.whl.

File metadata

  • Download URL: inngest-0.5.19a348-py3-none-any.whl
  • Upload date:
  • Size: 147.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for inngest-0.5.19a348-py3-none-any.whl
Algorithm Hash digest
SHA256 0d808e850ed6ef76d92317fc39803dc6c50ea6639e1d0b1f833c84d9ba52ec18
MD5 a8797552619a83ad02948c3a43b99673
BLAKE2b-256 ad67c775d87822c031c969499d02686acb1179dcc20ffda0def3e82069a81a06

See more details on using hashes here.

Provenance

The following attestation bundles were made for inngest-0.5.19a348-py3-none-any.whl:

Publisher: inngest.yml on inngest/inngest-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page