Dot Wiz
A blazing fast dict
subclass that enables dot access notation via Python
attribute style. Nested dict
and list
values are automatically
transformed as well.
- Documentation: https://dotwiz.readthedocs.io.
Install
$ pip install dotwiz
Usage
Here is an example of how to create and use a DotWiz
object:
from dotwiz import DotWiz
dw = DotWiz({'this': {'works': {'for': [{'nested': {'values': True}}]}}},
the_answer_to_life=42)
print(dw)
# > DotWiz(this=DotWiz(works=DotWiz(for=[DotWiz(nested=DotWiz(values=True))])),
# the_answer_to_life=42)
assert dw.this.works['for'][0].nested.values # True
assert dw.the_answer_to_life == 42
Using make_dot_wiz
allows you to pass in an iterable object when
creating a DotWiz
object:
from dotwiz import make_dot_wiz
dw = make_dot_wiz([('hello, world!', 123), ('easy: as~ pie?', True)],
AnyKey='value')
print(dw)
#> DotWiz(AnyKey='value', hello, world!=123, easy: as~ pie?=True)
assert dw['hello, world!'] == 123
assert dw['easy: as~ pie?']
assert dw.AnyKey == 'value'
Features
- TODO
Benchmarks
Check out the Benchmarks section in the docs for more info.
Using a dot-access approach such as DotWiz
can be up
to 100x faster than with make_dataclass from the dataclasses
module.
It’s also about 5x faster to create a DotWiz
from a dict
object
as compared to other libraries such as prodict
— or close to 15x faster
than creating a Box — and up to 10x faster in general to access keys
by dot notation — or almost 30x faster than accessing keys from a DotMap.
Contributing
Contributions are welcome! Open a pull request to fix a bug, or open an issue to discuss a new feature or change.
Check out the Contributing section in the docs for more info.
Credits
This package was created with Cookiecutter and the rnag/cookiecutter-pypackage project template.