Python middleware lifecycle

The order of middleware lifecycle hooks is as follows:

  1. transform_input
  2. before_memoization
  3. after_memoization
  4. before_execution
  5. after_execution
  6. transform_output
  7. before_response

All of these functions may be called multiple times in a single function run. For example, if your function has 2 steps then all of the hooks will run 3 times (once for each step and once for the function).

Additionally, there are two hooks when sending events:

  1. before_send_events
  2. after_send_events

Hook reference

transform_input

Called when receiving a request from Inngest and before running any functions. Commonly used to mutate data sent by Inngest, like decryption.

Arguments
  • Name
    ctx
    Type
    Context
    Required
    required
    Description

    ctx argument passed to Inngest functions.

  • Name
    function
    Type
    Function
    Required
    required
    Description

    Inngest function object.

  • Name
    steps
    Type
    StepMemos
    Required
    required
    Description

    Memoized step data.

before_memoization

Called before checking memoized step data.

after_memoization

Called after exhausting memoized step data.

before_execution

Called before executing "new code". For example, before_execution is called after returning the last memoized step data, since function-level code after that step is "new".

after_execution

Called after executing "new code".

transform_output

Called after a step or function returns. Commonly used to mutate data before sending it back to Inngest, like encryption.

Arguments
  • Name
    result
    Type
    TransformOutputResult
    Required
    required
    Description

before_response

Called before sending a response back to Inngest.

before_send_events

Called before sending events to Inngest.

Arguments
  • Name
    events
    Type
    list[Event]
    Required
    required
    Description

    Events to send.

after_send_events

Called after sending events to Inngest.

Arguments
  • Name
    result
    Type
    SendEventsResult
    Required
    required
    Description