Adict is an attribute-accessible dynamic dict wrapper, which allows to access dict items in
attribute notation (".") and allows friendly checks for non-existing items.
Adict is not an extension of Python's dict (as for example
adict and dict),
but a wrapper around dict objects. This allows to use attribute syntax not only for objects
created using the Adict() constructor, but also for child dictionaries, which are automatically
wrapped into an Adict when they're returned.
Features
- Default
dictbehavior - Full wrapping of nested
dicts - Fail-safe attribute notation (
adict.key) doesn't raiseKeyError - Save traversing using parenthesis syntax (
('key')) - Supports nested dicts
- Supports JSON encoding
Installation
pip install dictat
Examples
from dictat import Adict
dict1 = Adict()
print('noob' in dict1) # False
print(dict1.noob) # None - doesn't fail
# print(dict1['noob']) # raises KeyError - default dict behavior
dict1.noob = 'me'
print(dict1['noob']) # "me" - dict notation
print(dict1.noob) # "me" -, attribute notation
dict1.sub = {}
dict1.sub.dict = {'noobs': ['me', 'you']}
print(dict1.sub.dict.noobs[1]) # "you"
dict2 = {'noob': 'me', 'sub': {'you': 'noob'}}
dict3 = Adict(dict2) # construct around existing dict
print('noob' in dict3) # True
print(dict3['noob']) # "me", dict notation
print(dict3.noob) # "me", attribute notation
print(dict3.sub.you) # "noob', nested attribute notation
Safe traversing using paranthesis syntax
At the cost of not having None values, the () operator allows key access, which always returns
a valid (empty) Adict instance when the key doesn't exist. This allowes to traverse dicts
into depper levels, without intermediate None checks. This syntax is basically an abbreviation
of the dict.get(key, default) function, but has the additional feature to again wrap default
dict values into Adict(dict) results.
dd = Adict({'noob': 'me', 'sub': {'you': 'noob'}})
print(dd('sub')('you')) # "noob"
# is equivalent to
print(dd('sub', {})('you', {}))
# is equiivalent to
print(dd.get('sub', {}).get('you', {}))
print(dd('nokey')) # {} (isinstance Adict)
print(dd('nokey', {})) # {} (isinstance Adict)
print(dd('nokey', None) # None
JSON encoding
from dictat import Adict, JsonEncoder
import json
import pathlib
adict = Adict()
adict.key = 'string'
adict.sub = dict(subkey='subvalue', obj=object())
adict.path = pathlib.Path('somepath') # normally not JSON serializable
dump = json.dumps(adict, cls=JsonEncoder)
print(dump)
# {"key": "string", "sub": {"subkey": "subvalue"}, "path": "somepath"}
Metadata
Release files for dictat 1.2.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 | Provenance | Actions |
|---|---|---|---|---|
| dictat-1.2.0.tar.gz | 6.4 kB | Without provenance | Details for dictat-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dictat-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for dictat-1.2.0-py3-none-any.whl |
Total release size: 11.4 kB
Release files / dictat-1.2.0.tar.gz
| Download URL | dictat-1.2.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e68be789a70fb9377f5701a03208839bab18f77e37d69d4eafa61b55bfc5e07b
|
|
BLAKE2b-256 checksum How to use checksums |
526263f9043135c0a9eab8029eeaaa6be10da53c36269c66330d27e5322a28cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / dictat-1.2.0-py3-none-any.whl
| Download URL | dictat-1.2.0-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9b3d0ffcab13761aec7a6ae9b84100e4a5ef324e7c053010821863c145dc371b
|
|
BLAKE2b-256 checksum How to use checksums |
1f3e3acf8a792f977a69999d66886550808b1d9cce8768e1d69bb9ffc7c93584
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Security for dictat 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.