multidict¶
Multidicts are useful for working with HTTP headers, URL query args etc.
The code was extracted from aiohttp library.
Introduction¶
HTTP Headers and URL query string require specific data structure:
multidict. It behaves mostly like a regular dict but it may have
several values for the same key and preserves insertion ordering.
The key is str (or istr for case-insensitive
dictionaries).
multidict has four multidict classes:
MultiDict, MultiDictProxy,
CIMultiDict and CIMultiDictProxy.
Immutable proxies (MultiDictProxy and
CIMultiDictProxy) provide a dynamic view for the
proxied multidict, the view reflects underlying collection changes. They
implement the Mapping interface.
Regular mutable (MultiDict and
CIMultiDict) classes implement
MutableMapping and allows to change
their own content.
Case insensitive (CIMultiDict and
CIMultiDictProxy) ones assume the keys
are case insensitive, e.g.:
>>> dct = CIMultiDict(key='val')
>>> 'Key' in dct
True
>>> dct['Key']
'val'
Keys should be either str or istr
instance.
The library has optional C Extensions for sake of speed.
Other C extensions can build against multidict’s own C API to create and manipulate multidicts directly, or from Cython.
Both the C extension and the pure-Python fallback are optimized for
free-threaded (no-GIL) Python as well as the regular GIL build, and their
performance is in the same ballpark as the built-in dict, typically
within 20-30% for common operations, since dict itself benefits
from per-version interpreter specializations that a third-party type cannot
hook into. See Benchmarks for the full per-operation breakdown of the
C extension on both builds, and the free-threading overhead figures for the
pure-Python fallback.
Library Installation¶
$ pip install multidict
The library is Python 3 only!
PyPI contains binary wheels for Linux, Windows and MacOS. If you want to install
multidict on another operation system (or Alpine Linux inside a Docker) the
Tarball will be used to compile the library from sources. It requires C compiler and
Python headers installed.
To skip the compilation please use the MULTIDICT_NO_EXTENSIONS
environment variable, e.g.:
$ MULTIDICT_NO_EXTENSIONS=1 pip install multidict
Please note, the pure Python (uncompiled) version is dramatically slower: the
pure-Python backend table in Benchmarks measures it at about 40 times
more instructions than the C extension, averaged over the measured operations.
Unless the target platform genuinely cannot build the C extension, leave
MULTIDICT_NO_EXTENSIONS unset and let it compile.
Source code¶
The project is hosted on GitHub
Please file an issue on the bug tracker if you have found a bug or have some suggestion in order to improve the library.
Contents¶
- Reference
- MultiDict
MultiDictMultiDict.len()MultiDict.d()MultiDict.iter()MultiDict.add()MultiDict.clear()MultiDict.copy()MultiDict.to_dict()MultiDict.getone()MultiDict.getall()MultiDict.get()MultiDict.keys()MultiDict.items()MultiDict.values()MultiDict.popone()MultiDict.pop()MultiDict.popall()MultiDict.popitem()MultiDict.setdefault()MultiDict.extend()MultiDict.merge()MultiDict.update()
- CIMultiDict
- MultiDictProxy
- CIMultiDictProxy
- Version
- istr
- Abstract Base Classes
- Typing
- Environment variables
- MultiDict
- C API
- Cython API
- Benchmarks
- Changelog
- 7.1.0
- 7.0.0
- 6.9.1
- 6.9.0
- 6.8.0
- 6.7.1
- 6.7.0
- 6.6.4
- 6.6.3
- 6.6.2
- 6.6.1
- 6.6.0
- 6.5.1
- 6.5.0
- 6.4.4
- 6.4.3
- 6.4.2
- 6.4.1
- 6.4.0
- 6.3.2
- 6.3.1
- 6.3.0
- 6.2.0
- 6.1.0 (2024-09-09)
- 6.0.5 (2024-02-01)
- 6.0.4 (2022-12-24)
- 6.0.3 (2022-12-03)
- 6.0.2 (2022-01-24)
- 6.0.1 (2022-01-23)
- 6.0.0 (2022-01-22)
- 5.2.0 (2021-10-03)
- 5.1.0 (2020-12-03)
- 5.0.1 (2020-11-14)
- 5.0.0 (2020-10-12)
- Features
- Removal
- Misc
- 4.7.6 (2020-05-15)
- 4.7.5 (2020-02-21)
- 4.7.4 (2020-01-11)
- Multidict 4.7.3 (2019-12-30)
- 4.7.2 (2019-12-20)
- 4.7.1 (2019-12-12)
- 4.7.0 (2019-12-10)
- 4.6.1 (2019-11-21)
- 4.6.0 (2019-11-20)
- 4.5.2 (2018-11-28)
- 4.5.1 (2018-11-22)
- 4.5.0 (2018-11-19)
- 4.4.2 (2018-09-19)
- 4.4.1 (2018-09-17)
- 4.4.0 (2018-07-04)
- 4.3.1 (2018-05-06)
- 4.3.0 (2018-05-06)
- 4.2.0 (2018-04-15)
- 4.1.0 (2018-01-28)
- 4.0.0 (2018-01-14)
- 3.3.2 (2017-11-02)
- 3.3.1 (2017-11-01)
- 3.3.0 (2017-10-15)
- 3.2.0 (2017-09-17)
- 3.1.3 (2017-07-14)
- 3.1.2 (2017-07-14)
- 3.1.1 (2017-07-09)
- 3.1.0 (2017-06-25)
- 3.0.0 (2017-06-21)
- 2.1.7 (2017-05-29)
- 2.1.6 (2017-05-27)
- 2.1.5 (2017-05-13)
- 2.1.4 (2016-12-1)
- 2.1.3 (2016-11-26)
- 2.1.2 (2016-09-25)
- 2.1.1 (2016-09-22)
- 2.1.0 (2016-09-18)
- 2.0.1 (2016-08-02)
- 2.0.0 (2016-07-28)
- 1.2.2 (2016-08-02)
- 1.2.1 (2016-07-21)
- 1.2.0 (2016-07-16)
- 1.1.0 (2016-07-06)
- 1.0.3 (2016-03-24)
- 1.0.2 (2016-03-24)
- 1.0.0 (2016-02-19)