Skip to main content

Fast data traversal & manipulation tools.

Project description

traversy

Fast data traversal & manipulation tools for Python.

traverse(): Traverse deep data structures such as dict, mo-dots, and dotty_dict. Supports nested lists & data.

from traversy import traverse, set_output_format
import json


jo = json.loads("""{
  "2019": {
    "uat": {
      "pkey": true,
      "user": "testval",
      "testkey": true,
      "mylist": [
      {
        "foo": "bar",
        "foo2": "bar2"
      },
      {
        "baz": "milk",
        "bar": "foo"
      }
      ]
    },
    "dev": {
      "pkey": true,
      "testval": "testval",
      "testval2": true
    },
    "test1": [1, 2, "testval"],
    "test2": [{"one": "foo", "two": "bar", "three": "testval"}]
  }
}""")

def is_eq(key, val, opath, query):
    return val == query


for node in traverse(jo, is_eq, query="milk"):
    print("Found", node.key, ':', node.value)  # baz : milk
    print("Full path access:", jo[node.path_str])  # "2019.uat.mylist.1.baz"

For each iteration, traverse() returns a dict or data object of...

{'key', 'value', 'node_path', 'path_str', 'filter_func',
'filter_args': (data, kwargs), 'parent_node', 'output_formatter'}

For more information on these non-built-in data structure (Which are optional to use), check out mo-dots and dotty_dict.

License: MIT

Changelog

  • 11/13/2020 - Deprecated set_output_format() and made package compatible with both Python 2 and Python 3.

Project details


Download files

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

Source Distribution

traversy-0.1.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

traversy-0.1.1-py2.py3-none-any.whl (3.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file traversy-0.1.1.tar.gz.

File metadata

  • Download URL: traversy-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for traversy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 48e736a59265bbc4212add275ace4a7f2cc23071f5448799d60e5b5270f7fa5d
MD5 5f6e849b619efb5fdbc7ba7c0bd8a214
BLAKE2b-256 dc88cfb402ff6f8fc965982239355f510f036d7715bd4ceff996361d7fcf2308

See more details on using hashes here.

File details

Details for the file traversy-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: traversy-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for traversy-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 76b495e9e8c7b11d591501972d0a44b5544c3164116b0e1af05bcdadc9a63e17
MD5 18301118513531cd77894240acf504e5
BLAKE2b-256 2ff44b37488c8f40ab60b81182da8aac2df5e618234d9b0c4ab3a4d907379b33

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page