yv
Simple utils to get stuff out of Mappings (dict-like objects).
To install: pip install yv
Overview
The yv package provides a collection of utilities designed to facilitate the extraction, manipulation, and querying of data from dictionary-like objects in Python. These utilities are particularly useful when dealing with nested or complex data structures commonly encountered in data processing tasks.
Features
- Key Chain Extraction: Retrieve values from a dictionary using a list of potential keys.
- Subdictionary Access: Enhanced dictionary class allowing for easy subdictionary creation and batch key retrieval.
- MongoDB-style Querying: Filter dictionary items using MongoDB-like query language.
- Nested Key Paths: Functions to handle nested dictionary paths for setting and getting values.
- Utility Functions: Includes various utility functions for dictionary manipulation and querying.
Usage Examples
Key Chain Extraction
Retrieve values from a dictionary using a list of potential keys, with the first found key's value being returned.
from yv import key_chain
d = {'a': 1, 'b': 2, 'c': 3}
result = key_chain(d, 'x', 'c', 'b') # Returns 3
Subdictionary Access
Enhanced dictionary class that interprets lists and sets of keys as requests for subdictionaries.
from yv import Subdict
d = {'a': 1, 'b': 2, 'c': 3}
dd = Subdict(d)
subdict = dd('a', 'b', c=100, d=100) # Returns {'a': 1, 'b': 2, 'c': 3, 'd': 100}
MongoDB-style Querying
Filter dictionary items using a MongoDB-like query.
from yv import dict_filt_from_mg_filt
mg_filt = {'a': {'$gte': 10, '$lt': 20}}
filt = dict_filt_from_mg_filt(mg_filt)
result = list(filter(filt, [{'a': x} for x in range(9, 22)])) # Returns [{'a': 10}, {'a': 15}]
Nested Key Paths
Set and get values in a dictionary using dot-separated string paths or lists of keys.
from yv import set_value_in_nested_key_path, get_value_in_key_path
d = {}
set_value_in_nested_key_path(d, 'a.b.c', 100)
print(d) # Outputs: {'a': {'b': {'c': 100}}}
value = get_value_in_key_path(d, 'a.b.c') # Returns 100
Utility Functions
Various utility functions to manipulate and query dictionaries.
from yv import left_union, all_but
d = {'a': 1, 'b': 2}
defaults = {'b': 3, 'c': 4}
new_d = left_union(d, defaults) # Returns {'b': 2, 'c': 4, 'a': 1}
filtered_d = all_but(d, ['a']) # Returns {'b': 2}
Documentation
Each function and class within the yv package is documented with docstrings, providing detailed usage instructions and examples. This documentation can be accessed via Python's built-in help system or by reading the source code directly.
For more detailed examples and usage, refer to the function and class definitions in the source code.
Release files for yv 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| yv-0.0.7.tar.gz | 10.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| yv-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.5 kB
Release files / yv-0.0.7.tar.gz
| Download URL | yv-0.0.7.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5fbb4f01dab9db00e81fb8a55736659f108afea0e96119ef84b584445b3bed37
|
|
BLAKE2b-256 checksum How to use checksums |
d61eec6c25711d622fbb4df4bc780ec9f30d283f7cbc38196b78743b4c59694f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / yv-0.0.7-py3-none-any.whl
| Download URL | yv-0.0.7-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d55a54acbb52718aaa8975cd9ae2d709251705bcb39724ed814542c45cd9b79
|
|
BLAKE2b-256 checksum How to use checksums |
6390276fbc2609fcacef9aad3ba52ef5f3b9eb17ce31e3a764d8d9b4eb04ac06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|