All Projects → clarketm → mergedeep

clarketm / mergedeep

Licence: MIT license
A deep merge function for 🐍.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to mergedeep

deepmerge-ts
Deeply merge 2 or more objects respecting type information.
Stars: ✭ 102 (+39.73%)
Mutual labels:  merge, deepmerge
Mergo
Written by Dario Castañé.
Stars: ✭ 1,808 (+2376.71%)
Mutual labels:  mapping, merge
TreeWalker
PHP JSON diff
Stars: ✭ 58 (-20.55%)
Mutual labels:  merge
leaflet-experiments
Demos and experiments with LeafletJS
Stars: ✭ 20 (-72.6%)
Mutual labels:  mapping
gracidea
🌺 A Pokémon 2D live map gathering all regions, including wandering pokémons and characters and animated tiles!
Stars: ✭ 163 (+123.29%)
Mutual labels:  mapping
Mappable
flexible JSON to Model converter, specially optimized for immutable properties
Stars: ✭ 27 (-63.01%)
Mutual labels:  mapping
esri-experiments
Fly in space and look across the sea: demos and experiments with the ArcGIS API for JavaScript
Stars: ✭ 29 (-60.27%)
Mutual labels:  mapping
geologic-symbols-qgis
Geologic symbols library and development for QGIS
Stars: ✭ 63 (-13.7%)
Mutual labels:  mapping
leafmap
A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment
Stars: ✭ 1,299 (+1679.45%)
Mutual labels:  mapping
GA SLAM
🚀 SLAM for autonomous planetary rovers with global localization
Stars: ✭ 40 (-45.21%)
Mutual labels:  mapping
JSONUtilities
Easily load JSON objects and decode them into structs or classes
Stars: ✭ 57 (-21.92%)
Mutual labels:  mapping
morphmorph
😱 Isomorphic transformations. Map, transform, filter, and morph your objects
Stars: ✭ 26 (-64.38%)
Mutual labels:  mapping
CodableWrapper
@codec("encoder", "decoder") var cool: Bool = true
Stars: ✭ 143 (+95.89%)
Mutual labels:  mapping
data-mapping-component
A React Component which focus on Data-Mapping & Table-Field-Mapping.(基于React的数据/表字段映射组件)
Stars: ✭ 115 (+57.53%)
Mutual labels:  mapping
python-graphslam
Graph SLAM solver in Python
Stars: ✭ 118 (+61.64%)
Mutual labels:  mapping
srtmerger
subtitle merger is a tool for merging two or more subtitles for videos.
Stars: ✭ 35 (-52.05%)
Mutual labels:  merge
solidity-itMapsLib
Iterable maps library for Ethereum Solidity
Stars: ✭ 19 (-73.97%)
Mutual labels:  mapping
demo-oracle-mybatis
No description or website provided.
Stars: ✭ 26 (-64.38%)
Mutual labels:  mapping
slamkit
SLAM Kit
Stars: ✭ 28 (-61.64%)
Mutual labels:  mapping
GMT.jl
Generic Mapping Tools Library Wrapper for Julia
Stars: ✭ 148 (+102.74%)
Mutual labels:  mapping

mergedeep

PyPi release PyPi versions Downloads Conda Version Conda Downloads Documentation Status

A deep merge function for 🐍.

Check out the mergedeep docs

Installation

$ pip install mergedeep

Usage

merge(destination: MutableMapping, *sources: Mapping, strategy: Strategy = Strategy.REPLACE) -> MutableMapping

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 `destination` and `source` keys are the same, replace the `destination` value with one from `source` (default).

# Note: with multiple sources, the `last` (i.e. rightmost) source value will be what appears in the merged result. 

from mergedeep import merge, Strategy

dst = {"key": [1, 2]}
src = {"key": [3, 4]}

merge(dst, src, strategy=Strategy.REPLACE) 
# same as: merge(dst, src)

print(dst)
# {"key": [3, 4]}
  1. Additive

Strategy.ADDITIVE

# When `destination` and `source` values are both the same additive collection type, extend `destination` by adding values from `source`.
# Additive collection types include: `list`, `tuple`, `set`, and `Counter`

# Note: if the values are not additive collections of the same type, then fallback to a `REPLACE` merge.

from mergedeep import merge, Strategy

dst = {"key": [1, 2], "count": Counter({"a": 1, "b": 1})}
src = {"key": [3, 4], "count": Counter({"a": 1, "c": 1})}

merge(dst, src, strategy=Strategy.ADDITIVE) 

print(dst)
# {"key": [1, 2, 3, 4], "count": Counter({"a": 2, "b": 1, "c": 1})}
  1. Typesafe replace

Strategy.TYPESAFE_REPLACE or Strategy.TYPESAFE

# When `destination` and `source` values are of different types, raise `TypeError`. Otherwise, perform a `REPLACE` merge.

from mergedeep import merge, Strategy

dst = {"key": [1, 2]}
src = {"key": {3, 4}}

merge(dst, src, strategy=Strategy.TYPESAFE_REPLACE) # same as: `Strategy.TYPESAFE`  
# TypeError: destination type: <class 'list'> differs from source type: <class 'set'> for key: "key"
  1. Typesafe additive

Strategy.TYPESAFE_ADDITIVE

# When `destination` and `source` values are of different types, raise `TypeError`. Otherwise, perform a `ADDITIVE` merge.

from mergedeep import merge, Strategy

dst = {"key": [1, 2]}
src = {"key": {3, 4}}

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

License

MIT © Travis Clarke

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].