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.3.tar.gz (12.1 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.3-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: multicollections-1.1.3.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for multicollections-1.1.3.tar.gz
Algorithm Hash digest
SHA256 b7a2e48744b7e55c9d5cd168444e2f201d179c652bf5030393e7d7903f6bf2d8
MD5 2b235cae35ed74f54d8171d986ee1fce
BLAKE2b-256 9c573a94d8d877659b24ff86ea458a60ecc1c6ee3719a4a9682034101c5dcca0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: multicollections-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for multicollections-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d90fce9ac25b77ddf88eb0bb594d0c597c3e0175611e4b4613240aedccdd380a
MD5 5df202f57ea4b2d157170018a5fe9b3b
BLAKE2b-256 791fed7cf9c2dea52bc0b6d772d988253c8d4b19ec2a8d1abc4a01842b6df9f0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 files

1.1.2

2 files

1.1.1

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