Skip to main content

A JFDI approach that hydrates a Python class to allow dot notation access to the data structures.

Project description

PyHydrate

license pypi ci cd downloads versions

Easily access your json, yaml, dicts, and/or list with dot notation.

PyHydrate is a JFDI approach to interrogating common data structures without worrying about .get() methods, defaults, or array slicing. It is easy to use and errors are handled gracefully when trying to drill to data elements that may not exist. Additionally, data types are inferred, recursive depths are tracked, and key casting to snake case is mapped and managed.

Installation

Install using pip

pip install pyhydrate
# or, if you would like to upgrade the library
pip install -U pyhydrate

A Simple Example

Load any Python variable, and the class hydration will ensue. Access the data via dot notation.

from pyhydrate import PyHydrate as PyHy

_doc = {
  "level-one": {
    "levelTWO": {
      "Level3": {
        "TestString": "test string",
        "testInteger": 1,
        "test_Float": 2.345,
        "Test_BOOL": True
      }
    }
  }
}

_demo = PyHy(_doc, debug=True)

print(_demo.level_one.level_two)

# debug output
# >>> Root :: <PyHydrate>
#   >>> Object :: Get == level_one :: Depth == 1
#      >>> Object :: Get == level_two :: Depth == 2

# print output (yaml)
# level_3:
#   test_string: test string
#   test_integer: 1
#   test_float: 2.345
#   test_bool: true

Then access any level of the hydration by making a call to the class. Valid values are: , 'value', 'element', 'type', 'depth', 'map', 'json', and 'yaml'. See nomenclature below.

print(_demo.level_one.level_two('element'))

# debug output
# >>> Root :: <PyHydrate>
#    >>> Object :: Get == level_one :: Depth == 1
#       >>> Object :: Get == level_two :: Depth == 2
#          >>> Object :: Call == element :: Depth == 3

# print output (dict)
# {'dict': {'level_3': {'test_string': 'test string', 'test_integer': 1, 'test_float': 2.345, 'test_bool': True}}}

If a data point does not exist via expressed notation, an unknown/None/null value is returned.

print(_demo.level_one.level_four)

# debug output
# >>> Root :: <PyHydrate>
#    >>> Object :: Get == level_one :: Depth == 1
#       >>> Object :: Get == level_four :: Depth == 2
#          >>> Primitive :: Call == value :: Depth == 3 :: Output == None

# print output (yaml)
# NoneType: null

Nomenclature

The following nomenclature is being used within the code base, within the documentation, and within

  • Structure: A complex data element expressed as a dict or list, and any combination of nesting between the two.
    • Object: A collection of key/value pairs, expressed as a dict in the code base.
    • Array: A collection of primitives, Objects, or other Arrays, expressed as a list in the code base.
  • Primitive: A simple atomic piece of data with access to its type and underlying value.
    • String: A quoted collection of UTF-8 characters.
    • Integer: A signed integer.
    • Float: A variable length decimal number.
    • None: A unknown Primitive, expressed as None with a NoneType type.
  • Values: A primary data element in the code base used to track the lineage of the transformations in the class.
    • Source: The raw provided document, either a Structure or a Primitive.
    • Cleaned: Similar value to the source, but with the keys in the Objects cleaned to be cast as lower case snake.
    • Hydrated: A collection of nested classes representing Structures and Primitives that allows the dot notation access and graceful failures.
  • Element: A single dict output representation, where the key is represented as the type and the value is the Structure
  • Type: The Python expression of type with respect to the data being interrogated.
  • Map: A dict representation of the translations from source Object keys to "cleaned" keys, i.e. the Cleaned Values.

Documentation

Coming Soon to readthedocs.com!

Contributing

For guidance on setting up a development environment and how to make a contribution to PyHydrate, see CONTRIBUTING.md.

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

pyhydrate-1.0.8.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

pyhydrate-1.0.8-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file pyhydrate-1.0.8.tar.gz.

File metadata

  • Download URL: pyhydrate-1.0.8.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pyhydrate-1.0.8.tar.gz
Algorithm Hash digest
SHA256 d8d4b54811ea9ca62a0b4832e588755adb9abc865f0cc063138c0d0cb70068c0
MD5 7351d3dd7b43d8598392b99dde7809ed
BLAKE2b-256 aabae41d0192904f7d44192c22d26aa0e1ee27b454c5e6f4af558ca69b5a8ddf

See more details on using hashes here.

File details

Details for the file pyhydrate-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: pyhydrate-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pyhydrate-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1d1451acd94e925d4a76936f483c94443b6fec60bf79368d9daf20b52f9fee30
MD5 377e26ddf3bce526cb3a96cb45dbede5
BLAKE2b-256 f767d8efc43a4ae2554edb5663d55bcd2a8c0a1ca30d530679d970087a5b7b59

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