A data structure for quickly dealing with nested data in different formats
Project description
QueryTree
QueryTree is a python data structure that lets you quickly access deeply nested data and load/save it in any major format.
With QueryTree, you don't have to check for the esistance of (or create) any intermediate nodes.
json_str = """
{
"foo": {
"bar": [
{
"baz": {
"n": 1
}
},
{
"baz": {
"n": 1
},
"buz": {
"k": 2
}
}
]
}
}
"""
tree = Tree.parse_json(json_str)
print(tree['foo.bar.0.baz.n']) # 1
print(tree['foo.bar.1.buz.k']) # 2
# accessing nonexistant locations isn't a problem
print(tree['foo.bar.0.buz.k']) # None
print(tree['something.else']) # None
# assign values
tree['foo.bar.0.baz.n'] = 99
tree['foo.foo'] = {"myvalue": "a value"}
# save as any format
print(tree.to_yaml())
Outputs:
foo:
bar:
- baz:
n: 99
- baz:
n: 1
buz:
k: 2
foo:
myvalue: a value
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
querytree-0.1.0.tar.gz
(1.6 kB
view hashes)
Built Distribution
Close
Hashes for querytree-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b298e8598d41579dae92c2528e61952cfa8afe5307b11f3386d15e416aa2483 |
|
MD5 | b82cc3378e5b8e281e94cf07bbe6f3e2 |
|
BLAKE2b-256 | 1490f966e0f454a224adc435ff48196c8292bdb31a1fd9196571cbc9c1c689e5 |