Skip to main content

mergedeep

PyPi release PyPi versions Downloads Documentation Status

A deep merge function for 🐍.

Check out the mergedeep docs

Installation

$ pip install mergedeep

Usage

merge(target: Map[KT, VT], *sources: Map[KT, VT], strategy: Strategy = Strategy.REPLACE) -> Map[KT, VT]

Deep merge without mutating the source dicts.

from mergedeep import merge

a = {"keyA": 1}
b = {"keyB": {"sub1": 10}}
c = {"keyB": {"sub2": 20}}

merged = merge({}, a, b, c) 

print(merged)
# {"keyA": 1, "keyB": {"sub1": 10, "sub2": 20}}

Deep merge into an existing dict.

from mergedeep import merge

a = {"keyA": 1}
b = {"keyB": {"sub1": 10}}
c = {"keyB": {"sub2": 20}}

merge(a, b, c) 

print(a)
# {"keyA": 1, "keyB": {"sub1": 10, "sub2": 20}}

Merge strategies:

  1. Replace (default)
# Strategy.REPLACE
# When `target` and `source` values are the same, replace the `target` value with one from `source` (default).
# Note: with multiple sources, the `last` source value with be what appears in the merged result. 

from mergedeep import merge, Strategy

target = {"key": [1, 2]}
source = {"key": [3, 4]}

merge(target, source, strategy=Strategy.REPLACE) 
# same as: merge(target, source)

print(target)
# {"key": [3, 4]}
  1. Additive
# Strategy.ADDITIVE
# When `target` and `source` values are both either `list` or `set`, extend/update `target` with values from `source` collection.

from mergedeep import merge, Strategy

target = {"key": [1, 2]}
source = {"key": [3, 4]}

merge(target, source, strategy=Strategy.ADDITIVE) 

print(target)
# {"key": [1, 2, 3, 4]}
  1. Typesafe
# Strategy.TYPESAFE
# When `target` and `source` values are of different types, raise `TypeError`.

from mergedeep import merge, Strategy

target = {"key": [1, 2]}
source = {"key": {3, 4}}

merge(target, source, strategy=Strategy.TYPESAFE) 
# TypeError: target type: <class 'list'> differs from source type: <class 'set'> for key: "key"

License

MIT © Travis Clarke

Metadata

Release files for mergedeep 1.0.2

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

Source distribution (sdist)

Source distribution for mergedeep 1.0.2
File Size Uploaded
mergedeep-1.0.2.tar.gz 3.9 kB Details

Built distribution (wheel)

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

Total release size: 9.2 kB

Release files / mergedeep-1.0.2.tar.gz

Download URL mergedeep-1.0.2.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
542cf4b0361e529113ddf5eb46fbe0b6dca33caed9ad2cad72d79817e693b103
BLAKE2b-256 checksum
How to use checksums
f57374328ffb4c800d368985110e528b32b0275bc8854631791660d191627602
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.2

Release files / mergedeep-1.0.2-py3-none-any.whl

Download URL mergedeep-1.0.2-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99b8f8fe970899ba335cabfc5fa55911119cce5f7b3c4b23489a4ab50f09e438
BLAKE2b-256 checksum
How to use checksums
b8f90539e1d417d6a24b0483bd028f85ae74ece04d9253ffcea4276dc88649ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.2

Release history Release notifications | RSS feed

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.0.3

2 release files

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.0

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