dotpath
A tiny utility to read values from nested dicts/lists using dot-separated paths.
Install
pip install dotpath
Example
from dotpath import get_path, set_path
data = {
'pets': {
'dog': {
'name': 'Billy',
'age': 5,
'friends': ['Joe', 'Jack'],
},
'cat': {
'name': 'Joe',
'age': 6,
'friends': ['Billy', 'Pop'],
},
},
}
dog_name = get_path(data, 'pets.dog.name') # "Billy"
cat_name = get_path(data, 'pets.cat.name') # "Joe"
first_friend = get_path(data, 'pets.dog.friends.0') # "Joe"
set_path(data, 'pets.dog.age', 6) # Modifies the object in place
set_path(data, 'pets.bird.name', 'Kiwi') # Creates a new key
print(data) # {"pets": {"dog": {"name": "Billy", "age": 6, "friends": ["Joe", "Jack"]}, "cat": {"name": "Joe", "age": 6, "friends": ["Billy", "Pop"]}, "bird": {"name": "Kiwi"}}}
API
get_path(obj, path, default=None): Returns the value atpathordefaultif the path cannot be resolved.set_path(obj, path, value, default=None): Setsvalueatpathand returns the mutated object ordefaultif it fails.
Notes
- Path segments are split by
.. - List indexes are supported via numeric segments (e.g.
friends.0).
Metadata
Release files for dotpath 1.0.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 |
|---|---|---|---|---|
| dotpath-1.0.0.tar.gz | 58.9 kB | Without provenance | Details for dotpath-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dotpath-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for dotpath-1.0.0-py3-none-any.whl |
Total release size: 62.7 kB
Release files / dotpath-1.0.0.tar.gz
| Download URL | dotpath-1.0.0.tar.gz |
|---|---|
| Size | 58.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1df4689845ff4bef7e485d51ce865d43fe8cde19a21ab01125f0e7a8d2724e0
|
|
BLAKE2b-256 checksum How to use checksums |
cc550935c514885a14e020d597e2141f79a8e630a63d9d51ecbd425e4dec39ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Release files / dotpath-1.0.0-py3-none-any.whl
| Download URL | dotpath-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
770c0cd8189bb9eb481d89ce601609087241dac0f725b356de633fe8f06efbf2
|
|
BLAKE2b-256 checksum How to use checksums |
3a2172afa3d697f62aef2e0b51fab82316cc72d1767058a124972ca3d4f1b99f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Security for dotpath 1.0.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.