• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A deep merging tool for Python core data structures

deepmerge

A tools to handle merging of nested data structures in python.

Installation

deepmerge is available on pypi:

pip install deepmerge

Example

Generic Strategy

from deepmerge import always_merger

base = {"foo": ["bar"]}
next = {"foo": ["baz"]}

expected_result = {'foo': ['bar', 'baz']}
result = always_merger.merge(base, next)

assert expected_result == result

Custom Strategy

from deepmerge import Merger

my_merger = Merger(
    # pass in a list of tuple, with the
    # strategies you are looking to apply
    # to each type.
    [
        (list, ["append"]),
        (dict, ["merge"]),
        (set, ["union"])
    ],
    # next, choose the fallback strategies,
    # applied to all other types:
    ["override"],
    # finally, choose the strategies in
    # the case where the types conflict:
    ["override"]
)
base = {"foo": ["bar"]}
next = {"bar": "baz"}
my_merger.merge(base, next)
assert base == {"foo": ["bar"], "bar": "baz"}

You can also pass in your own merge functions, instead of a string.

For more information, see the docs

More Repositories

1

transmute-core

A web framework-agnostic API and documentation generation platform
Python
38
star
2

tome

convert any directory of scripts into your own fully-featured command.
Rust
35
star
3

nlgen

Natural Language Generator for Python
Python
27
star
4

jsonschema-extractor

Extract jsonschema from various Python objects
Python
26
star
5

uranium

Uranium: a build system for python, in python.
Python
23
star
6

aiohttp-transmute

A transmute implementation for aiohttp
Python
14
star
7

go-snippets

yasnippet snippets for Go
Emacs Lisp
13
star
8

yt.rc

My RC Files, sprinter configuration, etc.
Emacs Lisp
11
star
9

flask-transmute

a flask extension that generates APIs from python function and classes.
Python
7
star
10

sprinter

A cross-platform environment bootstrapping framework
Python
6
star
11

surgen

A tool to help perform automated upgrades to codebases
Python
5
star
12

toumorokoshi.github.com

Toumorokoshi's github pages.
SCSS
4
star
13

yelo

an elo rating webservice
Python
3
star
14

disp

A lisp-based programming language, focusing on performance and powerful expressions
Rust
3
star
15

greyhawk-language

A language spec for fun.
C++
3
star
16

greyhound-search

An indexing and file web application
CSS
2
star
17

go-fuzzy

A fuzzy string matching library for go
Go
2
star
18

swagger-schema

An object-oriented representation of Swagger for Python.
Python
2
star
19

ytlaces

shoelaces for myself
Lua
2
star
20

codersguide

A Coder's Guide to ... Something
2
star
21

atom-chimera

An editor built on atom, splicing the best DNA of multiple text editors
JavaScript
1
star
22

emacs-from-scratch

emacs-from-scratch tutorial files
Emacs Lisp
1
star
23

vcver-python

Reference Implementation of vcver (WIP)
Python
1
star
24

garage

A place to put and get your shell scripts
Go
1
star
25

yt.recipe.shell

Recipe to add shell commands as entry points
Python
1
star
26

yt.finance

A library of finance tools written in python
Python
1
star
27

cheatsheets

My Cheatsheets
Python
1
star
28

miura

A Jenkins Job Generation Tool
Python
1
star
29

pelican-export

A pelican plugin to export posts to systems like wordpress
Python
1
star
30

ax_check_mysql

An autoconf macro for Checking existence of MySQL installs and plugin compability
1
star