Skip to main content

Python SDK for Inngest

Project description




Serverless event-driven queues, background jobs, and scheduled jobs for Python.
Works with any framework and platform.

Read the documentation and get started in minutes.

pypi versions discord twitter


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:

  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.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:

  1. Use step: inngest.StepSync instead of step: inngest.Step
  2. Use serve_sync instead of serve
@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 async and non-async functions 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

inngest-0.1.0a4.tar.gz (34.7 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.1.0a4-py3-none-any.whl (41.4 kB view details)

Uploaded Python 3

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

Hashes for inngest-0.1.0a4.tar.gz
Algorithm Hash digest
SHA256 f9e2a3e834a01c09c572514126afbbe6e58aab89c92e35b94ad6207c1dcbb118
MD5 b2366e3e309026b49511e69521f8ac40
BLAKE2b-256 3c648208061ba754f8bacacee4986f86c98d018bf4fc336348bc60dde628a7b7

See more details on using hashes here.

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

Hashes for inngest-0.1.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 5a8915b310f473533fff2a289e781c641a063d535c587f3583ebed07f58fbd5d
MD5 3dd0220a998b8d8c404dd40f1fe358c0
BLAKE2b-256 e1ba92d7d9cf9e6db9b79e84438e9ae242622ed66e96fa09f5060a8019960e81

See more details on using hashes here.

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