Advanced Usage

Transaction Options

Transactions can be customized with different options:

class

TransactionOptions

Advanced Usage - 图1

Advanced Usage - 图2

Advanced Usage - 图3

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()

Advanced Usage - 图4

Advanced Usage - 图5

Advanced Usage - 图6

Returns the default TransactionOptions.

class

IsolationLevel

Advanced Usage - 图7

Advanced Usage - 图8

Advanced Usage - 图9

Isolation level for transaction

attribute

IsolationLevel.Serializable

Advanced Usage - 图10

Advanced Usage - 图11

Advanced Usage - 图12

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().

Retry Options

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

Advanced Usage - 图13

Advanced Usage - 图14

Advanced Usage - 图15

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()

Advanced Usage - 图16

Advanced Usage - 图17

Advanced Usage - 图18

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()

Advanced Usage - 图19

Advanced Usage - 图20

Advanced Usage - 图21

Returns the default RetryOptions.

class

RetryCondition

Advanced Usage - 图22

Advanced Usage - 图23

Advanced Usage - 图24

Specific condition to retry on for fine-grained control

attribute

RetryCondition.TransactionConflict

Advanced Usage - 图25

Advanced Usage - 图26

Advanced Usage - 图27

Triggered when a TransactionConflictError occurs.

attribute

RetryCondition.NetworkError

Advanced Usage - 图28

Advanced Usage - 图29

Advanced Usage - 图30

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

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

Advanced Usage - 图31

Advanced Usage - 图32

Advanced Usage - 图33

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()

Advanced Usage - 图34

Advanced Usage - 图35

Advanced Usage - 图36

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()

Advanced Usage - 图37

Advanced Usage - 图38

Advanced Usage - 图39

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()

Advanced Usage - 图40

Advanced Usage - 图41

Advanced Usage - 图42

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()

Advanced Usage - 图43

Advanced Usage - 图44

Advanced Usage - 图45

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()

Advanced Usage - 图46

Advanced Usage - 图47

Advanced Usage - 图48

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()

Advanced Usage - 图49

Advanced Usage - 图50

Advanced Usage - 图51

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()

Advanced Usage - 图52

Advanced Usage - 图53

Advanced Usage - 图54

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.