Globus Compute Serializer¶
- class globus_compute_sdk.serialize.ComputeSerializer(strategy_code: SerializationStrategy | None = None, strategy_data: SerializationStrategy | None = None, *, allowed_deserializer_types: Iterable[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 not supplied, uses
DEFAULT_STRATEGY_CODE
.strategy_data – The serialization strategy for data. If not supplied, uses
DEFAULT_STRATEGY_DATA
.allowed_deserializers – A list of strategies that are allowed to deserialize data/code, in the form of
SerializationStrategy
subclasses (not instances of those classes!), import paths to those classes, or the specialAllowlistWildcard
values. 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.
- 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
ComputeSerializer
back 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_buffers
does 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
SerializationStrategy
is not an instance of any type in that allowlist.- Parameters:
strategy – The strategy that was requested for deserialization.
- Raises:
If
strategy
is not allowed in this serializer.
- class globus_compute_sdk.serialize.AllowlistWildcard(value)¶
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: DillCode¶
The code serialization strategy used by
ComputeSerializer
when one is not specified.
- globus_compute_sdk.serialize.concretes.DEFAULT_STRATEGY_DATA: DillDataBase64¶
The data serialization strategy used by
ComputeSerializer
when one is not specified.