Python middleware lifecycle
The order of middleware lifecycle hooks is as follows:
transform_input
before_memoization
after_memoization
before_execution
after_execution
transform_output
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:
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.
- 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.
- 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.
- Name
events
- Type
- list[Event]
- Required
- required
- Description
Events to send.
after_send_events
Called after sending events to Inngest.
- Name
result
- Type
- SendEventsResult
- Required
- required
- Description