{"id":1847,"library":"munch","title":"Munch","description":"Munch is a Python library providing a dot-accessible dictionary, similar to JavaScript objects. It's a widely used package in the Python ecosystem for handling configuration and data with intuitive attribute-style access. Actively maintained, it currently stands at version 4.0.0 with a steady release cadence.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"https://github.com/Infinidat/munch","tags":["dictionary","dot-notation","javascript-like","config","serialization","data-structure"],"install":[{"cmd":"pip install munch","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Optional dependency for YAML serialization/deserialization methods (toYAML, fromYAML).","package":"PyYAML","optional":true}],"imports":[{"symbol":"Munch","correct":"from munch import Munch"},{"symbol":"DefaultMunch","correct":"from munch import DefaultMunch"},{"symbol":"DefaultFactoryMunch","correct":"from munch import DefaultFactoryMunch"},{"symbol":"RecursiveMunch","correct":"from munch import RecursiveMunch"},{"note":"The conversion function is `munchify` (lowercase), not `Munchify`.","wrong":"from munch import Munchify","symbol":"munchify","correct":"from munch import munchify"},{"note":"The conversion function is `unmunchify` (lowercase), not `Unmunchify`.","wrong":"from munch import Unmunchify","symbol":"unmunchify","correct":"from munch import unmunchify"}],"quickstart":{"code":"from munch import Munch, munchify, DefaultMunch\n\n# 1. Basic Munch object\ndata = Munch()\ndata.name = \"Alice\"\ndata.age = 30\nprint(f\"Name: {data.name}, Age: {data.age}\")\n\n# Munch supports dictionary-style access too\ndata['city'] = 'New York'\nprint(f\"City: {data.city}\")\n\n# 2. Initializing from a dictionary (shallow conversion)\nregular_dict = {'user': {'id': 101, 'status': 'active'}}\nm_shallow = Munch(regular_dict)\nprint(f\"Type of nested 'user' in shallow Munch: {type(m_shallow.user)}\") # Will be <class 'dict'>\n\n# 3. Recursive conversion using munchify()\nm_deep = munchify(regular_dict)\nprint(f\"Type of nested 'user' in deep Munch: {type(m_deep.user)}\") # Will be <class 'munch.Munch'>\nprint(f\"User ID: {m_deep.user.id}\")\n\n# 4. DefaultMunch for default values\ndefault_munch = DefaultMunch(0)\ndefault_munch.count = 5\nprint(f\"Existing count: {default_munch.count}\") # Output: Existing count: 5\nprint(f\"Non-existent value: {default_munch.non_existent}\") # Output: Non-existent value: 0\n","lang":"python","description":"This quickstart demonstrates how to create a basic `Munch` object, initialize it from a dictionary (highlighting the shallow nature of the constructor versus the recursive `munchify` function), and use `DefaultMunch` for handling missing attributes gracefully."},"warnings":[{"fix":"Ensure your project uses Python 3.6 or a later compatible version.","message":"Version 3.0.0 introduced a breaking change requiring Python 3.6 or newer. Older Python versions (Python 2.7 and early Python 3) are no longer supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Review project dependencies; if `pkg_resources` was an indirect dependency, ensure it's explicitly listed if still needed for other parts of your application.","message":"In version 3.0.0, the internal mechanism for version retrieval switched from `pkg_resources` to `importlib.metadata`. While primarily an internal change, this could affect projects that had implicit dependencies on `pkg_resources` being available via `munch`.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"If your project relies on `six` for Python 2/3 compatibility, ensure it is an explicit dependency in your `requirements.txt`.","message":"Version 4.0.0 removed the `six` compatibility library dependency. This change is unlikely to affect most direct users, but it means `six` is no longer implicitly installed or available through `munch`.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"For deep conversion of nested dictionaries, always use `munchify(your_dict)` instead of `Munch(your_dict)`.","message":"The `Munch()` constructor performs only a shallow conversion of nested dictionaries. If you initialize a `Munch` with a dictionary containing other dictionaries, those nested dictionaries will remain standard `dict` objects and not become `Munch` objects themselves. To achieve recursive conversion, use the `munchify()` function.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To load YAML containing these tags, use `Munch.fromYAML()`. To dump `Munch` objects to YAML without these tags, convert them to plain dictionaries recursively using `unmunchify()` before dumping, or configure PyYAML's representers to override the default behavior.","message":"When `PyYAML` is installed, `Munch` objects automatically register themselves with YAML representers. This can lead to `!munch.Munch` tags appearing in YAML output, which might not be desired for cross-language compatibility or readability.","severity":"gotcha","affected_versions":"All versions with PyYAML installed"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}