cloudpickle-rust 0.1.0__cp314-cp314-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ from . import cloudpickle
2
+ from .cloudpickle import * # noqa
3
+
4
+ __doc__ = cloudpickle.__doc__
5
+
6
+ __version__ = "0.1.0"
7
+
8
+ __all__ = [ # noqa
9
+ "__version__",
10
+ "Pickler",
11
+ "CloudPickler",
12
+ "dumps",
13
+ "loads",
14
+ "dump",
15
+ "load",
16
+ "register_pickle_by_value",
17
+ "unregister_pickle_by_value",
18
+ ]
@@ -0,0 +1,188 @@
1
+ """Type stubs of the `cloudpickle_rust.cloudpickle` extension module."""
2
+
3
+ import pickle
4
+ import threading
5
+ import types
6
+ import weakref
7
+ from collections import ChainMap
8
+ from typing import (
9
+ IO,
10
+ Any,
11
+ Callable,
12
+ Dict,
13
+ Iterable,
14
+ Iterator,
15
+ List,
16
+ Optional,
17
+ Set,
18
+ Tuple,
19
+ Type,
20
+ TypeVar,
21
+ Union,
22
+ )
23
+
24
+ _T = TypeVar("_T")
25
+ _BufferCallback = Optional[Callable[[pickle.PickleBuffer], Any]]
26
+ _Reduced = Union[str, Tuple[Any, ...]]
27
+
28
+ DEFAULT_PROTOCOL: int
29
+ PYPY: bool
30
+ builtin_code_type: Optional[type]
31
+ CellType = types.CellType
32
+
33
+ STORE_GLOBAL: int
34
+ DELETE_GLOBAL: int
35
+ LOAD_GLOBAL: int
36
+ GLOBAL_OPS: Tuple[int, ...]
37
+ HAVE_ARGUMENT: int
38
+ EXTENDED_ARG: int
39
+
40
+ _PICKLE_BY_VALUE_MODULES: Set[str]
41
+ _DYNAMIC_CLASS_TRACKER_BY_CLASS: "weakref.WeakKeyDictionary[Any, str]"
42
+ _DYNAMIC_CLASS_TRACKER_BY_ID: "weakref.WeakValueDictionary[str, Any]"
43
+ _DYNAMIC_CLASS_TRACKER_LOCK: threading.Lock
44
+ _extract_code_globals_cache: Dict[
45
+ int, Tuple["weakref.ref[types.CodeType]", Dict[str, None]]
46
+ ]
47
+ _BUILTIN_TYPE_NAMES: Dict[type, str]
48
+ _DATACLASSE_FIELD_TYPE_SENTINELS: Dict[str, Any]
49
+ _empty_cell_value: Any
50
+
51
+ class _DispatchTable(ChainMap[Any, Callable[[Any], Any]]): ...
52
+
53
+ class Pickler(pickle.Pickler):
54
+ _dispatch_table: Dict[Any, Callable[[Any], _Reduced]]
55
+ dispatch_table: _DispatchTable # type: ignore[assignment]
56
+ dispatch: Any
57
+ globals_ref: Dict[int, Dict[str, Any]]
58
+ proto: int
59
+ def __init__(
60
+ self,
61
+ file: IO[bytes],
62
+ protocol: Optional[int] = None,
63
+ buffer_callback: _BufferCallback = None,
64
+ ) -> None: ...
65
+ def dump(self, obj: Any) -> None: ...
66
+ def reducer_override(self, obj: Any) -> Any: ...
67
+ def _function_reduce(self, obj: types.FunctionType) -> Any: ...
68
+ def _dynamic_function_reduce(self, func: types.FunctionType) -> Tuple[Any, ...]: ...
69
+ def _function_getnewargs(self, func: types.FunctionType) -> Tuple[Any, ...]: ...
70
+
71
+ CloudPickler = Pickler
72
+
73
+ def dump(
74
+ obj: Any,
75
+ file: IO[bytes],
76
+ protocol: Optional[int] = None,
77
+ buffer_callback: _BufferCallback = None,
78
+ ) -> None: ...
79
+ def dumps(
80
+ obj: Any,
81
+ protocol: Optional[int] = None,
82
+ buffer_callback: _BufferCallback = None,
83
+ ) -> bytes: ...
84
+
85
+ load = pickle.load
86
+ loads = pickle.loads
87
+
88
+ def register_pickle_by_value(module: types.ModuleType) -> None: ...
89
+ def unregister_pickle_by_value(module: types.ModuleType) -> None: ...
90
+ def list_registry_pickle_by_value() -> Set[str]: ...
91
+ def is_tornado_coroutine(func: Any) -> bool: ...
92
+ def subimport(name: str) -> types.ModuleType: ...
93
+ def dynamic_subimport(name: str, vars: Dict[str, Any]) -> types.ModuleType: ...
94
+ def instance(cls: Type[_T]) -> _T: ...
95
+
96
+ # Private helpers (part of the pickle format or used by the test-suite).
97
+ def _get_or_create_tracker_id(class_def: Any) -> str: ...
98
+ def _lookup_class_or_track(class_tracker_id: Optional[str], class_def: _T) -> _T: ...
99
+ def _is_registered_pickle_by_value(module: types.ModuleType) -> bool: ...
100
+ def _getattribute(obj: Any, name: str) -> Any: ...
101
+ def _whichmodule(obj: Any, name: Optional[str]) -> Optional[str]: ...
102
+ def _should_pickle_by_reference(obj: Any, name: Optional[str] = None) -> bool: ...
103
+ def _lookup_module_and_qualname(
104
+ obj: Any, name: Optional[str] = None
105
+ ) -> Optional[Tuple[types.ModuleType, str]]: ...
106
+ def _extract_code_globals(co: types.CodeType) -> Dict[str, None]: ...
107
+ def _find_imported_submodules(
108
+ code: types.CodeType, top_level_dependencies: Iterable[Any]
109
+ ) -> List[types.ModuleType]: ...
110
+ def _walk_global_ops(code: types.CodeType) -> Iterator[str]: ...
111
+ def _builtin_type(name: str) -> type: ...
112
+ def _extract_class_dict(cls: type) -> Dict[str, Any]: ...
113
+ def _get_cell_contents(cell: types.CellType) -> Any: ...
114
+ def _make_function(
115
+ code: types.CodeType,
116
+ globals: Dict[str, Any],
117
+ name: Optional[str],
118
+ argdefs: Optional[Tuple[Any, ...]],
119
+ closure: Optional[Tuple[types.CellType, ...]],
120
+ ) -> types.FunctionType: ...
121
+ def _make_empty_cell() -> types.CellType: ...
122
+ def _make_cell(value: Any = ...) -> types.CellType: ...
123
+ def _make_skeleton_class(
124
+ type_constructor: type,
125
+ name: str,
126
+ bases: Tuple[Any, ...],
127
+ type_kwargs: Dict[str, Any],
128
+ class_tracker_id: Optional[str],
129
+ extra: Any,
130
+ ) -> type: ...
131
+ def _make_skeleton_enum(
132
+ bases: Tuple[type, ...],
133
+ name: str,
134
+ qualname: str,
135
+ members: Dict[str, Any],
136
+ module: str,
137
+ class_tracker_id: Optional[str],
138
+ extra: Any,
139
+ ) -> type: ...
140
+ def _make_typevar(
141
+ name: str,
142
+ bound: Any,
143
+ constraints: Tuple[Any, ...],
144
+ covariant: bool,
145
+ contravariant: bool,
146
+ class_tracker_id: Optional[str],
147
+ ) -> TypeVar: ...
148
+ def _decompose_typevar(obj: TypeVar) -> Tuple[Any, ...]: ...
149
+ def _typevar_reduce(obj: TypeVar) -> Tuple[Any, ...]: ...
150
+ def _get_bases(typ: type) -> Tuple[Any, ...]: ...
151
+ def _make_dict_keys(obj: Iterable[Any], is_ordered: bool = False) -> Any: ...
152
+ def _make_dict_values(obj: Iterable[Any], is_ordered: bool = False) -> Any: ...
153
+ def _make_dict_items(obj: Any, is_ordered: bool = False) -> Any: ...
154
+ def _class_getnewargs(obj: type) -> Tuple[Any, ...]: ...
155
+ def _enum_getnewargs(obj: type) -> Tuple[Any, ...]: ...
156
+ def _file_reconstructor(retval: _T) -> _T: ...
157
+ def _function_getstate(
158
+ func: types.FunctionType,
159
+ ) -> Tuple[Dict[str, Any], Dict[str, Any]]: ...
160
+ def _class_getstate(obj: type) -> Tuple[Dict[str, Any], Dict[str, Any]]: ...
161
+ def _enum_getstate(obj: type) -> Tuple[Dict[str, Any], Dict[str, Any]]: ...
162
+ def _code_reduce(obj: types.CodeType) -> Tuple[Any, ...]: ...
163
+ def _cell_reduce(obj: types.CellType) -> Tuple[Any, ...]: ...
164
+ def _classmethod_reduce(obj: Any) -> Tuple[Any, ...]: ...
165
+ def _file_reduce(obj: Any) -> Tuple[Any, ...]: ...
166
+ def _getset_descriptor_reduce(obj: Any) -> Tuple[Any, ...]: ...
167
+ def _mappingproxy_reduce(obj: types.MappingProxyType) -> Tuple[Any, ...]: ... # type: ignore[type-arg]
168
+ def _memoryview_reduce(obj: memoryview) -> Tuple[Any, ...]: ...
169
+ def _module_reduce(obj: types.ModuleType) -> Tuple[Any, ...]: ...
170
+ def _method_reduce(obj: types.MethodType) -> Tuple[Any, ...]: ...
171
+ def _logger_reduce(obj: Any) -> Tuple[Any, ...]: ...
172
+ def _root_logger_reduce(obj: Any) -> Tuple[Any, ...]: ...
173
+ def _property_reduce(obj: property) -> Tuple[Any, ...]: ...
174
+ def _weakset_reduce(obj: "weakref.WeakSet[Any]") -> Tuple[Any, ...]: ...
175
+ def _dynamic_class_reduce(obj: type) -> Tuple[Any, ...]: ...
176
+ def _class_reduce(obj: type) -> Any: ...
177
+ def _dict_keys_reduce(obj: Any) -> Tuple[Any, ...]: ...
178
+ def _dict_values_reduce(obj: Any) -> Tuple[Any, ...]: ...
179
+ def _dict_items_reduce(obj: Any) -> Tuple[Any, ...]: ...
180
+ def _odict_keys_reduce(obj: Any) -> Tuple[Any, ...]: ...
181
+ def _odict_values_reduce(obj: Any) -> Tuple[Any, ...]: ...
182
+ def _odict_items_reduce(obj: Any) -> Tuple[Any, ...]: ...
183
+ def _dataclass_field_base_reduce(obj: Any) -> Tuple[Any, ...]: ...
184
+ def _function_setstate(
185
+ obj: types.FunctionType, state: Tuple[Dict[str, Any], Dict[str, Any]]
186
+ ) -> None: ...
187
+ def _class_setstate(obj: _T, state: Tuple[Dict[str, Any], Dict[str, Any]]) -> _T: ...
188
+ def _get_dataclass_field_type_sentinel(name: str) -> Any: ...
@@ -0,0 +1,14 @@
1
+ """Compatibility module.
2
+
3
+ It can be necessary to load files generated by previous versions of cloudpickle
4
+ that rely on symbols being defined under the `cloudpickle.cloudpickle_fast`
5
+ namespace.
6
+
7
+ See: tests/test_backward_compat.py
8
+ """
9
+
10
+ from . import cloudpickle
11
+
12
+
13
+ def __getattr__(name):
14
+ return getattr(cloudpickle, name)
File without changes
@@ -0,0 +1,360 @@
1
+ Metadata-Version: 2.4
2
+ Name: cloudpickle-rust
3
+ Version: 0.1.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Operating System :: POSIX
7
+ Classifier: Operating System :: Microsoft :: Windows
8
+ Classifier: Operating System :: MacOS :: MacOS X
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Classifier: Programming Language :: Rust
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Scientific/Engineering
22
+ Classifier: Topic :: System :: Distributed Computing
23
+ License-File: LICENSE
24
+ License-File: NOTICE
25
+ License-File: licenses/LICENSE-cloudpickle.txt
26
+ Summary: Extended pickling support for Python objects: a Rust implementation of cloudpickle
27
+ Keywords: pickle,serialization,cloudpickle,distributed computing,rust
28
+ Author: The cloudpickle-rust developer team
29
+ License-Expression: Apache-2.0
30
+ Requires-Python: >=3.8, <3.15
31
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
32
+ Project-URL: Changelog, https://github.com/HyukjinKwon/cloudpickle-rust/blob/main/CHANGES.md
33
+ Project-URL: Homepage, https://github.com/HyukjinKwon/cloudpickle-rust
34
+ Project-URL: Issues, https://github.com/HyukjinKwon/cloudpickle-rust/issues
35
+ Project-URL: Repository, https://github.com/HyukjinKwon/cloudpickle-rust
36
+ Project-URL: Upstream, https://github.com/cloudpipe/cloudpickle
37
+
38
+ # cloudpickle-rust
39
+
40
+ [![Automated Tests](https://github.com/HyukjinKwon/cloudpickle-rust/actions/workflows/testing.yml/badge.svg?branch=main&event=push)](https://github.com/HyukjinKwon/cloudpickle-rust/actions/workflows/testing.yml)
41
+ [![PyPI](https://img.shields.io/pypi/v/cloudpickle-rust.svg)](https://pypi.org/project/cloudpickle-rust/)
42
+
43
+ `cloudpickle-rust` is a Rust implementation of
44
+ [cloudpickle](https://github.com/cloudpipe/cloudpickle), the library that makes
45
+ it possible to serialize Python constructs not supported by the default
46
+ `pickle` module from the Python standard library.
47
+
48
+ It is a complete rewrite of `cloudpickle/cloudpickle.py` in Rust (with
49
+ [PyO3](https://pyo3.rs)), exposing exactly the same API, producing the same
50
+ payloads, and passing the upstream test-suite with exactly the same results
51
+ (see [Compatibility](#compatibility-with-cloudpickle)).
52
+
53
+ `cloudpickle` is especially useful for **cluster computing** where Python
54
+ code is shipped over the network to execute on remote hosts, possibly close
55
+ to the data.
56
+
57
+ Among other things, `cloudpickle` supports pickling for **lambda functions**
58
+ along with **functions and classes defined interactively** in the
59
+ `__main__` module (for instance in a script, a shell or a Jupyter notebook).
60
+
61
+ Cloudpickle can only be used to send objects between the **exact same version
62
+ of Python**.
63
+
64
+ Using `cloudpickle` for **long-term object storage is not supported and
65
+ strongly discouraged.**
66
+
67
+ **Security notice**: one should **only load pickle data from trusted sources** as
68
+ otherwise `pickle.load` can lead to arbitrary code execution resulting in a critical
69
+ security vulnerability.
70
+
71
+
72
+ Installation
73
+ ------------
74
+
75
+ The latest release of `cloudpickle-rust` is available from
76
+ [pypi](https://pypi.org/project/cloudpickle-rust/):
77
+
78
+ pip install cloudpickle-rust
79
+
80
+ Binary wheels are provided for:
81
+
82
+ | Platform | CPython 3.8 – 3.14 | Free-threaded CPython 3.14t | PyPy 3.11 (7.3, 8.0) |
83
+ |---|---|---|---|
84
+ | Linux, manylinux (x86_64, aarch64) | ✓ | ✓ | ✓ (PyPy 8.0: manylinux_2_28) |
85
+ | Linux, manylinux (x86) | 3.9 – 3.14 | ✓ | |
86
+ | Linux, manylinux (armv7, s390x, ppc64le) | ✓ | ✓ | |
87
+ | Linux, musllinux (x86_64, x86, aarch64, armv7) | ✓ | ✓ | |
88
+ | macOS (x86_64, arm64) | ✓ | ✓ | ✓ |
89
+ | Windows (x64) | ✓ | ✓ | |
90
+ | Windows (x86) | ✓ | | |
91
+ | Windows (arm64) | 3.11 – 3.14 | ✓ | |
92
+
93
+ On other platforms (and on the free-threaded CPython 3.13t, for which maturin
94
+ does not build wheels since free-threading is experimental in 3.13),
95
+ installing from the source distribution requires a Rust toolchain.
96
+
97
+ The package is importable as `cloudpickle_rust`, so that it can be installed
98
+ alongside `cloudpickle`. To use it as a drop-in replacement:
99
+
100
+ ```python
101
+ import cloudpickle_rust as cloudpickle
102
+ ```
103
+
104
+ Like `cloudpickle`, the payloads reference the functions used to reconstruct
105
+ dynamic functions and classes (as `cloudpickle_rust.cloudpickle.<name>`), so
106
+ `cloudpickle-rust` must also be installed in the Python environment that loads
107
+ them (with plain `pickle.loads`).
108
+
109
+
110
+ Examples
111
+ --------
112
+
113
+ Pickling a lambda expression:
114
+
115
+ ```python
116
+ >>> import cloudpickle_rust as cloudpickle
117
+ >>> squared = lambda x: x ** 2
118
+ >>> pickled_lambda = cloudpickle.dumps(squared)
119
+
120
+ >>> import pickle
121
+ >>> new_squared = pickle.loads(pickled_lambda)
122
+ >>> new_squared(2)
123
+ 4
124
+ ```
125
+
126
+ Pickling a function interactively defined in a Python shell session
127
+ (in the `__main__` module):
128
+
129
+ ```python
130
+ >>> CONSTANT = 42
131
+ >>> def my_function(data: int) -> int:
132
+ ... return data + CONSTANT
133
+ ...
134
+ >>> pickled_function = cloudpickle.dumps(my_function)
135
+ >>> depickled_function = pickle.loads(pickled_function)
136
+ >>> depickled_function
137
+ <function __main__.my_function(data:int) -> int>
138
+ >>> depickled_function(43)
139
+ 85
140
+ ```
141
+
142
+
143
+ Overriding pickle's serialization mechanism for importable constructs:
144
+ ----------------------------------------------------------------------
145
+
146
+ An important difference between `cloudpickle` and `pickle` is that
147
+ `cloudpickle` can serialize a function or class **by value**, whereas `pickle`
148
+ can only serialize it **by reference**. Serialization by reference treats
149
+ functions and classes as attributes of modules, and pickles them through
150
+ instructions that trigger the import of their module at load time.
151
+ Serialization by reference is thus limited in that it assumes that the module
152
+ containing the function or class is available/importable in the unpickling
153
+ environment. This assumption breaks when pickling constructs defined in an
154
+ interactive session, a case that is automatically detected by `cloudpickle`,
155
+ that pickles such constructs **by value**.
156
+
157
+ Another case where the importability assumption is expected to break is when
158
+ developing a module in a distributed execution environment: the worker
159
+ processes may not have access to the said module, for example if they live on a
160
+ different machine than the process in which the module is being developed. By
161
+ itself, `cloudpickle` cannot detect such "locally importable" modules and
162
+ switch to serialization by value; instead, it relies on its default mode, which
163
+ is serialization by reference. However, since `cloudpickle 2.0.0`, one can
164
+ explicitly specify modules for which serialization by value should be used,
165
+ using the
166
+ `register_pickle_by_value(module)`/`/unregister_pickle_by_value(module)` API:
167
+
168
+ ```python
169
+ >>> import cloudpickle_rust as cloudpickle
170
+ >>> import my_module
171
+ >>> cloudpickle.register_pickle_by_value(my_module)
172
+ >>> cloudpickle.dumps(my_module.my_function) # my_function is pickled by value
173
+ >>> cloudpickle.unregister_pickle_by_value(my_module)
174
+ >>> cloudpickle.dumps(my_module.my_function) # my_function is pickled by reference
175
+ ```
176
+
177
+ Using this API, there is no need to re-install the new version of the module on
178
+ all the worker nodes nor to restart the workers: restarting the client Python
179
+ process with the new source code is enough.
180
+
181
+ Note that this feature is still **experimental**, and may fail in the following
182
+ situations:
183
+
184
+ - If the body of a function/class pickled by value contains an `import` statement:
185
+ ```python
186
+ >>> def f():
187
+ >>> ... from another_module import g
188
+ >>> ... # calling f in the unpickling environment may fail if another_module
189
+ >>> ... # is unavailable
190
+ >>> ... return g() + 1
191
+ ```
192
+
193
+ - If a function pickled by reference uses a function pickled by value during its execution.
194
+
195
+
196
+ Compatibility with cloudpickle
197
+ ------------------------------
198
+
199
+ `cloudpickle-rust` 0.1.0 implements cloudpickle 3.2.0.dev0 (upstream commit
200
+ [`4af5936`](https://github.com/cloudpipe/cloudpickle/commit/4af5936c328de0b33fa9c636e210d9a9e1e97dd3)).
201
+
202
+ - **Same structure and API.** The package mirrors upstream: `cloudpickle_rust/__init__.py`,
203
+ `cloudpickle_rust/cloudpickle_fast.py` and `cloudpickle_rust.cloudpickle`,
204
+ the Rust extension module equivalent to `cloudpickle/cloudpickle.py`. Every
205
+ function, class and module-level attribute of `cloudpickle.cloudpickle`
206
+ exists in `cloudpickle_rust.cloudpickle` (`Pickler`, `dumps`,
207
+ `register_pickle_by_value`, but also the private helpers such as
208
+ `_should_pickle_by_reference` or `_make_skeleton_class`).
209
+ - **Same payloads.** For a given object, the pickle opcodes (including the
210
+ memoization of objects, which cloudpickle carefully controls to produce
211
+ deterministic payloads) are identical to the ones produced by upstream
212
+ cloudpickle, except for the module of the reconstructors.
213
+ - **Same test results.** The test-suite of this repository is the upstream
214
+ test-suite, where only `import cloudpickle` was replaced by
215
+ `import cloudpickle_rust as cloudpickle`. On CPython 3.8 to 3.14 and
216
+ free-threaded 3.13t and 3.14t, every test has the same outcome (pass, skip
217
+ or expected failure) as with upstream cloudpickle.
218
+ - **PyPy 3.11.** Upstream cloudpickle cannot be imported on PyPy 3.11 (PyPy
219
+ 7.3.20+ and 8.0), whose `pickle.Pickler` became a native class without the
220
+ `dispatch` attribute that its PyPy implementation relies on (and its reducer
221
+ of code objects does not match the signature of `types.CodeType` of PyPy
222
+ 7.3). `cloudpickle-rust` uses the pure-Python pickler on PyPy, like upstream
223
+ did with earlier PyPy versions, detects the signature of `types.CodeType`,
224
+ and passes the whole test-suite on PyPy 7.3.23 and 8.0.1. On PyPy 8.0.1,
225
+ with upstream's import fixed, every upstream test has the same outcome.
226
+
227
+ The few implementation-level differences, which do not change what is
228
+ pickled:
229
+
230
+ - The `Pickler` methods are implemented in Rust (as method descriptors, like
231
+ the methods of builtin types) instead of Python functions, and
232
+ `Pickler.dispatch_table` is a subclass of `collections.ChainMap` with a
233
+ native `__getitem__`.
234
+ - Internal calls between the functions of the module are native: replacing a
235
+ private function of `cloudpickle_rust.cloudpickle` (for instance with
236
+ `monkeypatch`) does not change the behavior of the pickler. The module-level
237
+ `Pickler` and `DEFAULT_PROTOCOL` attributes, as well as the standard library
238
+ functions used by cloudpickle (`uuid.uuid4`, `io.BytesIO`, ...), are looked
239
+ up at call time like in upstream.
240
+ - `_walk_global_ops` decodes the bytecode directly (the encoding of the
241
+ global-referencing instructions is measured when the module is imported),
242
+ instead of relying on `dis.get_instructions`, and returns an iterator instead
243
+ of a generator.
244
+ - `_extract_code_globals_cache` maps `id(code)` to `(weakref(code), names)`
245
+ instead of being a `weakref.WeakKeyDictionary`.
246
+ - The functions accept the same arguments (including by keyword) as
247
+ upstream, and `inspect.signature` reports the same signatures, except for
248
+ `_make_cell(value=_empty_cell_value)`: the signature of a builtin function
249
+ cannot have a default value which is not a literal.
250
+
251
+
252
+ Performance
253
+ -----------
254
+
255
+ `cloudpickle-rust` produces the same payloads as cloudpickle while running
256
+ its logic natively: `reducer_override`, the reducers and state getters of
257
+ functions and classes, the bytecode analysis of functions, and the lookups in
258
+ the pickler's `dispatch_table` (which cloudpickle performs in Python for every
259
+ object that is not handled by `reducer_override`).
260
+
261
+ Time of `dumps` with [`benchmarks/bench.py`](benchmarks/bench.py), on an
262
+ Apple M3 Max with CPython 3.13.14 (release build of cloudpickle-rust 0.1.0,
263
+ cloudpickle 3.2.0.dev0, best of 15 interleaved runs):
264
+
265
+ | Payload | cloudpickle | cloudpickle-rust | Speedup |
266
+ |---|---:|---:|---:|
267
+ | A lambda | 10.7 µs | 7.2 µs | 1.48× |
268
+ | A closure using globals | 16.1 µs | 10.6 µs | 1.52× |
269
+ | A dynamic class | 27.7 µs | 16.8 µs | 1.65× |
270
+ | A dynamic dataclass | 74.4 µs | 46.7 µs | 1.59× |
271
+ | A dynamic enum | 19.6 µs | 11.7 µs | 1.68× |
272
+ | A generic class (`typing.Generic`) | 32.7 µs | 19.9 µs | 1.64× |
273
+ | 1,000 distinct lambdas | 5.16 ms | 3.51 ms | 1.47× |
274
+ | 100,000 instances of a dynamic class | 94.1 ms | 59.5 ms | 1.58× |
275
+ | 100,000 instances of a dynamic dataclass | 103.1 ms | 65.9 ms | 1.56× |
276
+ | 100,000 builtin objects (dict of lists) | 25.8 ms | 25.3 ms | 1.02× |
277
+
278
+ For the collections of instances, plain `pickle.dumps` (which pickles the
279
+ classes by reference instead of by value) takes 41.1 ms and 46.3 ms: the time
280
+ cloudpickle spends on top of the standard library pickler is about 3× smaller
281
+ with cloudpickle-rust. Builtin types (`dict`, `list`, `str`, `int`...) are
282
+ handled by the standard library pickler without involving cloudpickle at all,
283
+ hence the same speed (plain `pickle.dumps` takes 25.2 ms).
284
+
285
+
286
+ Running the tests
287
+ -----------------
288
+
289
+ - With `tox`, to test run the tests for all the supported versions of
290
+ Python and PyPy:
291
+
292
+ pip install tox
293
+ tox
294
+
295
+ or alternatively for a specific environment:
296
+
297
+ tox -e py312
298
+
299
+
300
+ - With `pytest` to only run the tests for your current version of
301
+ Python:
302
+
303
+ pip install -e .
304
+ pip install -r dev-requirements.txt
305
+ PYTHONPATH='.:tests' pytest
306
+
307
+ A Rust toolchain ([rustup](https://rustup.rs)) is required to build the
308
+ extension module. During development, `maturin develop` rebuilds it in place.
309
+
310
+
311
+ Releasing to PyPI
312
+ -----------------
313
+
314
+ The [`publish_to_pypi.yml`](.github/workflows/publish_to_pypi.yml) GitHub
315
+ Actions workflow builds the wheels of all the supported platforms and Python
316
+ versions (with [maturin-action](https://github.com/PyO3/maturin-action)) and the
317
+ source distribution, and tests the wheels, on every push. When a tag is pushed,
318
+ it publishes them to PyPI with the PyPI API token stored in the `PYPI_TOKEN`
319
+ secret of the repository:
320
+
321
+ 1. Bump the version in `Cargo.toml` and `python/cloudpickle_rust/__init__.py`,
322
+ and add an entry to `CHANGES.md`.
323
+ 2. Push a tag, for instance `git tag v0.1.0 && git push origin v0.1.0`.
324
+
325
+ To build the distributions locally instead:
326
+
327
+ pip install maturin
328
+ maturin build --release # wheel for the current interpreter
329
+ maturin sdist # source distribution
330
+
331
+
332
+ History
333
+ -------
334
+
335
+ `cloudpickle` was initially developed by [picloud.com](http://web.archive.org/web/20140721022102/http://blog.picloud.com/2013/11/17/picloud-has-joined-dropbox/) and shipped as part of
336
+ the client SDK.
337
+
338
+ A copy of `cloudpickle.py` was included as part of PySpark, the Python
339
+ interface to [Apache Spark](https://spark.apache.org/). Davies Liu, Josh
340
+ Rosen, Thom Neale and other Apache Spark developers improved it significantly,
341
+ most notably to add support for PyPy and Python 3.
342
+
343
+ The aim of the `cloudpickle` project is to make that work available to a wider
344
+ audience outside of the Spark ecosystem and to make it easier to improve it
345
+ further notably with the help of a dedicated non-regression test suite.
346
+
347
+ `cloudpickle-rust` is a Rust implementation of `cloudpickle`, which retains
348
+ its test-suite.
349
+
350
+
351
+ License
352
+ -------
353
+
354
+ `cloudpickle-rust` is licensed under the [Apache License, Version 2.0](LICENSE).
355
+
356
+ It is derived from `cloudpickle`, which is distributed under the
357
+ [BSD 3-Clause License](licenses/LICENSE-cloudpickle.txt): the code derived from
358
+ it and the files copied from it (listed at the end of [LICENSE](LICENSE)) keep
359
+ its copyright and license notice (see also [NOTICE](NOTICE)).
360
+
@@ -0,0 +1,12 @@
1
+ cloudpickle_rust/__init__.py,sha256=V6fOIlopJouFvhj43RXpRUS20ZzWgCUiy4SlBWfIKLs,326
2
+ cloudpickle_rust/cloudpickle.cp314-win32.pyd,sha256=nagz-iWhUU5TDWE_x5dkoT-1mVvYMhOa_p8WnzjSI90,770048
3
+ cloudpickle_rust/cloudpickle.pyi,sha256=_kDASzgBPm4wQeVTBI4obrbsMUiuWnECWfUqs2f8B6M,7199
4
+ cloudpickle_rust/cloudpickle_fast.py,sha256=mZYCbd7A9lgj0kMB0sXiytzKFDTqvgf7sebuz2Mcbx4,337
5
+ cloudpickle_rust/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ cloudpickle_rust-0.1.0.dist-info/METADATA,sha256=R4_vm4gkxeIY-XuwX7Pfs-JVhQcIUwhXl55AIuUTzPo,16176
7
+ cloudpickle_rust-0.1.0.dist-info/WHEEL,sha256=wkszVsmv0KLgRIp3AAntqJqm1bOsjFaxpAqkfcC0Vw0,93
8
+ cloudpickle_rust-0.1.0.dist-info/licenses/LICENSE,sha256=BzVsKIb-d_YQuaxeMUCUJ1NAb75JI7gAUnan99eIVAc,12153
9
+ cloudpickle_rust-0.1.0.dist-info/licenses/NOTICE,sha256=la5JaZtXqhhrfAmM0VOEUSFwKR8R4QrwbicqMGAFE5o,580
10
+ cloudpickle_rust-0.1.0.dist-info/licenses/licenses/LICENSE-cloudpickle.txt,sha256=_QX8O_YAMXKE27jQrhppGDL5BB9g8AxifRUbmbg6Mow,1786
11
+ cloudpickle_rust-0.1.0.dist-info/sboms/cloudpickle-rust.cyclonedx.json,sha256=AGHZfV-nicDS-L1H4ixh9RuQhSEgKlJHCnx2JPBShPE,16414
12
+ cloudpickle_rust-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.16.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp314-cp314-win32