Skip to main content

prefect.transactions

Functions

get_transaction

transaction

A context manager for opening and managing a transaction. Args:
  • - key: An identifier to use for the transaction
  • - store: The store to use for persisting the transaction result. If not provided, a default store will be used based on the current run context.
  • - commit_mode: The commit mode controlling when the transaction and child transactions are committed
  • - overwrite: Whether to overwrite an existing transaction record in the store
  • - write_on_commit: Whether to write the result to the store on commit. If not provided, will default will be determined by the current run context. If no run context is available, the value of PREFECT_RESULTS_PERSIST_BY_DEFAULT will be used.

atransaction

An asynchronous context manager for opening and managing an asynchronous transaction. Args:
  • - key: An identifier to use for the transaction
  • - store: The store to use for persisting the transaction result. If not provided, a default store will be used based on the current run context.
  • - commit_mode: The commit mode controlling when the transaction and child transactions are committed
  • - overwrite: Whether to overwrite an existing transaction record in the store
  • - write_on_commit: Whether to write the result to the store on commit. If not provided, the default will be determined by the current run context. If no run context is available, the value of PREFECT_RESULTS_PERSIST_BY_DEFAULT will be used.

Classes

IsolationLevel

Methods:

auto

Exposes enum.auto() to avoid requiring a second import to use AutoEnum

CommitMode

Methods:

auto

Exposes enum.auto() to avoid requiring a second import to use AutoEnum

TransactionState

Methods:

auto

Exposes enum.auto() to avoid requiring a second import to use AutoEnum

BaseTransaction

A base model for transaction state. Methods:

add_child

get

Get a stored value from the transaction. Child transactions will return values from their parents unless a value with the same name is set in the child transaction. Direct changes to returned values will not update the stored value. To update the stored value, use the set method. Args:
  • name: The name of the value to get
  • default: The default value to return if the value is not found
Returns:
  • The value from the transaction
Examples: Get a value from the transaction:
Get a value from a parent transaction:
Update a stored value:

get

Get the current context instance

get_active

get_parent

is_active

is_committed

is_pending

is_rolled_back

is_staged

model_copy

Duplicate the context model, optionally choosing which fields to include, exclude, or change. Attributes:
  • include: Fields to include in new model.
  • exclude: Fields to exclude from new model, as with values this takes precedence over include.
  • update: Values to change/add in the new model. Note: the data is not validated before creating the new model - you should trust this data.
  • deep: Set to True to make a deep copy of the model.
Returns:
  • A new model instance.

prepare_transaction

Helper method to prepare transaction state and validate configuration.

serialize

Serialize the context model to a dictionary that can be pickled with cloudpickle.

set

Set a stored value in the transaction. Args:
  • name: The name of the value to set
  • value: The value to set
Examples: Set a value for use later in the transaction:

stage

Stage a value to be committed later.

Transaction

A model representing the state of a transaction. Methods:

add_child

begin

commit

get

Get a stored value from the transaction. Child transactions will return values from their parents unless a value with the same name is set in the child transaction. Direct changes to returned values will not update the stored value. To update the stored value, use the set method. Args:
  • name: The name of the value to get
  • default: The default value to return if the value is not found
Returns:
  • The value from the transaction
Examples: Get a value from the transaction:
Get a value from a parent transaction:
Update a stored value:

get_active

get_parent

is_active

is_committed

is_pending

is_rolled_back

is_staged

prepare_transaction

Helper method to prepare transaction state and validate configuration.

read

reset

rollback

run_hook

set

Set a stored value in the transaction. Args:
  • name: The name of the value to set
  • value: The value to set
Examples: Set a value for use later in the transaction:

stage

Stage a value to be committed later.

AsyncTransaction

A model representing the state of an asynchronous transaction. Methods:

add_child

begin

commit

get

Get a stored value from the transaction. Child transactions will return values from their parents unless a value with the same name is set in the child transaction. Direct changes to returned values will not update the stored value. To update the stored value, use the set method. Args:
  • name: The name of the value to get
  • default: The default value to return if the value is not found
Returns:
  • The value from the transaction
Examples: Get a value from the transaction:
Get a value from a parent transaction:
Update a stored value:

get_active

get_parent

is_active

is_committed

is_pending

is_rolled_back

is_staged

prepare_transaction

Helper method to prepare transaction state and validate configuration.

read

reset

rollback

run_hook

set

Set a stored value in the transaction. Args:
  • name: The name of the value to set
  • value: The value to set
Examples: Set a value for use later in the transaction:

stage

Stage a value to be committed later.