magicattr
A getattr and setattr that works on nested objects, lists, dicts, and any combination thereof without resorting to eval
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 magicattruv
uv add magicattrpoetry
poetry add magicattrInstalling 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
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
super-collectionsConverts nested JSON and YAML data into Python…
permissive · top 5,000 on PyPI
pathablePathable provides path-like objects for…
permissive · top 1,000 on PyPI
flatdictFlattens nested dictionaries into single-level…
permissive · top 5,000 on PyPI
json-flattenConverts nested JSON objects into flat…
permissive · top 15,000 on PyPI
mulpyplexerMulpyplexer applies method calls and attribute…
permissive · top 15,000 on PyPI
python-boxBox wraps Python dictionaries to enable…
permissive · top 5,000 on PyPI
jsonslicerParses JSON streams and large files without…
permissive · top 15,000 on PyPI
magic-filterProvides a filter mechanism based on dynamic…
permissive · top 5,000 on PyPI
slicerProvides a uniform slicing interface for…
permissive · top 5,000 on PyPI
dictorDictor provides a simplified interface for…
permissive · top 15,000 on PyPI