skillfed

multiset

An implementation of a multiset.

multiset v3.2.0 453.1K downloads/30d#6,578 on PyPI39
Permissive license MIT DORMANT released

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 multiset

uv

uv add multiset

poetry

poetry add multiset

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

multiset data structureset with duplicateshashable collection duplicatesunion intersection multisetfrozenset alternativecounter-like set operationsmutable multiset
data-structuresset-operations

More Software Development packages