python-benedict is a `dict` subclass that enhances the standard Python dictionary with powerful features like keylist, keypath, and keyattr support. It provides normalized I/O operations for various data formats (including base64, csv, ini, json, pickle, plist, query-string, toml, xls, xml, yaml) and numerous utility methods. It is currently active, with its latest version being 0.35.0, and maintains a regular release cadence.
pip install python-benedictVerified import paths — ran on the pinned version, not inferred.
This example demonstrates creating a `benedict` instance, accessing and setting values using both keypath (dot notation) and keylist (list of keys), and serializing the dictionary to a JSON string.
Upgrade Python to 3.10 or newer, or pin `python-benedict<0.34.0`.
Ensure that arguments passed for keylist access are strictly `list` types.
Either choose a custom keypath separator by passing `keypath_separator='_'` (or another suitable character) to the `benedict` constructor, or disable keypath functionality with `keypath=False` if not needed. Alternatively, sanitize keys in the original dictionary.
Adjust code to expect `benedict` instances from `items()` and `values()`, or explicitly cast results to `dict` if standard `dict` behavior is strictly required.
pip install python-benedict
Use the `get()` method with a default value (e.g., `data.get('path.to.missing.key', None)`) or check for key existence with the `in` operator (e.g., `if 'path.to.missing.key' in data:`).Install the required dependency using pip: `pip install lxml` or install 'python-benedict' with its xml extra: `pip install python-benedict[xml]`.
Ensure the input string is a well-formed document according to its respective format (e.g., JSON, YAML) before passing it to the `benedict.from_json()` method.