pynenc.call

Task call representations with optimized argument handling.

This module defines the core call abstractions for Pynenc tasks, optimized for different construction contexts:

  • Call: Standard client-side construction with raw arguments

  • LazyCall: State backend construction with deferred deserialization

  • PreSerializedCall: Batch construction with shared pre-serialized arguments

Key components:

  • CallId: Structured identifier combining task and argument identity

  • CallDTO: Serialization-ready data transfer object

  • compute_args_id: Deterministic hashing from serialized arguments

Module Contents

Classes

Call

Standard task call with raw arguments.

LazyCall

Task call with deferred argument deserialization.

PreSerializedCall

Task call optimized for batch operations with shared arguments.

Functions

compute_args_id

Compute deterministic argument hash from serialized form.

API

pynenc.call.compute_args_id(serialized_args: dict[str, str]) str[source]

Compute deterministic argument hash from serialized form.

class pynenc.call.Call(task: Task[Params, Result], arguments: pynenc.arguments.Arguments | None = None, _serialized_arguments: dict[str, str] | None = None)[source]

Bases: typing.Generic[pynenc.types.Params, pynenc.types.Result]

Standard task call with raw arguments.

Created client-side when invoking tasks. Arguments are stored as Python objects and serialized on-demand for distribution.

Parameters:
  • task (Task[Params, Result]) – Associated task definition

  • arguments (Arguments) – Raw Python argument values

Initialization

property app: pynenc.app.Pynenc
property arguments: pynenc.arguments.Arguments

Get the arguments for this call. This property allows subclasses to override argument handling.

Returns:

Arguments object containing call arguments

property serialized_arguments: dict[str, str]

Serialize arguments with external storage for large values.

Returns:

Mapping of argument names to serialized values or storage keys

Raises:

SerializationError – If an argument cannot be serialized, enriched with task context.

property args_id: str

Compute argument identity hash.

Returns:

SHA256 hash of serialized arguments

property call_id: pynenc.identifiers.call_id.CallId

Compute composite call identifier.

Returns:

CallId combining task and argument identity

arg_keys() set[str]

Set of argument keys for this call.

property serialized_args_for_concurrency_check: dict[str, str] | None

Determines the call arguments required for the task concurrency check.

Returns:

A dictionary of serialized argument strings required for concurrency control, or None if concurrency control is disabled.

to_dto() pynenc.models.call_dto.CallDTO[source]

Create serialization-ready DTO.

Returns:

CallDTO with pre-serialized data

__str__() str[source]
__repr__() str[source]
__hash__() int[source]
__eq__(other: Any) bool[source]
class pynenc.call.LazyCall(task: Task[Params, Result], _serialized_arguments: dict[str, str], _call_id: pynenc.identifiers.call_id.CallId)[source]

Bases: pynenc.call.Call[pynenc.types.Params, pynenc.types.Result]

Task call with deferred argument deserialization.

Created by state backends when loading persisted invocations. Arguments remain serialized until accessed, avoiding deserialization cost for identity-only operations (concurrency checks, status queries).

Must be constructed via from_dto factory method - do not instantiate directly.

Parameters:
  • task (Task[Params, Result]) – Associated task definition

  • _serialized_arguments (dict[str, str]) – Pre-serialized argument mapping

  • _args_id (str) – Pre-computed argument hash

Initialization

property arguments: pynenc.arguments.Arguments

Lazily deserialize arguments on first access.

arg_keys() set[str]
classmethod from_dto(app: pynenc.app.Pynenc, dto: pynenc.models.call_dto.CallDTO) LazyCall[Params, Result][source]

Construct LazyCall from DTO without deserialization.

Primary factory method for state backend usage.

Parameters:
  • app (Pynenc) – Pynenc application instance

  • dto (CallDTO) – Data transfer object with serialized data

Returns:

LazyCall with deferred deserialization

__str__() str[source]
class pynenc.call.PreSerializedCall(task: Task[Params, Result], common_args: dict[str, Any] | None = None, common_serialized_args: dict[str, str] | None = None, other_args: dict[str, Any] | None = None)[source]

Bases: pynenc.call.Call[pynenc.types.Params, pynenc.types.Result]

Task call optimized for batch operations with shared arguments.

Used when distributing many similar tasks with large common arguments. Common arguments are pre-serialized once; unique arguments serialized per-call. Enables efficient batch routing without redundant serialization.

Parameters:
  • task (Task[Params, Result]) – Associated task definition

  • pre_serialized_args (dict[str, str]) – Shared pre-serialized arguments

  • other_args (dict[str, Any]) – Call-specific raw arguments

Initialization

property serialized_arguments: dict[str, str]

Combine pre-serialized and freshly serialized arguments.

Returns:

Complete serialized argument mapping

abstract property serialized_args_for_concurrency_check: dict[str, str] | None
__str__() str[source]