multidict is a mapping implementation that allows multiple values per key, mirroring the semantics of HTTP headers and query strings. It provides four concrete classes — MultiDict (mutable), MultiDictProxy (immutable view), CIMultiDict (case-insensitive mutable), and CIMultiDictProxy (case-insensitive immutable view) — plus the istr helper for pre-folded string keys. Current version is 6.7.1 (released January 2026). The library ships an optional C extension; release cadence is frequent patch releases with periodic minor releases adding features such as the new merge() method (6.6.0) and a hash-table backend replacing the previous O(N) array (6.5.0).
pip install multidictVerified import paths — ran on the pinned version, not inferred.
Demonstrates mutable MultiDict with duplicate keys, getall, add, and a case-insensitive CIMultiDict.
Replace d['key'] with d.getall('key') when multiple values per key are expected.Use d.add(key, value) to append a value while preserving existing entries for the same key.
Upgrade to >=6.5.1 which fixes a resize-with-deleted-slots bug introduced in 6.5.0. Treat key iteration order as insertion-order stable but do not assume slot density.
Wrap the source mapping in MultiDict() first: MultiDictProxy(MultiDict(plain_dict)).
Do not set MULTIDICT_NO_EXTENSIONS in production. For Alpine Linux / source builds without a C compiler, the pure-Python wheel is automatically used as a fallback starting with 6.x.
Always import from the top-level package: from multidict import MultiDict, CIMultiDict, ...
Use str(key) if you need a plain str, or compare with == rather than 'is'. istr is a subclass of str so equality checks work normally.
For case-insensitive key access, use `CIMultiDict` instead of `MultiDict`. Ensure the object `ci` is an instance of `CIMultiDict` if you expect `assert 'content-type' in ci` to pass when only 'Content-Type' is present.
Install the package using pip: `pip install multidict` or `python -m pip install multidict`.
Ensure you have a C compiler (e.g., Build Tools for Visual Studio on Windows, or `build-essential` on Debian/Ubuntu) and Python development headers installed. Alternatively, you can force the installation of the pure-Python version (which will be slower) using the environment variable: `MULTIDICT_NO_EXTENSIONS=1 pip install multidict`.
Use the `.get()` method, which returns `None` or a specified default value if the key is not found, or check for key existence with `if 'key' in d:` before accessing. To get all values for a key, use `.getall('key')`.Replace `d.iteritems()` with `d.items()`, `d.iterkeys()` with `d.keys()`, and `d.itervalues()` with `d.values()`. These methods return view objects in Python 3, which behave similarly to iterators for looping.
If you need to serialize the data, convert the proxy object to a mutable `CIMultiDict` or a standard dictionary first. For example, `import pickle; dct = multidict.CIMultiDict(original_proxy); pickled_dct = pickle.dumps(dct)` or `pickled_dict = pickle.dumps(dict(original_proxy))`.
No dependency data recorded yet.