# Python SDK

> Install the Python SDK, create a client, and find every API it offers.

The Python SDK defines durable functions, sends events, and serves your functions from FastAPI, Flask, or Django. It also runs [Connect](/docs-markdown/durable-execution/deploying-functions/connect) workers. Some features are TypeScript-only for now; see [feature support](/docs-markdown/sdks#feature-support).

## Install

The SDK needs Python 3.10 or newer.

```shell
pip install inngest
```

## Create a client and serve functions

Create one client for your app, define functions with it, and serve them from your web framework. This example uses FastAPI:

```python {{ title: "main.py" }}
import logging

from fastapi import FastAPI
import inngest
import inngest.fast_api

inngest_client = inngest.Inngest(
    app_id="my-app",
    logger=logging.getLogger("uvicorn"),
)

@inngest_client.create_function(
    fn_id="process-task",
    trigger=inngest.TriggerEvent(event="app/task.created"),
)
async def process_task(ctx: inngest.Context) -> dict[str, object]:
    return await ctx.step.run("handle-task", lambda: {"processed": True})

app = FastAPI()
inngest.fast_api.serve(app, inngest_client, [process_task])
```

The [Python quick start](/docs-markdown/durable-execution/quick-start/python-quick-start) walks through a full example with the Dev Server.

## Define steps

Steps are the units of work Inngest retries and memoizes. The Python SDK gives you two ways to write them.

**Imperative:** call `ctx.step.run()` with a step ID and a handler inside your function.

```python
@inngest_client.create_function(
    fn_id="greet-user",
    trigger=inngest.TriggerEvent(event="app/greet-user"),
)
async def greet_user(ctx: inngest.Context) -> str:
    async def prepare_greeting() -> str:
        return f"Welcome, {ctx.event.data['name']}!"

    return await ctx.step.run("prepare-greeting", prepare_greeting)
```

**Decorator (experimental):** decorate a function with `step` from `inngest.experimental`. Calls inside an Inngest function run as steps; calls anywhere else run the function directly.

```python
from inngest.experimental import step

@step("prepare-greeting")
async def prepare_greeting(name: str) -> str:
    return f"Welcome, {name}!"

@inngest_client.create_function(
    fn_id="greet-user",
    trigger=inngest.TriggerEvent(event="app/greet-user"),
)
async def greet_user(ctx: inngest.Context) -> str:
    return await prepare_greeting(str(ctx.event.data["name"]))
```

Both produce the same step. Use `ctx.step.run()` for logic specific to one function; use the decorator for steps you share across functions or also call from regular code. See [choosing `step.run` or the decorator](/docs-markdown/reference/python/steps/run?ref=docs-reference-python#choosing-step-run-or-the-decorator).

## Reference

**Client and events**

- [Inngest client](/docs-markdown/reference/python/client/overview)
- [Send events](/docs-markdown/reference/python/client/send)

**Functions**

- [Create a function](/docs-markdown/reference/python/functions/create): triggers, retries, flow control, and cancellation options

**Steps**

- [`run`](/docs-markdown/reference/python/steps/run), [`sleep`](/docs-markdown/reference/python/steps/sleep), and [`sleep_until`](/docs-markdown/reference/python/steps/sleep-until)
- [`wait_for_event`](/docs-markdown/reference/python/steps/wait-for-event)
- [`invoke`](/docs-markdown/reference/python/steps/invoke), [`invoke_by_id`](/docs-markdown/reference/python/steps/invoke_by_id), and [`send_event`](/docs-markdown/reference/python/steps/send-event)
- [`parallel`](/docs-markdown/reference/python/steps/parallel)
- [`@step` decorator](/docs-markdown/reference/python/steps/run?ref=docs-reference-python#step-decorator) (experimental): turn a Python function into a reusable step

**Middleware**

- [Overview](/docs-markdown/reference/python/middleware/overview) and [lifecycle](/docs-markdown/reference/python/middleware/lifecycle)

**Configuration**

- [Environment variables](/docs-markdown/reference/python/overview/env-vars)
- [Production mode](/docs-markdown/reference/python/overview/prod-mode)

**Guides**

- [Testing](/docs-markdown/reference/python/guides/testing), [Pydantic](/docs-markdown/reference/python/guides/pydantic), and [Modal](/docs-markdown/reference/python/guides/modal)
- [Realtime in Python](/docs-markdown/realtime/reference#python) (beta)

**Migrations**

- [v0.4 to v0.5](/docs-markdown/reference/python/migrations/v0.4-to-v0.5) and [v0.3 to v0.4](/docs-markdown/reference/python/migrations/v0.3-to-v0.4)

## Source code

The Python SDK is open source on GitHub: [ inngest/inngest-py](https://github.com/inngest/inngest-py). Releases are published to [PyPI](https://pypi.org/project/inngest/).