Search
ctrl/
Ask AI
Light
Dark
System

Advanced Usage

Transactions can be customized with different options:

class

TransactionOptions
TransactionOptions(isolation = IsolationLevel.Serializable, readonly = False, deferrable = False)
Parameters
  • isolation (IsolationLevel) – transaction isolation level

  • readonly (bool) – if true the transaction will be readonly

  • deferrable (bool) – if true the transaction will be deferrable

classmethod

TransactionOptions.defaults()

Returns the default TransactionOptions.

class

IsolationLevel

Isolation level for transaction

attribute

IsolationLevel.Serializable

Serializable isolation level

TransactionOptions can be set on Client or AsyncIOClient using one of these methods:

These methods return a “shallow copy” of the current client object with modified transaction options. Both self and the returned object can be used, but different transaction options will applied respectively.

Transaction options are used by the future calls to the method edgedb.Client.transaction() or edgedb.AsyncIOClient.transaction().

Individual EdgeQL commands or whole transaction blocks are automatically retried on retryable errors. By default, edgedb-python will try at most 3 times, with an exponential backoff time interval starting from 100ms, plus a random hash under 100ms.

Retry rules can be granularly customized with different retry options:

class

RetryOptions
RetryOptions(attempts, backoff = default_backoff)
Parameters
  • attempts (int) – the default number of attempts

  • backoff (Callable[[int], Union[float, int]]) – the default backoff function

method

RetryOptions.with_rule()
RetryOptions.with_rule(condition, attempts = None, backoff = None)

Adds a backoff rule for a particular condition

Parameters
  • condition (RetryCondition) – condition that will trigger this rule

  • attempts (int) – number of times to retry

  • backoff (Callable[[int], Union[float, int]]) – function taking the current attempt number and returning the number of seconds to wait before the next attempt

classmethod

RetryOptions.defaults()

Returns the default RetryOptions.

class

RetryCondition

Specific condition to retry on for fine-grained control

attribute

RetryCondition.TransactionConflict

Triggered when a TransactionConflictError occurs.

attribute

RetryCondition.NetworkError

Triggered when a ClientError occurs.

RetryOptions can be set on Client or AsyncIOClient using one of these methods:

These methods return a “shallow copy” of the current client object with modified retry options. Both self and the returned object can be used, but different retry options will applied respectively.

State is an execution context that affects the execution of EdgeQL commands in different ways: default module, module aliases, session config and global values.

class

State
State(default_module = None, module_aliases = {}, config = {}, globals_ = {})
Parameters
  • default_module (str or None) – The default module that the future commands will be executed with. None means the default default module on the server-side, which is usually just default.

  • module_aliases (dict[str, str]) – Module aliases mapping of alias -> target module.

  • config (dict[str, object]) – Non system-level config settings mapping of config name -> config value.For available configuration parameters refer to the Config documentation.

  • globals (dict[str, object]) – Global values mapping of global name -> global value.The global name can be either a qualified name like my_mod::glob2, or a simple name under the default module. Simple names will be prefixed with the default module, while module aliases in qualified names - if any - will be resolved into actual module names.

method

State.with_default_module()
State.with_default_module(module = None)

Returns a new State copy with adjusted default module.

This will not affect the globals that are already stored in this state using simple names, because their names were resolved before this call to with_default_module(), which affects only the future calls to the with_globals() method.

This is equivalent to using the set module command, or using the reset module command when giving None.

Parameters

module (str or None) – Adjust the default module. If module is None, the default module will be reset to default.

method

State.with_module_aliases()
State.with_module_aliases(aliases_dict = None, /, ** aliases)

Returns a new State copy with adjusted module aliases.

This will not affect the globals that are already stored in this state using module aliases, because their names were resolved before this call to with_module_aliases(), which affects only the future calls to the with_globals() method.

This is equivalent to using the set alias command.

Parameters
  • aliases_dict (dict[str, str] or None) – Adjust the module aliases by merging with the given alias -> target module mapping. This is an optional positional-only argument.

  • aliases (dict[str, str]) – Adjust the module aliases by merging with the given alias -> target module mapping, after applying aliases_dict if set.

method

State.without_module_aliases()
State.without_module_aliases(* aliases)

Returns a new State copy without specified module aliases.

This will not affect the globals that are already stored in this state using module aliases, because their names were resolved before this call to without_module_aliases(), which affects only the future calls to the with_globals() method.

This is equivalent to using the reset alias command.

Parameters

aliases (tuple[str]) – Adjust the module aliases by dropping the specified aliases if they were set, no errors will be raised if they weren’t.If no aliases were given, all module aliases will be dropped.

method

State.with_config()
State.with_config(config_dict = None, /, ** config)

Returns a new State copy with adjusted session config.

This is equivalent to using the configure session set command.

Parameters
  • config_dict (dict[str, object] or None) – Adjust the config settings by merging with the given config name -> config value mapping. This is an optional positional-only argument.

  • config (dict[str, object]) – Adjust the config settings by merging with the given config name -> config value mapping, after applying config_dict if set.

method

State.without_config()
State.without_config(* config_names)

Returns a new State copy without specified session config.

This is equivalent to using the configure session reset command.

Parameters

config_names (tuple[str]) – Adjust the config settings by resetting the specified config to default if they were set, no errors will be raised if they weren’t.If no names were given, all session config will be reset.

method

State.with_globals()
State.with_globals(globals_dict = None, /, ** globals_)

Returns a new State copy with adjusted global values.

The globals are stored with their names resolved into the actual fully-qualified names using the current default module and module aliases set on this state.

This is equivalent to using the set global command.

Parameters
  • globals_dict (dict[str, object] or None) – Adjust the global values by merging with the given global name -> global value mapping. This is an optional positional-only argument.

  • globals (dict[str, object]) – Adjust the global values by merging with the given global name -> global value mapping, after applying globals_dict if set.

method

State.without_globals()
State.without_globals(* global_names)

Returns a new State copy without specified globals.

This is equivalent to using the reset global command.

Parameters

global_names (tuple[str]) – Adjust the globals by resetting the specified globals to default if they were set, no errors will be raised if they weren’t.If no names were given, all globals will be reset.

State can be set on Client or AsyncIOClient using one of these methods:

These methods return a “shallow copy” of the current client object with modified state, affecting all future commands executed using the returned copy. Both self and the returned object can be used, but different state will applied respectively.

Alternatively, shortcuts are available on client objects:

They work the same way as with_state, and adjusts the corresponding state values.