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/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multicollections-1.1.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

multicollections-1.1.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file multicollections-1.1.1.tar.gz.

File metadata

  • Download URL: multicollections-1.1.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","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

Hashes for multicollections-1.1.1.tar.gz
Algorithm Hash digest
SHA256 30d3706d08435e772007af902bae744ba3136a6f7b97eb358cb2512d070f880e
MD5 7fec85560e033b248a3da5501073e0a4
BLAKE2b-256 8890a57e077a03325b49a57855ec7f8f870495a67aa714304af5706893260081

See more details on using hashes here.

File details

Details for the file multicollections-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: multicollections-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","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

Hashes for multicollections-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da15d38623145318f884400de42e35506fd639b15bb9d8e851d227f161f0cd1f
MD5 36429dfff2025989af46520870e82ded
BLAKE2b-256 038a143199730f71641f1923148001da87ae38120aa80495a82f57501ae000e3

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.3

2 files

1.1.2

2 files

This release

1.1.1 This release

2 files

1.1.0

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page