Install & Compatibility
Where this runs
tested against v4.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.114s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.108s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Munch
✓ from munch import Munch
DefaultMunch
✓ from munch import DefaultMunch
DefaultFactoryMunch
✓ from munch import DefaultFactoryMunch
RecursiveMunch
✓ from munch import RecursiveMunch
munchify
✓ from munch import munchify
✗ from munch import Munchify
The conversion function is `munchify` (lowercase), not `Munchify`.
unmunchify
✓ from munch import unmunchify
✗ from munch import Unmunchify
The conversion function is `unmunchify` (lowercase), not `Unmunchify`.
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.
from munch import Munch, munchify, DefaultMunch
# 1. Basic Munch object
data = Munch()
data.name = "Alice"
data.age = 30
print(f"Name: {data.name}, Age: {data.age}")
# Munch supports dictionary-style access too
data['city'] = 'New York'
print(f"City: {data.city}")
# 2. Initializing from a dictionary (shallow conversion)
regular_dict = {'user': {'id': 101, 'status': 'active'}}
m_shallow = Munch(regular_dict)
print(f"Type of nested 'user' in shallow Munch: {type(m_shallow.user)}") # Will be <class 'dict'>
# 3. Recursive conversion using munchify()
m_deep = munchify(regular_dict)
print(f"Type of nested 'user' in deep Munch: {type(m_deep.user)}") # Will be <class 'munch.Munch'>
print(f"User ID: {m_deep.user.id}")
# 4. DefaultMunch for default values
default_munch = DefaultMunch(0)
default_munch.count = 5
print(f"Existing count: {default_munch.count}") # Output: Existing count: 5
print(f"Non-existent value: {default_munch.non_existent}") # Output: Non-existent value: 0
Debug
Known issues
breakingVersion 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.fixEnsure your project uses Python 3.6 or a later compatible version.
affects: >=3.0.0
breakingIn 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`.fixReview project dependencies; if `pkg_resources` was an indirect dependency, ensure it's explicitly listed if still needed for other parts of your application.
affects: >=3.0.0
breakingVersion 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`.fixIf your project relies on `six` for Python 2/3 compatibility, ensure it is an explicit dependency in your `requirements.txt`.
affects: >=4.0.0
gotchaThe `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.fixFor deep conversion of nested dictionaries, always use `munchify(your_dict)` instead of `Munch(your_dict)`.
affects: All versions
gotchaWhen `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.fixTo 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.
affects: All versions with PyYAML installed
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'munch'
The 'munch' package is not installed in your current Python environment.
AttributeError: 'Munch' object has no attribute 'some_key'
You are attempting to access an attribute (key) that does not exist on the 'Munch' object, or there is a typo in the attribute name.
fixVerify the attribute name is correct and exists in the Munch object. You can use `munch_object.get('some_key', default_value)` for safe access to potentially missing keys. AttributeError: 'dict' object has no attribute 'some_key'
This often occurs after deserializing a JSON string (e.g., using `json.loads`), which converts a 'Munch' object back into a standard Python 'dict', thereby losing its dot-accessible attributes.
fixConvert the deserialized dictionary back into a 'Munch' object using `Munch.fromDict(your_dict)` or `munchify(your_dict)` from the munch library.
TypeError: 'Munch' object is not callable
You are attempting to call a 'Munch' object or one of its attributes as if it were a function, but the object or attribute is not a callable type (e.g., it's a string, int, or another Munch instance).
fixEnsure you are accessing attributes correctly (e.g., `munch_object.attribute_name` for values) and not trying to invoke them as functions unless they are actual methods or callable objects.
Upgrade
Version history
4.0.0latest on PyPI · released Jul 1, 2023
Audit
Dependencies
PyYAMLoptionalOptional dependency for YAML serialization/deserialization methods (toYAML, fromYAML).