mergedict - A Python dict with a merge() method
A MergeDict is a dict with a merge() method. merge() is like dict.update()…
from mergedict import MergeDict
d1 = MergeDict({'a': 1, 'b': 'one'})
d1.merge({'a':2, 'c': [2]})
assert d1 == {'a': 2, 'c': [2], 'b': 'one'}
A MergeDict can be subclassed to create custom “merge” operations based on the type of an item value.
from mergedict import MergeDict
class SumDict(MergeDict):
@MergeDict.dispatch(int)
def merge_int(this, other):
return this + other
d2 = SumDict({'a': 1, 'b': 'one'})
d2.merge({'a':2, 'b': 'two'})
assert d2 == {'a': 3, 'b': 'two'}
mergedict module comes with a ConfigDict that will extend/update lists/sets/dicts.
from mergedict import ConfigDict
d3 = ConfigDict({'a': 1, 'my_list': [1, 2]})
d3.merge({'a':2, 'my_list': [3, 4]})
assert d3 == {'a': 2, 'my_list': [1, 2, 3, 4]}
Project Details
Project management on github - https://github.com/schettino72/mergedict/
license
The MIT License Copyright (c) 2013 Eduardo Naufel Schettino
see LICENSE file
developers / contributors
Eduardo Naufel Schettino — main author
Sebastian Pipping — build system fixes
install
$ pip install mergedict
or download and:
$ python setup.py install
tests
To run the tests:
$ py.test
Metadata
Release files for mergedict 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mergedict-1.0.0.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mergedict-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / mergedict-1.0.0.tar.gz
| Download URL | mergedict-1.0.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1992b36a54229014fbcbc7a9c8c28d1f4ae131ea1d8d345c93973f9f0dc6fdc
|
|
BLAKE2b-256 checksum How to use checksums |
aaf227542b17a2f3d0b15957684467b9617a518caaf340c5ab86b8e8023945e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.10
|
Release files / mergedict-1.0.0-py3-none-any.whl
| Download URL | mergedict-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0eeede3d2119a002f96d56a6f7617dd2d80e225926809403d54e8c811eca22d
|
|
BLAKE2b-256 checksum How to use checksums |
b4f298a8757575ae9eb2d2ac8a7dbced7da3214f394b4c7f0716abc8e3292569
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.6.10
|