INTRODUCTION
A magic dictionary which never raises KeyError but creates non-existent
items as they are requested. By default newly created items in this way are
an empty instance of AwesomeDict, but that can be set with set_defaults.
The instances also have a filter method which can filter based on
a regular expression matched against the key or value. A default regex for
filter can be set with set_filter.
INSTALLATION
pip install awesomedict
EXAMPLE USAGE
from awesomedict import AwesomeDict
import json
# create a default order
mdorder = AwesomeDict().set_defaults(
{
'^price$': 0,
'_address$': 'No such street, PO 000'
}).set_defaults({'^items$': []}, do_copy=True)
mdorder['items']
mdorder['price']
mdorder['shipping_address']
mdorder['billing_address']
md = AwesomeDict().set_defaults(
{'^[0-9]+$': mdorder}, do_copy=True).set_filter('^!')
md['customers']['foo'][1]['price'] = 15
md['customers']['foo'][1]['items'].append('notebook')
md['customers']['foo'][1]['shipping_address'] = 'FOO street'
md['customers']['foo'][1]['billing_address'] = 'FOO office'
md['customers']['foo'][1]['!notes'] = 'important notes'
md['customers']['foo'][2] # use all defaults
md['customers']['!important customer'][1]['price'] = 25 # use default address
md['customers']['!important customer'][1]['items'].append('pen')
print(json.dumps(md, default=lambda o: o.data, indent=2))
print('\n-----important only:-----\n')
print(json.dumps(md.filter(), default=lambda o: o.data, indent=2))
print('\n-----items only:-----\n')
print(json.dumps(md.filter('^items$'), default=lambda o: o.data, indent=2))
$ python demo.py
{
"customers": {
"foo": {
"1": {
"items": [
"notebook"
],
"price": 15,
"shipping_address": "FOO street",
"billing_address": "FOO office",
"!notes": "important notes"
},
"2": {
"items": [],
"price": 0,
"shipping_address": "No such street, PO 000",
"billing_address": "No such street, PO 000"
}
},
"!important customer": {
"1": {
"items": [
"pen"
],
"price": 25,
"shipping_address": "No such street, PO 000",
"billing_address": "No such street, PO 000"
}
}
}
}
-----important only:-----
{
"customers": {
"foo": {
"1": {
"!notes": "important notes"
}
},
"!important customer": {
"1": {
"items": [
"pen"
],
"price": 25,
"shipping_address": "No such street, PO 000",
"billing_address": "No such street, PO 000"
}
}
}
}
-----items only:-----
{
"customers": {
"foo": {
"1": {
"items": [
"notebook"
]
},
"2": {
"items": []
}
},
"!important customer": {
"1": {
"items": [
"pen"
]
}
}
}
}
Metadata
Release files for awesomedict 0.1.1
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 |
|---|---|---|---|---|
| awesomedict-0.1.1.tar.gz | 4.3 kB | Without provenance | Details for awesomedict-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| awesomedict-0.1.1-py2-none-any.whl | Python 2 | none | any | Details for awesomedict-0.1.1-py2-none-any.whl |
Total release size: 9.7 kB
Release files / awesomedict-0.1.1.tar.gz
| Download URL | awesomedict-0.1.1.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db9a310bbc83e8559a775da9be410c3abd929d434fc827b7bc844f50c6ffcc22
|
|
BLAKE2b-256 checksum How to use checksums |
8536dc622fa20e2c0a7e395f2554045a2564e80ae6bdcd430e06334913715804
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Release files / awesomedict-0.1.1-py2-none-any.whl
| Download URL | awesomedict-0.1.1-py2-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
90fc00d12149ca1960cd9200489f65145579513755f18276234f9793ea15f13b
|
|
BLAKE2b-256 checksum How to use checksums |
ad51f82d418823fcf70876932da47f0f2c4b52e9ad5f547a8a99fc9b6282ea08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Security for awesomedict 0.1.1
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.