Skip to main content

Cython recursive dictionary merging

Project description

Dict merger

Simple Cython+Python library for merge python dictionaries recursively

Usage

from dict_merger.static_merger import merge

a = {1: 2, 2: 3, 3: {1: 1, 2: 3}, 4: 1}
b = {1: 5, 3: {1: 2}, 5: 3}

print(merge(a, b))
# {1: 5, 2: 3, 3: {1: 2, 2: 3}, 4: 1, 5: 3}

API

# dict_merger.static_merger - pure Cython module with static python types
# dict_merger.dynamic_merger - same module, but with dynamic types, works a bit slower

def merge(first_dict: dict, second_dict: dict) -> dict:
    """
    Merge 2 dicts recursively. If more than one given map or object defines the same key or attribute,
    then the one that is later in the argument sequence takes precedence.
    :param first_dict:
    :param second_dict:
    :return:
    """
    ...

def merge_inplace(first_dict: dict, second_dict: dict) -> None:
    """
    Merge 2 dicts recursively. If more than one given map or object defines the same key or attribute,
    then the one that is later in the argument sequence takes precedence.
    First dict will contain merged version
    """
    ...

def merge_many(dicts: List[dict]) -> dict:
    """
    Merge list of dicts. If more than one given map or object defines the same key or attribute,
    then the one that is later in the argument sequence takes precedence.
    :param dicts: list of dicts
    :return: dict
    """
    ...

Installation

# via pypi
pip install dict_merger

# via git
pip install git+https://github.com/TeaDove/dict_merger.git #@branch/tag

# build locally
git clone https://github.com/TeaDove/dict_merger.git #@branch/tag
cd dict_merger
make install

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_merger-0.0.2.tar.gz (99.0 kB view hashes)

Uploaded Source

Built Distribution

dict_merger-0.0.2-cp38-cp38-macosx_10_14_arm64.whl (102.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.14+ ARM64

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