purify
Pythonic object-mutator transforms as pure functions
What it is and what it does
Purify is a decorator that solves a common Python pattern problem: writing functions that transform objects while maintaining functional purity. Normally, Python encourages mutating an object in place and returning it for efficiency, but this breaks referential transparency when the original object is needed elsewhere. Deepcopy is the pure alternative but is orders of magnitude slower. Purify uses shallow copy by default, making the decorated function pure without the performance cost of deep copying.
The decorator works by automatically shallow-copying the target argument before the function executes, so mutations inside the function only affect the copy. You specify which argument to copy either by position (last argument by default) or by name. For complex nested structures, the documentation recommends decomposing your transforms into multiple shallow-copy layers rather than using deep copy, which often yields both purer and more reusable functions.
Use it for:
- Transform tree or graph structures where you need the original unchanged but want to write natural mutation-style code
- Build pipelines of object modifications where intermediate results must not affect earlier stages
- Write testable functions that don't have hidden side effects on their inputs
- Refactor existing mutation-based codebases toward functional style without rewriting to use expensive deepcopy
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A decorator that makes object-mutating functions pure by automatically shallow-copying the target argument, allowing you to write mutation-style code that doesn't modify the original object.
Yes, if you regularly write object-transform functions and want to enforce purity without deep-copy overhead. The package is actively maintained, has no dependencies, and works on current Python versions. It's a narrow but well-defined tool—install it when you recognize the pattern it solves in your own code, not as a general utility.
Install
purify on PyPI
pip
pip install purifyuv
uv add purifypoetry
poetry add purifyInstalling purify
Before you install
Low friction: pure Python, no runtime dependencies, and supports modern Python versions 3.10 through 3.14. Repository is active with recent commits.
License in practice
Apache License 2.0 is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install purify
from purify import purify
@purify
def rename_tree(name: str, tree):
tree.name = name
return tree
original = Tree('Old')
modified = rename_tree('New', original)
# original.name is still 'Old', modified.name is 'New'
Verify before relying
- Whether the shallow-copy approach is sufficient for nested mutable structures in typical use cases beyond the documented examples
- Performance characteristics and memory overhead compared to standard mutation in real-world codebases
Package facts
| License | Apache License Version 2.0, January 2004 https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (<3.15,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 141 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 120,297/month — #12,034 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: purify-0.3.0-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
decopatchDecopatch simplifies writing decorators in…
permissive · top 5,000 on PyPI
lensesLenses provides a functional approach to…
copyleft · top 15,000 on PyPI
legacy-api-wrapProvides a decorator to wrap legacy function…
copyleft · top 5,000 on PyPI
wraptwrapt provides a Python module for building…
permissive · top 100 on PyPI
mutmutMutmut is a mutation testing system for Python…
permissive · top 5,000 on PyPI
flake8-functionsA flake8 extension that enforces function-level…
permissive · top 15,000 on PyPI
makefunDynamically creates Python functions at runtime…
permissive · top 5,000 on PyPI
ConfigUpdaterConfigUpdater reads and modifies INI…
permissive · top 5,000 on PyPI
singleton-decoratorProvides a decorator that enforces singleton…
copyleft · top 15,000 on PyPI
decoratorProvides utilities for writing function…
permissive · top 1,000 on PyPI