prefect.serializers
Serializer implementations for converting objects to bytes and bytes to objects.
All serializers are based on the Serializer
class and include a type
string that
allows them to be referenced without referencing the actual class. For example, you
can get often specify the JSONSerializer
with the string "json". Some serializers
support additional settings for configuration of serialization. These are stored on
the instance so the same settings can be used to load saved objects.
All serializers must implement dumps
and loads
which convert objects to bytes and
bytes to an object respectively.
CompressedJSONSerializer
Bases: CompressedSerializer
A compressed serializer preconfigured to use the json serializer.
Source code in src/prefect/serializers.py
250 251 252 253 254 255 256 257 |
|
CompressedPickleSerializer
Bases: CompressedSerializer
A compressed serializer preconfigured to use the pickle serializer.
Source code in src/prefect/serializers.py
240 241 242 243 244 245 246 247 |
|
CompressedSerializer
Bases: Serializer
Wraps another serializer, compressing its output.
Uses lzma
by default. See compressionlib
for using alternative libraries.
Attributes:
Name | Type | Description |
---|---|---|
serializer |
Serializer
|
The serializer to use before compression. |
compressionlib |
str
|
The import path of a compression module to use.
Must have methods |
level |
str
|
If not null, the level of compression to pass to |
Source code in src/prefect/serializers.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
JSONSerializer
Bases: Serializer
Serializes data to JSON.
Input types must be compatible with the stdlib json library.
Wraps the json
library to serialize to UTF-8 bytes instead of string types.
Source code in src/prefect/serializers.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
PickleSerializer
Bases: Serializer
Serializes objects using the pickle protocol.
- Uses
cloudpickle
by default. Seepicklelib
for using alternative libraries. - Stores the version of the pickle library to check for compatibility during deserialization.
- Wraps pickles in base64 for safe transmission.
Source code in src/prefect/serializers.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
Serializer
Bases: BaseModel
, Generic[D]
, ABC
A serializer that can encode objects of type 'D' into bytes.
Source code in src/prefect/serializers.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
dumps(obj)
abstractmethod
Encode the object into a blob of bytes.
Source code in src/prefect/serializers.py
96 97 98 |
|
loads(blob)
abstractmethod
Decode the blob of bytes into an object.
Source code in src/prefect/serializers.py
100 101 102 |
|
prefect_json_object_decoder(result)
JSONDecoder.object_hook
for decoding objects from JSON when previously encoded
with prefect_json_object_encoder
Source code in src/prefect/serializers.py
57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
prefect_json_object_encoder(obj)
JSONEncoder.default
for encoding objects into JSON with extended type support.
Raises a TypeError
to fallback on other encoders on failure.
Source code in src/prefect/serializers.py
42 43 44 45 46 47 48 49 50 51 52 53 54 |
|