Fully generic MultiDict class
Project description
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/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file multicollections-1.0.8.tar.gz.
File metadata
- Download URL: multicollections-1.0.8.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aaeb7b2c1f4a54a508867935068569229a67f9be33fa93dbc182221e27b6976a
|
|
| MD5 |
1d76795812d26ee0585b79daeb317138
|
|
| BLAKE2b-256 |
1a9ab0993de2190d9dff89f930cba923b1071cd53f8343052bfb97de238a2ae6
|
File details
Details for the file multicollections-1.0.8-py3-none-any.whl.
File metadata
- Download URL: multicollections-1.0.8-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
535e121559e93cb44c50992014bb7790d4cfc04d6c4d01b17a92c9b1edba3794
|
|
| MD5 |
a78df5eab9281ca10bc1676ae0602efa
|
|
| BLAKE2b-256 |
3e714023e325e969c5b592c900bc722ad5bba18060b2e3a00218fb91c0835eca
|