DeepMerge
A lightweight python package for performing deep-merges of python dictionaries
Installation
Install this package with pip!
$ pip install pydeepmerge
To install this package from source, clone the repo and run:
$ pip install .
If you would like to develop, remember to install the extras.
# for bash
$ pip install -e .[test,dev]
# for zsh
$ pip install -e .\[test,dev\]
Usage
Usage is simple:
from pydeepmerge import deep_merge
> some_data = {'foo': {'bar': 'baz', 'spam': 'eggs'}, 'ham': 'eggs'}
> more_data = {'spam': {'eggs': 'ham'}, 'foo': {'baz': 'bar', 'bar': 'foo'}}
> deep_merge(some_data, more_data)
{'foo': {'bar': 'foo', 'baz': 'bar', 'spam': 'eggs'}, 'spam': {'eggs': 'ham'}, 'ham': 'eggs'}
pydeepmerge also allows users to specify their own merge strategy function. By default, it uses the function prefer_right.
A merge strategy is any function that can accept exactly two inputs. The output of the merge strategy function should be what the merge result between two values should be.
When writing your own merge strategy function, keep in mind that if the key does not exist on the left-hand mapping, the value Key.NoKeyFound will be passed to the first parameter of the function. This is done deliberately so the user can determine if they want to do special behaviour if it is the first occurrence of the key in the sequence of dictionaries.
An example of a merge strategy function can be found below:
from pydeepmerge import deep_merge
from pydeepmerge.types import Key
from typing import Mapping
def pick_shallower(left_value, right_value):
if left_value is Key.NoKeyFound:
return right_value
if isinstance(right_value, Mapping):
if not isinstance(left_value, Mapping):
return left_value
return deep_merge(left_value, right_value)
return right_value
The deep_merge function does not mutate any mapping but instead creates a new dictionary.
Metadata
Release files for pydeepmerge 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pydeepmerge-0.3.3.tar.gz | 6.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydeepmerge-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.8 kB
Release files / pydeepmerge-0.3.3.tar.gz
| Download URL | pydeepmerge-0.3.3.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8db9935b666b92baebdae53eaffb0be3c775f68df21c2cb86bbbafb3cbbb970
|
|
BLAKE2b-256 checksum How to use checksums |
895b55b6eab1f2f14b07f62dd1f2e1f14eaa5d515afadf51c7f0468c90b00a4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10
|
Release files / pydeepmerge-0.3.3-py3-none-any.whl
| Download URL | pydeepmerge-0.3.3-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e570fe4422a4448d21919c086f27d249dc8330684737160c02f5f35ba862ed90
|
|
BLAKE2b-256 checksum How to use checksums |
15fdc3c86a5d14cfd17b47e0ba24afb398c61f4519672d22a435ba586fd974a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.7.10
|
Security for pydeepmerge 0.3.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.