py_gql.execution.runtime#

class py_gql.execution.runtime.Runtime[source]#

Bases: abc.ABC

Runtime base class.

A runtime is a way for consumers to implement specific execution primitives (especially around I/O considerations).

ensure_wrapped(value)[source]#

Ensure values are wrapped in the necessary container type.

This is essentially used after execution has finished to make sure the final value conforms to the expected types (e.g. coroutines) and avoid consumers having to typecheck them needlessly.

Return type:Any
gather_values(values)[source]#

Group multiple wrapped values inside a single wrapped value.

This is equivalent to the asyncio.gather semantics.

Return type:Any
map_value(value, then, else_=None)[source]#

Execute a callback on a wrapped value, potentially catching exceptions.

This is used internally to orchestrate callbacks and should be treated similarly to await semantics map in Future combinators. The else_ argument can be used to handle exceptions (limited to a single exception type).

Return type:Any
submit(fn, *args, **kwargs)[source]#

Execute a function through the runtime.

Return type:Any
unwrap_value(value)[source]#

Recursively traverse wrapped values.

Given that resolution across the graph can span multiple level, this is used to support resolved values depending on deeper values (such as object fields).

wrap_callable(func)[source]#

Wrap a function to be called through the executor.

Return type:Callable[…, Any]
class py_gql.execution.runtime.SubscriptionRuntime[source]#

Bases: py_gql.execution.runtime.base.Runtime

Subscription runtime base class.

By default runtimes are assumed to not support subscriptions which usually require implementing some form of background streams to be useful. Implementing this instead of the base Runtime class notifies the library that subscriptions are available.

map_stream(source_stream, map_value)[source]#

Apply a mapping function to a stream / iterable of values.

Return type:Any
class py_gql.execution.runtime.BlockingRuntime[source]#

Bases: py_gql.execution.runtime.base.Runtime

Default runtime implementation which blocks the current thread.

ensure_wrapped(value)[source]#

Ensure values are wrapped in the necessary container type.

This is essentially used after execution has finished to make sure the final value conforms to the expected types (e.g. coroutines) and avoid consumers having to typecheck them needlessly.

Return type:Any
gather_values(values)[source]#

Group multiple wrapped values inside a single wrapped value.

This is equivalent to the asyncio.gather semantics.

Return type:Any
map_value(value, then, else_=None)[source]#

Execute a callback on a wrapped value, potentially catching exceptions.

This is used internally to orchestrate callbacks and should be treated similarly to await semantics map in Future combinators. The else_ argument can be used to handle exceptions (limited to a single exception type).

Return type:Any
submit(fn, *args, **kwargs)[source]#

Execute a function through the runtime.

Return type:Any
unwrap_value(value)[source]#

Recursively traverse wrapped values.

Given that resolution across the graph can span multiple level, this is used to support resolved values depending on deeper values (such as object fields).

wrap_callable(func)[source]#

Wrap a function to be called through the executor.

Return type:Callable[…, Any]
class py_gql.execution.runtime.AsyncIORuntime(loop=None, execute_blocking_functions_in_thread=True)[source]#

Bases: py_gql.execution.runtime.base.SubscriptionRuntime

Executor implementation to work with Python’s asyncio module.

ensure_wrapped(value)[source]#

Ensure values are wrapped in the necessary container type.

This is essentially used after execution has finished to make sure the final value conforms to the expected types (e.g. coroutines) and avoid consumers having to typecheck them needlessly.

Return type:Awaitable[~T]
gather_values(values)[source]#

Group multiple wrapped values inside a single wrapped value.

This is equivalent to the asyncio.gather semantics.

Return type:Union[Awaitable[Iterable[~T]], Iterable[~T]]
map_stream(source_stream, map_value)[source]#

Apply a mapping function to a stream / iterable of values.

Return type:AsyncIterable[~G]
map_value(value, then, else_=None)[source]#

Execute a callback on a wrapped value, potentially catching exceptions.

This is used internally to orchestrate callbacks and should be treated similarly to await semantics map in Future combinators. The else_ argument can be used to handle exceptions (limited to a single exception type).

Return type:Union[Awaitable[~G], ~G]
submit(fn, *args, **kwargs)[source]#

Execute a function through the runtime.

Return type:Union[Awaitable[~T], ~T]
unwrap_value(value)[source]#

Recursively traverse wrapped values.

Given that resolution across the graph can span multiple level, this is used to support resolved values depending on deeper values (such as object fields).

wrap_callable(func)[source]#

Wrap a function to be called through the executor.

Return type:Callable[…, Any]
class py_gql.execution.runtime.ThreadPoolRuntime(*args, **kwargs)[source]#

Bases: py_gql.execution.runtime.base.Runtime

Runtime implementation which executes in a thread pool.

This offloads every function passed to it in a thread pool by wrapping concurrent.futures.ThreadPoolExecutor.

All init arguments will be forwarded to concurrent.futures.ThreadPoolExecutor.

ensure_wrapped(value)[source]#

Ensure values are wrapped in the necessary container type.

This is essentially used after execution has finished to make sure the final value conforms to the expected types (e.g. coroutines) and avoid consumers having to typecheck them needlessly.

gather_values(values)[source]#

Group multiple wrapped values inside a single wrapped value.

This is equivalent to the asyncio.gather semantics.

map_value(value, then, else_=None)[source]#

Execute a callback on a wrapped value, potentially catching exceptions.

This is used internally to orchestrate callbacks and should be treated similarly to await semantics map in Future combinators. The else_ argument can be used to handle exceptions (limited to a single exception type).

submit(func, *args, **kwargs)[source]#

Execute a function through the runtime.

unwrap_value(value)[source]#

Recursively traverse wrapped values.

Given that resolution across the graph can span multiple level, this is used to support resolved values depending on deeper values (such as object fields).

wrap_callable(func)[source]#

Wrap a function to be called through the executor.