Fast drop-in replacement for copy.deepcopy().
- ⚡ 4-28x faster than
copy.deepcopy()on builtin types - 🧠 uses ~44% less memory than
copy.deepcopy()on average - 🧪 passes all tests in
CPython/Lib/test/test_copy.py - 🎯 behaves exactly the same as
copy.deepcopy()for alldatamodelzoo.CASES - 🛡️ tested for refcount, recursion, threading and memo edge cases
- 🐍 pre-built wheels for Python 3.10-3.14 on Linux/macOS/Windows (x64/ARM64)
- 🔓 passes all tesee-frts on threaded Pyth buildons
Warning
This is an alpha version. Run your test suite with COPIUM_PATCH_DEEPCOPY=1 to verify compatibility in your environment.
pip install copiumSimply export COPIUM_PATCH_DEEPCOPY=1 before running your application. You
don't have to change a single line of code:
cat example.py
from copy import deepcopy
assert deepcopy(x := []) is not xCOPIUM_PATCH_DEEPCOPY=1 python example.py
To enable the patch manually:
import copium.patch
copium.patch.enable()To use manually:
from copium import deepcopy
assert deepcopy(x := []) is not xThe copium module includes all public declarations of stdlib copy module, so it's generally safe to:
- from copy import copy, deepcopy, Error
+ from copium import copy, deepcopy, Error()~5.66xtuple[int, ...]~12.46x (20 items)tuple[int, ...]~28.28x (5000 items)tuple[tuple[str, tuple[tuple[str, tuple[tuple[str, tuple[tuple[str, tuple[int, ...]]]]]]]]]]~14.54x
[]~4.97xlist[int]~9.58x (20 items)list[int]~16.23x (5000 items)list[str | list[str | list[str | list[str | list[int]]]]]~9.19x
{}~4.59xdict[str, int]~5.95x (20 items)dict[str, int]~3.94x (5000 items)dict[str, dict[str, ...]]~6.19x
set()~15.87xset[int]~6.55x (20 items)set[int]~3.69x (5000 items)set[frozenset[frozenset[int]]]~13.72x
int/str/bytes~4.86xdataclasses~2.74x
Expect much higher speedups on Python 3.13 and lower.