Advanced Usage
Transaction Options
Transactions can be customized with different options:
-
isolation(IsolationLevel) – transaction isolation level -
readonly(bool) – if true the transaction will be readonly -
deferrable(bool) – if true the transaction will be deferrable
Returns the default TransactionOptions.
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 gel.Client.transaction() or gel.AsyncIOClient.transaction().
Retry Options
Individual EdgeQL commands or whole transaction blocks are automatically retried on retryable errors. By default, gel-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:
Adds a backoff rule for a particular condition
-
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
Returns the default RetryOptions.
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.
-
default_module(strorNone) – The default module that the future commands will be executed with.Nonemeans the default default module on the server-side, which is usually justdefault. -
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 likemy_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.
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.
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.
-
aliases_dict(dict[str,str] orNone) – 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 applyingaliases_dictif set.
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.
Returns a new State copy with adjusted session config.
This is equivalent to using the configure session set command.
-
config_dict(dict[str,object] orNone) – 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 applyingconfig_dictif set.
Returns a new State copy without specified session config.
This is equivalent to using the configure session reset command.
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.
-
globals_dict(dict[str,object] orNone) – 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 applyingglobals_dictif set.
Returns a new State copy without specified globals.
This is equivalent to using the reset global command.
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.