Serialization Strategies¶
- class globus_compute_sdk.serialize.SerializationStrategy¶
A
SerializationStrategyis in charge of converting function source code or arguments into string data and back again.- identifier: ClassVar[str]¶
The unique, 3-character string that identifies this strategy. The first two characters are the effective identifier; the third must always be the newline character
"\n".
- for_code: ClassVar[bool]¶
If
True, this strategy works with callable Python objects - functions, classes that implement__call__, etc. IfFalse, this strategy works with all other Python objects (ie, arguments and keyword arguments in submissions). Note that a singleSerializationStrategycannot support both callables and non-callables.
- abstract serialize(data: Any) str¶
Converts arbitrary Python data to a string representation.
- Parameters:
data – If
for_code, any callable Python object; if notfor_code, any other Python object. Serializers are not guaranteed to work with every callable or non-callable object.- Returns:
The string representation, which can be deserialized again by an instance of this strategy.
- Raises:
A
SerializationStrategymay raise for various reasons if it cannot handle a given Python object.
- abstract deserialize(payload: str) Any¶
Converts serialized string data back into the Python object it represents. Inverse of
serialize.- Parameters:
payload – Serialized data generated by an instance of this strategy.
- Returns:
The Python object represented by the payload.
- Raises:
If the payload wasn’t serialized by an instance of this strategy, or if encountering other unexpected errors. May also raise if the payload was serialized with a different Python version than what is currently running.
Note
In the tables below, the ✅ symbol means that the given strategy supports the given
scenario, while the ❌ symbol means the given strategy cannot support the given
scenario. Note that even when the ✅ symbol is present, Python serialization is
tricky and there may be edge cases where the given strategy will fail; if in doubt,
test a strategy against a payload using check_strategies().
Warning
Some code serialization strategies make a best-effort attempt to work across Python version boundaries, as shown via the ⚠️ symbol. While they may work in many situations, there is no guarantee they will work in every situation or between every pair of versions. However, using the same Python version on the submit side and execution side is guaranteed to work, and is the recommended approach whenever possible.
- class globus_compute_sdk.serialize.ComboSerializationStrategy¶
Bases:
SerializationStrategy,ABCCombines serialized results from multiple strategies into a single payload.
- class globus_compute_sdk.serialize.AllCodeStrategies¶
Bases:
ComboSerializationStrategyAttempts to serialize the function using each of the other code strategies:
The serialized results from each sub-strategy are combined into a single payload. When deserializing, it will try each sub-strategy in order until one succeeds.
Use this strategy when maximum compatibility is needed across different Python environments, and when payload size and serialization time are not critical.
Supports¶ Functions defined in Python interpreter
Code from notebooks
Interop between mismatched Python versions
Decorated functions
✅
✅
⚠️
✅
- class globus_compute_sdk.serialize.AllDataStrategies¶
Bases:
ComboSerializationStrategyAttempts to serialize Python data using each of the other data strategies:
The serialized results from each sub-strategy are combined into a single payload. When deserializing, it will try each sub-strategy in order until one succeeds.
Use this strategy when maximum compatibility is needed across different Python environments, and when payload size and serialization time are not critical.
- class globus_compute_sdk.serialize.CombinedCode¶
Bases:
SerializationStrategyThis strategy attempts to serialize the function using the other code strategies (namely
DillCodeSource,DillCode,DillCodeTextInspect,PureSourceDill, andPureSourceTextInspect), combining the results of each sub-strategy as the final serialized payload. When deserializing, it tries each sub-strategy in order until one successfully deserializes its part of the payload. Intended for maximum compatibility, but is slower than using a single strategy and generates larger payloads.Warning
Deprecated since version
4.0.0; useAllCodeStrategiesinstead.Supports¶ Functions defined in Python interpreter
Code from notebooks
Interop between mismatched Python versions
Decorated functions
✅
✅
⚠️
✅
- deserialize(payload: str, variation: int = 0) Any¶
If a variation is specified, try that strategy/payload if present. If variation is not specified, loop and return the first one that deserializes successfully. If none works, raise
Note variation is 1-indexed (ie. 2 means 2nd strategy), not the
identifierof the strategy (like"04\n","01\n").
- class globus_compute_sdk.serialize.DillCode¶
Bases:
SerializationStrategyDirectly serializes the function via
dill.dumps(), then encodes it in base 64.Supports¶ Functions defined in Python interpreter
Code from notebooks
Interop between mismatched Python versions
Decorated functions
❌
✅
❌
✅
- class globus_compute_sdk.serialize.DillCodeSource¶
Bases:
SerializationStrategyExtracts a function’s body via
dill.source.getsource(), serializes it withdill.dumps(), then encodes it via base 64.Warning
Deprecated since version
4.0.0; usePureSourceDillinstead.Supports¶ Functions defined in Python interpreter
Code from notebooks
Interop between mismatched Python versions
Decorated functions
✅
❌
⚠️
❌
- class globus_compute_sdk.serialize.DillCodeTextInspect¶
Bases:
SerializationStrategyExtracts a function’s body via
inspect.getsource(), serializes it withdill.dumps(), then encodes it via base 64.Warning
Deprecated since version
4.0.0; usePureSourceTextInspectinstead.Supports¶ Functions defined in Python interpreter
Code from notebooks
Interop between mismatched Python versions
Decorated functions
❌
✅
⚠️
❌
- class globus_compute_sdk.serialize.PureSourceDill¶
Bases:
SerializationStrategyExtracts a function’s definition via
dill.source.getsource()and sends the resulting string directly over the wire.Supports¶ Functions defined in Python interpreter
Code from notebooks
Interop between mismatched Python versions
Decorated functions
✅
❌
⚠️
❌
- class globus_compute_sdk.serialize.PureSourceTextInspect¶
Bases:
SerializationStrategyExtracts a function’s definition via
inspect.getsource()and sends the resulting string directly over the wire.Supports¶ Functions defined in Python interpreter
Code from notebooks
Interop between mismatched Python versions
Decorated functions
❌
✅
⚠️
❌
- class globus_compute_sdk.serialize.DillDataBase64¶
Bases:
SerializationStrategySerializes Python data to binary via
dill.dumps(), and then encodes that binary to a string using base 64 representation.
- class globus_compute_sdk.serialize.JSONData¶
Bases:
SerializationStrategySerializes Python data to a string via
json.dumps().