Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for querytree, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size querytree-0.1.1-py3-none-any.whl (8.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size querytree-0.1.1.tar.gz (8.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page