DotWiz is a dict subclass that enables accessing (nested) keys in dot notation.
Project description
A dict subclass that is easy to create, and supports fast dot access notation.
Documentation: https://dotwiz.readthedocs.io.
Installation
The Dot Wiz library is available on PyPI, and can be installed with pip:
$ pip install dotwiz
The dotwiz library officially supports Python 3.6 or higher.
Usage
Here is an example using DotWiz.from_dict to create a DotWiz object from a dict object:
from dotwiz import DotWiz
dw = DotWiz.from_dict({'this': {'works': {'for': [{'nested': 'values'}]}}})
print(dw)
#> DotWiz(this=DotWiz(works=DotWiz(for=[DotWiz(nested='values')])))
assert dw.this.works['for'][0].nested == 'values' # True
Using make_dot_wiz allows you to pass in keyword arguments when creating a DotWiz object:
Note: This helper function is also aliased to DotWiz.from_kwargs.
from dotwiz import make_dot_wiz
dw = make_dot_wiz({'hello, world!': 123}, AnyKey='value', isActive=True)
assert dw['hello, world!'] == 123
assert dw.AnyKey == 'value'
assert dw.isActive
Features
TODO
Benchmarks
The benchmark tests can be found in the project repo on GitHub.
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, and up to 2x faster in general to access keys by dot access.
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dotwiz-0.1.0.tar.gz
.
File metadata
- Download URL: dotwiz-0.1.0.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcd6ff793922058a04aef9ff51173868a5b394d4a0802fc9a7aedfec5ed6cd4f |
|
MD5 | a93cd3876fe133e881c052ae1c53a171 |
|
BLAKE2b-256 | a85bb526aa0e65a9801ffb478d6087864236d49b7984a35fbbff9d6598f4243f |
File details
Details for the file dotwiz-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: dotwiz-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3537ac641e733421dd190dd255c471687de4ca6b4dc6274bb0c7f0bdcd2fcdb3 |
|
MD5 | 639b5ee347b76fd87dfc792e67a88993 |
|
BLAKE2b-256 | e028f5adab1f2bfa6f08ef9141cd3ff5d25237ff6045e09c8ea5353b6fe7180e |