cloudpickle

Extended Python pickling that can serialize lambdas, closures, and interactively defined objects

Library
PyPI
v3.1.2
1,944 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
64 /100 Good
Development Activity 52
Maintenance 28
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 80
Code Quality 78
Innovation 75
Learning Curve 82

cloudpickle extends Python’s standard pickle module to serialize objects that pickle cannot handle on its own — lambda expressions, functions and classes defined interactively in __main__ (a script, shell, or Jupyter notebook), and closures capturing local state. It was built for cluster computing, where Python code and data need to travel over the network to remote workers, and today underpins distributed frameworks like Dask, PySpark, and Ray for exactly that reason.

What You Get

  • cloudpickle.dumps/loads — a pickle-compatible API for serializing objects standard pickle cannot, including lambdas and closures
  • Support for pickling functions and classes defined interactively in __main__ (scripts, REPL sessions, Jupyter notebooks)
  • A register_pickle_by_value/unregister_pickle_by_value API to force serialization-by-value for specific modules under active development
  • Correct handling of nested functions and closures that capture surrounding local variables
  • Compatibility layer so output can be loaded with the standard library’s pickle.loads

Common Use Cases

  • Distributed computing frameworks (Dask, PySpark, Ray) shipping user-defined functions and closures to remote worker processes
  • Serializing interactively defined functions/classes from a Jupyter notebook or REPL session so they can run on a separate worker
  • Checkpointing or transmitting callables in task-queue systems where the callable was defined in __main__ rather than an importable module
  • ML training pipelines that pass custom loss functions, lambdas, or locally-defined model classes to worker processes

Under The Hood

Architecture — The library is a thin, focused patch over the CPython pickle protocol: cloudpickle.py implements custom Pickler subclass reducers that intercept function, class, and closure-cell objects before the standard reducer would fail on them, detecting whether a given object was defined in an importable module (serialize by reference, like stock pickle) versus interactively or dynamically (serialize by value — capture bytecode, globals, and closure cells). cloudpickle_fast.py and __init__.py are thin wiring/compat shims. Tech Stack — Pure Python (99.9% of the codebase) with zero runtime dependencies, targeting compatibility across CPython and PyPy; the test suite is run via tox across supported Python versions. Code Quality — A large tests/ directory (cloudpickle_test.py, test_backward_compat.py, cloudpickle_file_test.py, cloudpickle_ipykernel_test.py) covers core serialization, cross-version backward compatibility, and notebook-specific edge cases; the README explicitly documents known limitations (e.g. functions pickled by value containing local import statements can fail), which is a good maintainability signal. API Design — The API is deliberately a drop-in replacement for pickle.dumps/pickle.loads with no new concepts to learn for basic use; advanced behavior (register_pickle_by_value) is opt-in and only needed for the specific case of live-reloading modules on distributed workers.

Used by 6 apps in this directory

Python
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 89%
Updated 1 weeks ago
Go
84%
AGPL 3.0

Beta9

AI Development · Automation · Data Engineering

1,794

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
85
Repo Health
78
Technical
66
Dependency
Built with
Go 84%
Python 15%
Updated 1 weeks ago
Python
65%
MIT

Flowfile

Data Engineering

363

Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.

View details
83
Repo Health
81
Technical
66
Dependency
Built with
Python 65%
Vue 17%
TypeScript 17%
Updated 1 weeks ago
Python
58%
Apache 2.0

MLflow

AI Development · Monitoring

28,154

The open source AI engineering platform for debugging, evaluating, monitoring, and optimizing production LLMs and agents at scale.

View details
97
Repo Health
86
Technical
66
Dependency
Built with
Python 58%
TypeScript 33%
Updated 1 weeks ago
Rust
85%
Apache 2.0

OpenShell

AI Agents · Developer Tools

8,811

The safe, private runtime that lets autonomous AI agents operate in sandboxed environments governed by declarative YAML policies — blocking data exfiltration, credential leaks, and unauthorized network activity before they happen.

View details
85
Repo Health
81
Technical
68
Dependency
Built with
Rust 85%
Updated 1 weeks ago
Python
70%
AGPL 3.0

Tracecat

AI Agents · Automation · Security

3,816

Open-source agentic security automation platform that runs AI agents and durable workflows at scale with sandboxed execution.

View details
89
Repo Health
88
Technical
66
Dependency
Built with
Python 70%
TypeScript 28%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers