multicollections
A fully generic MultiDict class that allows multiple values for the same key while preserving insertion order.
✨ Features
- 🔑 Multiple values per key: Store multiple values for the same key, perfect for handling data like HTTP headers, form data, or configuration files
- 📝 Insertion order preserved: Maintains the order in which items are added
- 🧩 Fully generic: Accepts any types for both keys and values
- ✅ Thoroughly tested: 100% code coverage
- ⚡ Type-safe: Fully typed with generics
- 🪶 Lightweight: Zero dependencies, pure Python implementation
- 🎯 Rich, compatible API: Implements the
multidictAPI - 📐 Abstract base classes: The
multicollections.abcmodule provides a common interface for other custom multi-value collections
📦 Installation
pip
pip install multicollections
conda
conda install -c conda-forge multicollections
🚀 Quick Start
from multicollections import MultiDict
# Create a MultiDict with duplicate keys
headers = MultiDict(
[
("Accept", "text/html"),
("Accept-Encoding", "gzip"),
("Accept", "application/json"), # Same key, different value
("User-Agent", "MyApp/1.0"),
]
)
# Access the first value for a key
print(headers["Accept"]) # 'text/html'
# Get ALL values for a key
print(headers.getall("Accept")) # ['text/html', 'application/json']
# See all key-value pairs (duplicates preserved)
print(list(headers.items()))
# [('Accept', 'text/html'), ('Accept-Encoding', 'gzip'),
# ('Accept', 'application/json'), ('User-Agent', 'MyApp/1.0')]
# Add more values for existing keys
headers.add("Accept", "text/xml")
print(headers.getall("Accept")) # ['text/html', 'application/json', 'text/xml']
print(len(headers)) # 5 items total
# Remove and return the first value
first_accept = headers.popone("Accept")
print(first_accept) # 'text/html'
print(headers.getall("Accept")) # ['application/json', 'text/xml']
# Remove and return all values for a key
all_accepts = headers.popall("Accept")
print(all_accepts) # ['application/json', 'text/xml']
print("Accept" in headers) # False
# Create from keyword arguments
config = MultiDict(host="localhost", port=8080, debug=True)
# Mix iterable and keyword arguments
mixed = MultiDict([("a", 1), ("b", 2)], c=3, d=4)
📖 Why MultiDict?
Standard Python dictionaries can only hold one value per key. When you need to handle data formats that naturally allow multiple values for the same key, MultiDict is the perfect solution:
- HTTP headers: Multiple
AcceptorSet-Cookieheaders - URL query parameters:
?tag=python&tag=web&tag=api - Form data: Multiple form fields with the same name
- Configuration files: Multiple values for the same configuration key
As opposed to the popular multidict package, multicollections's MultiDict implementation allows both keys and values to be of any type, providing greater flexibility.
🔗 Documentation
For detailed documentation, examples, and API reference, visit: https://multicollections.readthedocs.io/
Metadata
Release files for multicollections 1.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| multicollections-1.1.4.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| multicollections-1.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.5 kB
Release files / multicollections-1.1.4.tar.gz
| Download URL | multicollections-1.1.4.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b84903dca51172aed1459d356ad8ed3cb1b1b51ac583d65429699f741470b105
|
|
BLAKE2b-256 checksum How to use checksums |
e7581c7507d30712d45a916968b640009d64cd664f8b58d172772e9aac606f38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / multicollections-1.1.4-py3-none-any.whl
| Download URL | multicollections-1.1.4-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8307d14df229a867831c74e0084825b6bdfb5a4337a6da59998a2e13fdee5f5
|
|
BLAKE2b-256 checksum How to use checksums |
5872f46e9e69ad7317671b85c7821f1678f66c71d69cdace24a6325a6d87b611
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|