--- id: lenses version: "1.2.0" license: GPLv3+ license_treatment: copyleft maintenance: dormant --- # lenses — A lens library for python License: copyleft · Maintenance: dormant · Downloads: 163.4K/mo ## What it is and what it does Lenses is a Python library that implements functional lens patterns to safely navigate and transform nested data structures without mutating the original. It lets you compose operations like filtering, mapping, and method calls across arbitrary levels of nesting—lists, dicts, custom objects—in a single declarative expression. Instead of writing nested loops and conditionals to reach deep values and rebuild structures, you chain lens operations that describe the path and transformation, then apply them to your data. The library is inspired by Haskell's lens ecosystem but adapted for Python's imperative style. It has no external runtime dependencies and works across modern Python versions (3.7–3.11). The main trade-off is that the lens syntax is unfamiliar to most Python developers and requires learning a new mental model; the payoff is cleaner, more composable code for complex data transformations that would otherwise require deeply nested loops. Use it for: - Transform deeply nested JSON or dictionary structures (e.g., API responses) without writing nested loops. - Apply the same operation to all matching elements across multiple levels of nesting in a single expression. - Build reusable, composable data transformations that can be combined and tested independently. - Work with immutable data patterns in functional Python code or when mutation safety is required. - Extract and modify specific fields in complex object hierarchies without intermediate variable assignments. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Lenses provides a functional approach to reading and modifying nested data structures without mutating the original data, using composable lens operations inspired by Haskell. Yes, if you work regularly with nested data structures and want cleaner, more composable transformation code. The copyleft GPLv3+ license is a hard blocker for proprietary projects. The dormant maintenance status is a minor concern—the library is stable and has no known vulnerabilities, but you should verify that its behavior matches your needs before adopting it for new projects. ## Install pip install lenses uv add lenses poetry add lenses ## Installing lenses Before you install: Installation is straightforward with no runtime dependencies. The package is in production/stable status but dormant—last release was over a year ago, though the repository remains active and supported on Python 3.7 through 3.11. License in practice: Licensed under GPLv3+, a copyleft license. Any derivative work or distribution must also be open-source under compatible terms; this is a significant constraint for proprietary or closed-source projects. Quickstart: pip install lenses from lenses import lens data = [{'name': 'Jane', 'scores': ['a', 'b']}, {'name': 'Zoe', 'scores': ['f', 'f']}] format_scores = lens.Each()['scores'].Each().Instance(str).call_upper() result = format_scores(data) Requires Python 3.7 or later (supports up to 3.11). Verify before relying: - Whether the dormant maintenance status affects real-world usability or indicates unaddressed issues. - Performance characteristics on very large or deeply nested data structures compared to imperative approaches. ## Package facts - License: GPLv3+ (copyleft) - Python support: supports_current - Install friction: low - Maintenance: dormant - Downloads: 163.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags immutable data structure manipulation, functional lens library, nested data access without mutation, composable optics for python, functional programming data transformation, functional-programming, immutable-data, data-transformation [View on SkillFed](https://skillfed.io/packages/lenses) · [View on PyPI](https://pypi.org/project/lenses/)