DotDict
A simple Python library that builds upon argparse.Namespace to make chained attributes possible.
Why?
Configs of all kinds follow a dict-like structure.
However, nobody likes the dict["key"] syntax. We all much prefer the dict.key syntax.
There are a number of workarounds for this, including easydict or argparse.Namespace (upon which this library is based).
The downside of these libraries, though, is that when you want to start a new level, you must explicitly define it first. For example:
config = edict()
config.host = 'localhost'
config.users = edict() # or {}
config.users.foo = 'bar'
This is ugly.
Wouldn't you much prefer the following syntax?
config = dd()
config.host = 'localhost'
config.users.foo = 'bar'
Installation
Installation is simple: pip install attr-dot-dict. Alternatively: pip install . from the root of the repository.
Usage
Usage is equally as simple:
from dotdict import DotDict as dd
x = dd()
x.a.b.c = 1
x.a.d = 2
x.a.b.e = 3
print(x) # DotDict(a=DotDict(b=DotDict(c=1, e=3), d=2))
print(vars(x)) # {'a': DotDict(b=DotDict(c=1, e=3), d=2)}
print(vars(x.a)) # {'b': DotDict(c=1, e=3), 'd': 2}
Metadata
Release files for attr-dot-dict 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| attr-dot-dict-0.1.0.tar.gz | 39.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| attr_dot_dict-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 66.6 kB
Release files / attr-dot-dict-0.1.0.tar.gz
| Download URL | attr-dot-dict-0.1.0.tar.gz |
|---|---|
| Size | 39.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff95eaa1732844d7f052609a49f7073a25750812b5cd9e8a9220a797733aafca
|
|
BLAKE2b-256 checksum How to use checksums |
a2205545f37264691945529a069abb646dab6de274dfdd6a327b22dff948cf0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|
Release files / attr_dot_dict-0.1.0-py3-none-any.whl
| Download URL | attr_dot_dict-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3403b96e2dd09813dc8e8cb59cfe822c805a1605c3d9a7df4567b70fd6955a28
|
|
BLAKE2b-256 checksum How to use checksums |
afab3c717181e61cfa97b71e6e01d072725c2d323350b408ab43547d02bc19ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.17
|