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¶
Standard task call with raw arguments. |
|
Task call with deferred argument deserialization. |
|
Task call optimized for batch operations with shared arguments. |
Functions¶
Compute a deterministic hash of a call’s serialized arguments. |
API¶
- pynenc.call.compute_args_id(serialized_args: dict[str, str]) str[source]¶
Compute a deterministic hash of a call’s serialized arguments.
This is the canonical pynenc implementation. For each key (in sorted order) the SHA256 hasher is updated with the bytes::
JSON(key) + b"=" + JSON(value) + b";"
where JSON denotes
json.dumps(s, ensure_ascii=False). This format matches rustvello’s Rust implementation exactly, enabling heterogeneous clusters (Python workers + Rust workers) to agree on every invocation’sargs_id.The
pynenc-rustvelloplugin (and any future Rust/Go/JS binding) must produce byte-identical output for the same input — enforced by cross-system tests, not by importing rustvello here.
- 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:
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 call_id: pynenc.identifiers.call_id.CallId¶
Compute composite call identifier.
- Returns:
CallId combining task and argument identity
- serialized_args_for_concurrency_control(concurrency_control: pynenc.conf.config_task.ConcurrencyControlType) dict[str, str] | None[source]¶
Determines the serialized arguments required for one concurrency mode.
- Parameters:
concurrency_control (ConcurrencyControlType) – The concurrency mode to evaluate.
- Returns:
Serialized arguments required by the mode, or None when no argument filter is needed.
- to_dto() pynenc.models.call_dto.CallDTO[source]¶
Create serialization-ready DTO.
- Returns:
CallDTO with pre-serialized data
- 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:
Initialization
- property arguments: pynenc.arguments.Arguments¶
Lazily deserialize arguments on first access.
- 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.
- 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:
Initialization
- property serialized_arguments: dict[str, str]¶
Combine pre-serialized and freshly serialized arguments.
- Returns:
Complete serialized argument mapping