Skip to main content

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.

Download files

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

Source Distribution

yv-0.0.7.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yv-0.0.7-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file yv-0.0.7.tar.gz.

File metadata

  • Download URL: yv-0.0.7.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for yv-0.0.7.tar.gz
Algorithm Hash digest
SHA256 5fbb4f01dab9db00e81fb8a55736659f108afea0e96119ef84b584445b3bed37
MD5 16ecfc222e5dc7a9cb6921cbd538ca6b
BLAKE2b-256 d61eec6c25711d622fbb4df4bc780ec9f30d283f7cbc38196b78743b4c59694f

See more details on using hashes here.

File details

Details for the file yv-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: yv-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for yv-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3d55a54acbb52718aaa8975cd9ae2d709251705bcb39724ed814542c45cd9b79
MD5 be7a2a6fbaf6be677b5fa1e3a0a5e2f8
BLAKE2b-256 6390276fbc2609fcacef9aad3ba52ef5f3b9eb17ce31e3a764d8d9b4eb04ac06

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page