python-box is an active library that provides an advanced Python dictionary with dot notation access, allowing dictionary keys to be accessed as attributes. It simplifies working with deeply nested data structures and offers various serialization methods (JSON, YAML, TOML, JSON5, TOON) and other utility classes. The current version is 7.4.1, and it maintains a regular release cadence with updates and bug fixes.
pip install python-boxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a `Box` object from a standard Python dictionary and access its elements using convenient dot notation. It also shows how to modify and add new attributes, and highlights the behavior when accessing non-existent keys (raising an AttributeError by default).
Upgrade your Python environment to 3.10 or higher. For example, Python 3.9 was dropped in 7.4.0, and 3.8 in 7.3.0.
If you need keys with periods to be treated literally without nesting, use the `box_dots_filter` parameter to specify which keys should be excluded from dot notation parsing, or use `box_dots_exclude` (added in 7.4.0) to explicitly list keys to ignore.
Install the required dependencies for the serialization format you intend to use. For example, `pip install python-box[yaml]` or `pip install python-box[all]` for all optional features.
Update the signature of your `default_function` to accept `box_instance` and `key` as arguments, even if you don't use them, e.g., `def my_default_func(box_instance, key): ...`