--- id: purify version: "0.3.0" 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) license_treatment: permissive maintenance: active --- # purify — Pythonic object-mutator transforms as pure functions License: permissive · Maintenance: active · Downloads: 120.3K/mo ## 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 above — 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 pip install purify uv add purify poetry add purify ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 120.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pure function decorator python, immutable object transforms, shallow copy decorator, functional programming object mutation, pure function object modification, pythonic immutability pattern, object transform without mutation, functional-programming, decorator, immutability [View on SkillFed](https://skillfed.io/packages/purify) · [View on PyPI](https://pypi.org/project/purify/)