A JFDI approach that hydrates a Python class to allow dot notation access to the data structures.
Project description
PyHydrate
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 aNoneType
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
Built Distribution
File details
Details for the file pyhydrate-1.0.5.tar.gz
.
File metadata
- Download URL: pyhydrate-1.0.5.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b63aba5a1e20151520d71e4549ab9c623023b746692fbc99bce42bba341dba03 |
|
MD5 | 337228ed23b65dd69e2438bb087fb18f |
|
BLAKE2b-256 | d492dedbe94e09a1c38b8951c4092bd5e2e6b835c3d5c63a490c58faad8dbf1f |
File details
Details for the file pyhydrate-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: pyhydrate-1.0.5-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c157676b19a2ab7be5c21ffd686b648eeeb2d7c7703ee87f67f75e9dc365ddf3 |
|
MD5 | 17bccb5f598262dfffa93b8b6b16769c |
|
BLAKE2b-256 | ee43071e5e9117df52a5498c41f76fc1e5e2974597b65343d9c2b88f34446891 |