la-deep-get
Function to get value that is deep inside another structure.
install
pip install la-deep-get
syntax
dget(structure, *args, default=None)
structure - Structure to go through
*args - Each field to be passed as key
default - The value to return in case it fail to access any of the keys (default is None)
example
Let's say that you have dictionary with product information and you want all active big images.
product = {
"name": "really cool product",
"images": {
"active: {
"small": [
"https://www.smallimage.com",
"https://www.smallimage.com",
"https://www.smallimage.com",
],
"big": [
"https://www.bigimage.com",
"https://www.bigimage.com",
"https://www.bigimage.com",
]
},
"disabled": {
"small": [
"https://www.notcool.com",
"https://www.notcool.com",
"https://www.notcool.com",
],
"big": [
"https://www.notcool.com",
"https://www.notcool.com",
"https://www.notcool.com",
]
}
}
}
It's a simple one line function to get a value.
big_images = dget(product, "images", "active", "big", default=[])
Without the package you would have to do things like try except:
try:
big_images = product["images"]["active"]["big"]
except:
big_images = []
Or chain get() methods like:
big_images = product.get("images", {}).get("active", {}).get("big", [])
usage
All that you need to know is that you will navigate like normally do with dictionaries or lists (using square brackets) but it will not raise exceptions if one field doesn't exist along the way.
list_ = [
[1,2,3],
[4,5,6],
[7,8,9],
[
[10, 11, 12],
[13, 14, 15],
[16, 17, 18],
]
]
# Same as: list_[3][1][2]
value = dget(list_, 3, 1, 2)
print(value) # 15
list_ = {
"hello": {
"annoing": {
"dictionary": "here"
}
}
}
# Same as: list_["hello"]["annoing"]["dictionary"]
value = dget(list_, "hello", "annoing", "dictionary")
print(value) # "here"
It really doesn't care what strcuture it is.
list_ = {
"first": {
5: [
"nice"
]
}
}
# Same as: list_["first"][5][0]
value = dget(list_, "first", 5, 0)
print(value) # "nice"
Metadata
Release files for la-deep-get 0.0.6
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 |
|---|---|---|---|---|
| la-deep-get-0.0.6.tar.gz | 3.7 kB | Without provenance | Details for la-deep-get-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| la_deep_get-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for la_deep_get-0.0.6-py3-none-any.whl |
Total release size: 6.8 kB
Release files / la-deep-get-0.0.6.tar.gz
| Download URL | la-deep-get-0.0.6.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7fd0a28d6e19620effdd57e044217390debdfd346c9c23a2f2d0f597be39c20b
|
|
BLAKE2b-256 checksum How to use checksums |
64f7145b515895ae57c47cfe56eea180297a596df05f53e6ade7c11185c1b373
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.1.3 CPython/3.10.6
|
Release files / la_deep_get-0.0.6-py3-none-any.whl
| Download URL | la_deep_get-0.0.6-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b71ef4343f624a06f51dbe9615b26cbdd940b11e54ef8984aff00a445aeef54b
|
|
BLAKE2b-256 checksum How to use checksums |
ca829d9982d80f9644f2caf8c9184272dd4fe47693b5a5c988f6ef332b2995f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.1.3 CPython/3.10.6
|
Security for la-deep-get 0.0.6
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.