METADATA 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Metadata-Version: 2.1
  2. Name: deepmerge
  3. Version: 1.1.1
  4. Summary: a toolset to deeply merge python dictionaries.
  5. Home-page: http://deepmerge.readthedocs.io/en/latest/
  6. Classifier: Development Status :: 5 - Production/Stable
  7. Classifier: License :: OSI Approved :: MIT License
  8. Classifier: Programming Language :: Python :: 3
  9. License-File: LICENSE
  10. =========
  11. deepmerge
  12. =========
  13. .. image:: https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml/badge.svg
  14. :target: https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml
  15. A tools to handle merging of
  16. nested data structures in python.
  17. ------------
  18. Installation
  19. ------------
  20. deepmerge is available on `pypi <https://pypi.python.org/>`_:
  21. .. code-block:: bash
  22. pip install deepmerge
  23. -------
  24. Example
  25. -------
  26. **Generic Strategy**
  27. .. code-block:: python
  28. from deepmerge import always_merger
  29. base = {"foo": ["bar"]}
  30. next = {"foo": ["baz"]}
  31. expected_result = {'foo': ['bar', 'baz']}
  32. result = always_merger.merge(base, next)
  33. assert expected_result == result
  34. **Custom Strategy**
  35. .. code-block:: python
  36. from deepmerge import Merger
  37. my_merger = Merger(
  38. # pass in a list of tuple, with the
  39. # strategies you are looking to apply
  40. # to each type.
  41. [
  42. (list, ["append"]),
  43. (dict, ["merge"]),
  44. (set, ["union"])
  45. ],
  46. # next, choose the fallback strategies,
  47. # applied to all other types:
  48. ["override"],
  49. # finally, choose the strategies in
  50. # the case where the types conflict:
  51. ["override"]
  52. )
  53. base = {"foo": ["bar"]}
  54. next = {"bar": "baz"}
  55. my_merger.merge(base, next)
  56. assert base == {"foo": ["bar"], "bar": "baz"}
  57. You can also pass in your own merge functions, instead of a string.
  58. For more information, see the `docs <https://deepmerge.readthedocs.io/en/latest/>`_