Skip to main content

DotWiz is a dict subclass that enables accessing (nested) keys in dot notation.

Project description

https://img.shields.io/pypi/v/dotwiz.svg https://img.shields.io/pypi/pyversions/dotwiz.svg https://github.com/rnag/dotwiz/actions/workflows/dev.yml/badge.svg Documentation Status Updates

A dict subclass that is easy to create, and supports fast dot access notation.

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

dotwiz-0.1.0.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distribution

dotwiz-0.1.0-py2.py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page