Skip to main content

multicollections

A fully generic MultiDict class that allows multiple values for the same key while preserving insertion order.

Documentation CI Codecov Ruff ty uv Publish PyPI PyPI - Python Version

✨ 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 multidict API
  • 📐 Abstract base classes: The multicollections.abc module 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 Accept or Set-Cookie headers
  • 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)

Source distribution for multicollections 1.1.4
File Size Uploaded
multicollections-1.1.4.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for multicollections 1.1.4
File Interpreter ABI Platform
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}

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

This release

1.1.4 This release

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page