Skip to main content

Dict tools for Python projects

Project description

INSTALLATION

pip install dict-toolbox

Contains various dict tools from the Salt Project.

Differ

from dict_tools import differ

deep_diff

Computes the difference between to dictionaries.

recursive_diff

Computes the recursive difference between two dictionaries.

Trim

from dict_tools import trim

trim_dict

Takes a dictionary and iterates over its keys, looking for large values and replacing them with a trimmed string.

Update

from dict_tools import trim

update

Merges “upd” recursively into the target

merge_list

merge_recurse

merge_aggregate

merge_overwrite

merge

ensure_dict_key

Ensures that in_dict contains the series of recursive keys defined in keys.

set_dict_key_value

Ensures that in_dict contains the series of recursive keys defined in keys. Also sets whatever is at the end of in_dict traversed with keys to value.

update_dict_key_value

Ensures that in_dict contains the series of recursive keys defined in keys. Also updates the dict, that is at the end of in_dict traversed with keys, with value.

append_dict_key_value

Ensures that in_dict contains the series of recursive keys defined in keys. Also appends value to the list that is at the end of in_dict traversed with keys.

extend_dict_key_value

Ensures that in_dict contains the series of recursive keys defined in keys. Also extends the list, that is at the end of in_dict traversed with keys, with value.

XML

from dict_tools import xml

to_dict

Convert an XML tree into a dict. The tree that is passed in must be an ElementTree object.

YAMLEX

from dict_tools import yamlex

YAMLEX is a format that allows for things like sls files to be more intuitive.

SLSMap

Ensures that dict str() and repr() are YAML friendly.

SLSString

Ensures that str str() and repr() are YAML friendly.

AggregatedMap

AggregatedSequence

Dumper

sls dumper.

merge_recursive

Merge obj_b into obj_a.

MySQL

from dict_tools import mysql

to_num

Convert a string to a number.

to_dict

Convert MySQL-style output to a python dictionary.

DATA

from dict_tools import data

CaseInsensitiveDict

Inspired by requests’ case-insensitive dict implementation, but works with non-string keys as well.

ImmutableDict

An immutable mapping that can access it’s keys via the namespace

NamespaceDict

A dictionary that can access it’s string keys through the namespace

compare_dicts

Compare before and after results from various functions, returning a dict describing the chagnes that were made.

is_dictlist

Returns True if data is a list of one-element dicts (as found in many SLS schemas)

object_to_dict

Convert an arbitrary object to a dictionary

recursive_diff

Performs a recursive diff on mappings and/or iterables and returns the result in a {‘old’: values, ‘new’: values}-style. Compares dicts and sets unordered (obviously), OrderedDicts and Lists ordered (but only if both old and new are of the same type), all other Mapping types unordered, and all other iterables ordered.

repack_dictlist

Takes a list of one-element dicts (as found in many SLS schemas) and repacks into a single dictionary.

subdict_match

Check for a match in a dictionary using a delimiter character to denote levels of subdicts, and also allowing the delimiter character to be matched. Thus, ‘foo:bar:baz’ will match data[‘foo’] == ‘bar:baz’ and data[‘foo’][‘bar’] == ‘baz’. The latter would take priority over the former, as more deeply-nested matches are tried first.

traverse_dict

Traverse a dict using a colon-delimited (or otherwise delimited, using the ‘delimiter’ param) target string. The target ‘foo:bar:baz’ will return data[‘foo’][‘bar’][‘baz’] if this value exists, and will otherwise return the dict in the default argument.

traverse_dict_and_list

Traverse a dict or list using a colon-delimited (or otherwise delimited, using the ‘delimiter’ param) target string. The target ‘foo:bar:0’ will return data[‘foo’][‘bar’][0] if this value exists, and will otherwise return the dict in the default argument. Function will automatically determine the target type. The target ‘foo:bar:0’ will return data[‘foo’][‘bar’][0] if data like {‘foo’:{‘bar’:[‘baz’]}} , if data like {‘foo’:{‘bar’:{‘0’:’baz’}}} then return data[‘foo’][‘bar’][‘0’]

Arg

from dict_tools import arg

yamlify_arg

yaml.safe_load the arg

Aggregation

from dict_tools import aggregation

Makes it possible to introspect dataset and aggregate nodes when it is instructed

levelise

Describe which levels are allowed to do deep merging.

mark

Convert obj into an Aggregate instance

aggregate

Merge obj_b into obj_a.

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

dict-toolbox-2.3.2.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

dict_toolbox-2.3.2-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file dict-toolbox-2.3.2.tar.gz.

File metadata

  • Download URL: dict-toolbox-2.3.2.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.16

File hashes

Hashes for dict-toolbox-2.3.2.tar.gz
Algorithm Hash digest
SHA256 06984651ee966a72417dc264e0c6782bcf6d2eaf25f31f0d324f2595b89ae069
MD5 a84bd8404e56e6e5fce35b3cc00cad94
BLAKE2b-256 42f190b2c927a0c2f0e8f56d3769dfdc1e1b8bc32d44571e09d10b78f9981ce9

See more details on using hashes here.

File details

Details for the file dict_toolbox-2.3.2-py3-none-any.whl.

File metadata

  • Download URL: dict_toolbox-2.3.2-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.9.16

File hashes

Hashes for dict_toolbox-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab56c55c854b61820e1e1e792ad2095f2f1314d311efad629addf8991a380ed5
MD5 195d36169cbd1ded8e15b59dfb574cd7
BLAKE2b-256 01757eab118d60b69767630c3f42e2b8a3bdc4c8aeb6c821f415ab34f6fb2f2d

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