Ordered Multivalue Dictionary
orderedmultidict is a Python library that provides an `omdict` class, an ordered multivalue dictionary. It retains the insertion order of both keys and their associated values, and aims for method parity with Python's built-in `dict`. The library is known for powering `furl` and supports both Python 2 and Python 3 environments. The current version is 1.0.2, with the last release dating back to 2019, indicating an infrequent release cadence.
Warnings
- gotcha The `orderedmultidict` library has not seen updates since its 1.0.2 release in July 2019. This means it may not be compatible with newer Python versions beyond 3.9 (as listed on PyPI) and is unlikely to receive bug fixes or new features, potentially leading to compatibility issues or unaddressed vulnerabilities in modern environments.
- gotcha Performance of `orderedmultidict` (omdict) can be significantly slower compared to more optimized alternatives, especially for operations like initialization and iteration over items. Benchmarks suggest an order of magnitude difference in some cases.
- gotcha Since Python 3.7, built-in `dict` objects officially preserve insertion order for keys. While `orderedmultidict` provides additional functionality for multiple values per key and preserves the order of *individual values* as well, the 'ordered' aspect for single-value entries is less unique than it once was.
Install
-
pip install orderedmultidict
Imports
- omdict
from orderedmultidict import omdict
Quickstart
from orderedmultidict import omdict # Create an empty ordered multivalue dictionary omd = omdict() # Add values for keys omd[1] = 'apple' omd.add(2, 'banana') omd.add(1, 'apricot') # Add another value for key 1 # Access values print(omd[1]) # Accesses the first value for key 1: 'apple' print(omd.getlist(1)) # Gets all values for key 1: ['apple', 'apricot'] # See insertion order print(list(omd.keys())) # Keys in insertion order: [1, 2, 1] print(list(omd.items())) # Items in insertion order: [(1, 'apple'), (2, 'banana'), (1, 'apricot')]