Skip to main content

yf

Diagnosing dictionaries

To install: pip install yf

Overview

The yf package provides a suite of tools designed to assist in the diagnosis and inspection of dictionaries, particularly useful for debugging and data validation in Python applications. It includes functions for printing dictionary key paths, validating dictionary contents against specified criteria, comparing dictionaries, and generating example dictionaries from a list of dictionaries.

Features

Key Path Printing

  • print_key_paths(d): Prints all key paths in a dictionary.
  • print_key_paths_and_val_peep(d, n_characters_in_val_peep=15): Prints key paths along with a preview of their values, truncated to a specified number of characters.

Dictionary Validation

  • validate_kwargs(kwargs_to_validate, validation_dict, validation_funs=base_validation_funs, all_kwargs_should_be_in_validation_dict=False, ignore_misunderstood_validation_instructions=False): Validates a dictionary of keyword arguments (kwargs_to_validate) against a set of rules defined in validation_dict using the functions specified in validation_funs.

Dictionary Comparison

  • are_equal_on_common_keys(dict1, dict2): Checks if two dictionaries are equal based on the keys they both share.
  • first_difference_on_common_keys(dict1, dict2, key_path_so_far=None): Finds the first key path where two dictionaries differ.

Dictionary Analysis

  • json_size_of_fields(d): Returns a dictionary where the values are the sizes of the JSON string representations of the corresponding values in the input dictionary.
  • example_dict_from_dict_list(dict_list, recursive=False): Generates an example dictionary that includes at least one occurrence of each key found in a list of dictionaries.
  • dict_of_types_of_dict_values(x, recursive=False): Returns a dictionary describing the types of the values in the input dictionary, optionally doing so recursively.

Usage Examples

Printing Key Paths

d = {'a': {'b': {'c': 1}}}
print_key_paths(d)

Validating Keyword Arguments

validation_rules = {
    'age': {'be at least': 18},
    'name': {'be a': str}
}
kwargs = {'age': 20, 'name': 'John'}
validate_kwargs(kwargs, validation_rules)

Comparing Dictionaries

dict1 = {'a': 1, 'b': 2}
dict2 = {'a': 1, 'b': 3}
are_equal_on_common_keys(dict1, dict2)  # Returns False
first_difference_on_common_keys(dict1, dict2)  # Returns ['b']

Analyzing Dictionary Content

d = {'name': 'Alice', 'data': [1, 2, 3]}
json_size_of_fields(d)

Generating Example Dictionary from List

dict_list = [{'a': 1, 'b': 2}, {'b': 3, 'c': 4}]
example_dict_from_dict_list(dict_list)

Function Documentation

Each function in the yf package is documented with Python docstrings, providing a detailed description of its purpose, parameters, return values, and usage examples. This documentation is accessible via the Python help system or by reading the source code directly.

Installation

To install the yf package, use the following pip command:

pip install yf

This package is a powerful tool for developers working with complex data structures in Python, providing robust functionalities for dictionary diagnostics and validation.

Metadata

Release files for yf 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yf 0.0.6
File Size Uploaded
yf-0.0.6.tar.gz 10.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yf 0.0.6
File Interpreter ABI Platform
yf-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 20.6 kB

Release files / yf-0.0.6.tar.gz

Download URL yf-0.0.6.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
df08ad1769445d6c6ae78c909185444ade336b0e21bbbe1b519895e70bef4f1d
BLAKE2b-256 checksum
How to use checksums
3e671e9d51297e3ce6379f1e09a5f14ae7591564f1729bc5c509eea76e7603a6
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 / yf-0.0.6-py3-none-any.whl

Download URL yf-0.0.6-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58f0a698c04922aa34a690217f280483072a8266bbeb0ce55252bec5d8dcfafe
BLAKE2b-256 checksum
How to use checksums
06f4a822c9fbee4d8ae17d9e7ca6f7a87e9891c066559a7d5e5c3604bdb90a09
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 history Release notifications | RSS feed

This release

0.0.6 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release 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