Skip to main content

traverse nested dicts and deal with it

Project description

dict8

features

  • No boilerplate: just a, b, path and some code.

  • Enables you to define a specific merge behavior for every part of the tree.

  • Merge into datclasses or attrs.

internal

The default machinery converts all input data to a Mapper. If a and b are mappable, the new, common and old values are taken to a custom function to decide upon the value precedence. Returning missing will omit this key from the intermediate result. The chosen mapper will decide how to incorporate the latter.

example

import dict8


@dict8.ion
def merge(a, b, path, /, **kv):
    try:
        # try descent into sub mappings
        return merge(
            a,
            b,
            path,
            **kv,
        )
    except dict8.UnMappable:
        # take b else a
        return b if b is not dict8.missing else a


assert (
    merge(
        {
            1: 2,
            3: {4: 5},
        },
        {
            3: {4: 2, 5: 1},
        },
    )
    == {1: 2, 3: {4: 2, 5: 1}}
)

license

This is public domain.

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

dict8-0.0.2.tar.gz (1.9 kB view details)

Uploaded Source

Built Distribution

dict8-0.0.2-py3-none-any.whl (1.8 kB view details)

Uploaded Python 3

File details

Details for the file dict8-0.0.2.tar.gz.

File metadata

  • Download URL: dict8-0.0.2.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for dict8-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2e06fe66eee1372fc68f67aeee502d4490c594e6f14babb950ac19146314a7bc
MD5 4ea02c9d4ee0434940969f3656366775
BLAKE2b-256 6682c3630622cc6e23e11816d79f274b905a7e3c8982fe1dec248f850e83f8ee

See more details on using hashes here.

File details

Details for the file dict8-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dict8-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 1.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for dict8-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0558f9e7b5db7792e24ae5ed70c29ea06845da318ef7e3c5e74e89db042b21b4
MD5 e40811866382f966e162805300ea6a02
BLAKE2b-256 53bdcdd742394f718801cd1be8724e959ccee257433cac0a9118230dc2fc8138

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