skillfed

magicattr

A getattr and setattr that works on nested objects, lists, dicts, and any combination thereof without resorting to eval

magicattr v0.1.6 5.9M downloads/30d#2,008 on PyPI18
Permissive license MIT Abandoned released

What it is and what it does

Magicattr extends Python's getattr and setattr to work on deeply nested structures—objects with attributes, lists, and dictionaries—by parsing a path string into an abstract syntax tree and evaluating it safely without using eval. Instead of raising a generic AttributeError, it preserves the actual failure cause, making debugging easier.

The package is useful when you need to read or write values deep within a complex object hierarchy using a single string path, such as `'friends[0].settings["style"]["width"]'`. It supports get, set, and delete operations on combinations of object attributes, list indices (including negative indexing), and dictionary keys. It explicitly blocks unsafe operations like function calls, expressions, and slicing.

Use it for:

  • Retrieve or modify configuration nested in dictionaries and objects without manual traversal.
  • Update deeply nested properties in data models or ORM objects via a single path string.
  • Delete attributes or list items at arbitrary depths in a complex object tree.
  • Parse and apply user-provided paths to objects without the security risk of eval.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides nested attribute access and modification on objects, lists, and dictionaries using a dot-and-bracket notation string, without eval.

Yes, if you need safe nested attribute access and can accept an abandoned package. The code is simple and has no dependencies, so the risk of breakage is low for stable use cases. However, do not rely on it for new projects requiring active maintenance or support for future Python versions—consider it a utility for existing codebases where the feature set is complete and stable.

Install

magicattr on PyPI

pip

pip install magicattr

uv

uv add magicattr

poetry

poetry add magicattr

Installing magicattr

Before you install

Low friction: pure Python wheel with no runtime dependencies. However, the package is abandoned—last commit was 2022-02-18 and no releases since 2022-01-25, so it will not receive bug fixes or maintenance.

License in practice

MIT license is permissive; you may use, modify, and distribute this package freely with minimal restrictions.

Quickstart

pip install magicattr

import magicattr

class Person:
    settings = {'style': {'width': 200}}
    def __init__(self, name):
        self.name = name

bob = Person('Bob')
width = magicattr.get(bob, 'settings["style"]["width"]')
magicattr.set(bob, 'settings["style"]["width"]', 400)

Verify before relying

  • Whether the package works reliably with modern Python versions (support unspecified in metadata).
  • Whether any edge cases or bugs have emerged since the last release in 2022 that users have worked around.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance abandoned — 1,662 days since the last release
Last repo commit
First released
Downloads 5,930,589/month — #2,008 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: magicattr-0.1.6-py2.py3-none-any.whl

Tags

nested attribute accessdeep object property getterlist and dict traversalgetattr setattr nestedsafe attribute path parsingobject tree navigation
object-introspectiondata-access

More Software Development packages