multiset
An implementation of a multiset.
What it is and what it does
Multiset is a data structure that extends Python's built-in set to allow elements to appear multiple times. Like a set, it requires elements to be hashable and supports the same operations—membership tests, union, intersection, symmetric difference—but tracks how many times each element occurs. The package provides both a mutable Multiset class and an immutable FrozenMultiset (similar to frozenset) that is also hashable.
Unlike collections.Counter from the standard library, multiset enforces proper set semantics: it only allows positive counts, automatically removes elements with zero multiplicity, and supports all standard set operations without treating the collection as a frequency counter. The implementation uses a dictionary internally to map elements to their counts, making it suitable for algorithms that need set operations on collections with duplicates.
Use it for:
- Counting occurrences of hashable items while performing set operations like union or intersection
- Implementing algorithms that require multiset semantics (e.g., graph theory, combinatorics) where duplicate membership matters
- Using multisets as dictionary keys or in sets by wrapping them in FrozenMultiset for immutability and hashability
- Comparing collections where element frequency and set relationships both matter (e.g., checking if one multiset is a sub-multiset of another)
- Replacing ad-hoc Counter-based logic when you need proper set operations rather than frequency counting
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a mutable and immutable multiset data structure that extends Python's set semantics to allow duplicate elements, supporting set operations like union, intersection, and difference.
Yes, if you need set operations on collections with duplicates. The package is stable, has zero dependencies, and installs easily. However, maintenance is dormant (last release 717 days ago), so consider whether you need active support or can rely on a mature, unchanging implementation. For simple frequency counting, collections.Counter may be sufficient; reach for multiset when you specifically need set semantics with duplicates.
Install
multiset on PyPI
pip
pip install multisetuv
uv add multisetpoetry
poetry add multisetInstalling multiset
Before you install
Low friction: pure Python wheel with no runtime dependencies. Maintenance is dormant—last release was 717 days ago—but the repository is not archived and the package is marked Production/Stable with support for current Python versions (3.8 through 3.12).
License in practice
MIT license (permissive) imposes no restrictions on use, modification, or redistribution in proprietary or open-source projects.
Quickstart
from multiset import Multiset, FrozenMultiset
set1 = Multiset('aab')
set2 = Multiset('abc')
result = sorted(set1 | set2) # ['a', 'a', 'b', 'c']
frozen = FrozenMultiset('abc')
hash(frozen) # hashable
Requires Python 3.8 or later.
Verify before relying
- Performance characteristics compared to collections.Counter or repeated set operations for large datasets
- Whether the API is fully stable or if breaking changes are possible despite dormant maintenance status
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 717 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 453,051/month — #6,578 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: multiset-3.2.0-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
collections-extendedProvides four specialized collection types—bag…
permissive · top 15,000 on PyPI
orderly-setProvides multiple ordered set implementations…
permissive · top 1,000 on PyPI
immutablesProvides an immutable mapping type backed by a…
permissive · top 5,000 on PyPI
frozenlistProvides a list-like container that starts…
permissive · top 100 on PyPI
frozendictProvides an immutable, hashable dictionary…
copyleft · top 5,000 on PyPI
ordered-setOrderedSet is a mutable collection that…
permissive · top 1,000 on PyPI
portionportion provides data structures and operations…
copyleft · top 5,000 on PyPI
pyrsistentPyrsistent provides immutable, persistent data…
permissive · top 1,000 on PyPI
permutationProvides a Permutation class for representing…
permissive · top 15,000 on PyPI
HeapDictHeapDict is a mutable mapping that acts as a…
permissive · top 15,000 on PyPI