Globus Compute Serializer¶
- class globus_compute_sdk.serialize.ComputeSerializer(strategy_code: SerializationStrategy | type[SerializationStrategy] | str | None = None, strategy_data: SerializationStrategy | type[SerializationStrategy] | str | None = None, *, allowed_deserializer_types: Iterable[SerializationStrategy | type[SerializationStrategy] | str | AllowlistWildcard] | None = None)¶
Provides a uniform interface to Compute’s various serialization strategies.
- Parameters:
strategy_code – The serialization strategy for code. If passed as a string, must be a valid import path to a known strategy; if not supplied, uses
DEFAULT_STRATEGY_CODE.strategy_data – The serialization strategy for data. If passed as a string, must be a valid import path to a known strategy; if not supplied, uses
DEFAULT_STRATEGY_DATA.allowed_deserializers – A list of strategies (or import paths) that are allowed to deserialize data/code. Requires at least one code and one data strategy to be specified. If falsy, all deserializers are allowed.
- Raises:
If any serializer is unknown to Compute, or if any of the arguments are not in the expected format.
- static serialize_from_list(data: Any, strategies: Iterable[SerializationStrategy | type[SerializationStrategy] | str]) str¶
Iterates through the list of Strategylike objects, validating each one and attempting serialization. Returns the first successful serialization, or, if all Strategylike objects fail to validate or serialize, raises an error with the details of each failure.
If strategies is falsy, uses the default strategies.
- serialize(data: Any) str¶
Converts Python data to a string representation, using this serializer’s configured strategies.
- Parameters:
data – Any Python object that can be serialized by this serializer’s strategies. An error is raised if this object is incompatible.
- Returns:
The string representation, which can be deserialized by any
ComputeSerializer.- Raises:
If this serializer’s strategy is unable to serialize this data.
- deserialize(payload: str) Any¶
Converts a string representation of a Python object generated by a
ComputeSerializerback to the object it represents. Inverse ofserialize().- Parameters:
payload – Serialized data to turn back into Python data.
- Returns:
The Python data represented by that string.
- Raises:
If the payload is in the wrong format, or if it was not serialized with an allowed strategy.
- static pack_buffers(buffers: list[str]) str¶
Combines a list of Compute-serialized buffers into a single string format understood by the
ComputeSerializer.- Parameters:
buffers – A list of serialized buffers, as produced by
serialize().
- static unpack_buffers(packed_buffer: str) list[str]¶
Splits a packed buffer string into its constituents. Inverse of
pack_buffers().- Parameters:
packed_buffer – A packed buffer string as produced by
pack_buffers().
- unpack_and_deserialize(packed_buffer: str) list[Any]¶
Takes a packed string containing three buffers, unpacks them, and deserializes.
- Parameters:
packed_buffer – A packed buffer string as produced by
pack_buffers().- Raises:
If
packed_buffersdoes not contain exactly three buffers.
- check_strategies(function: Callable, *args: Any, **kwargs: Any) list[Any]¶
Check that the given function, args, and kwargs are compatible with this
ComputeSerializer’s serialization strategies.Uses the same interface as the
Executor’ssubmit()method. Returns a list containing the function, args, and kwargs after going through serialization and deserialization.For example:
def function(x, y=None): return x+y serde = ComputeSerializer() rf, args, kwargs = serde.check_strategies(function, 3, y=4) assert rf(*args, **kwargs) == 7
- assert_deserializer_allowed(strategy: SerializationStrategy) None¶
Raise an error if there is a configured deserializer allowlist and the given
SerializationStrategyis not an instance of any type in that allowlist.- Parameters:
strategy – The strategy that was requested for deserialization.
- Raises:
If
strategyis not allowed in this serializer.
- globus_compute_sdk.serialize.facade.Strategylike¶
This type encapsulates all the ways a serialization strategy can be specified to a
ComputeSerializer.SerializationStrategyclasses and instances can be passed directly and are essentially equivalent; alternatively, an import path pointing to such an instance or class can be passed as a string.alias of
SerializationStrategy|type[SerializationStrategy] |str
- class globus_compute_sdk.serialize.AllowlistWildcard(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
Special values that can be included in deserializer allowlists to allow all serializers of a certain kind.
- CODE = 'globus_compute_sdk.*Code'¶
Include this to allow all code serializers from the Compute SDK.
- DATA = 'globus_compute_sdk.*Data'¶
Include this to allow all data serializers from the Compute SDK.
- globus_compute_sdk.serialize.concretes.DEFAULT_STRATEGY_CODE¶
The code serialization strategy used by
ComputeSerializerwhen one is not specified.
- globus_compute_sdk.serialize.concretes.DEFAULT_STRATEGY_DATA¶
The data serialization strategy used by
ComputeSerializerwhen one is not specified.