skillfed

constantdict

An immutable dict class.

constantdict v2025.3 74.1K downloads/30d#14,882 on PyPI6
Permissive license MIT License Copyright (c) 2024 University of Illinois Board of Trustees Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation… (full text in the JSON record) AGING released

What it is and what it does

constantdict is a lightweight immutable dictionary implementation that sits on top of Python's built-in dict. It prevents accidental in-place modifications by raising AttributeError on attempts to mutate (like setting items, popping, or clearing), while remaining fully hashable with cached hashes and comparable to regular dicts. The class is designed to be faster than some alternative immutable dictionary libraries.

You use it when you need a dict-like object that can serve as a dictionary key, be safely shared across code without fear of mutation, or benefit from cached hashing. It supports both functional-style operations (returning new immutable copies via setdefault, update, delete) and bulk mutation via a mutate()/finish() pattern for performance when making multiple changes at once.

Use it for:

  • Use as dictionary keys in sets or as dict keys where regular dicts cannot be used due to mutability.
  • Share configuration or lookup tables across functions without risk of accidental modification.
  • Cache immutable snapshots of data where hash stability and equality checks matter.
  • Bulk-update immutable structures efficiently via mutate()/finish() when creating many variants.
  • Replace frozendict or other immutable dict implementations when performance is a concern.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides an immutable dictionary class that wraps Python's built-in dict, preventing in-place modifications while remaining hashable and comparable to regular dicts.

Yes, if you need an immutable, hashable dict and want a lightweight, permissively licensed option. Install with caution given aging maintenance (last commit 2025-07-21, no recent releases), but the package is stable, has no known vulnerabilities, and low install friction. Best for projects where immutable dicts are a core requirement rather than an occasional convenience.

Install

constantdict on PyPI

pip

pip install constantdict

uv

uv add constantdict

poetry

poetry add constantdict

Installing constantdict

Before you install

Low install friction with only two lightweight runtime dependencies (importlib-metadata and typing-extensions). Maintenance status is aging—last commit was 2025-07-21, with no releases in the past 389 days, though the repository remains active and unarchived.

License in practice

MIT License permits unrestricted use, modification, and distribution with minimal restrictions, making it suitable for both open-source and proprietary projects.

Quickstart

pip install constantdict

from constantdict import constantdict

cd = constantdict({1: 2})
print(hash(cd))  # hashable and cached
cd_new = cd.setdefault(10, 5)  # returns mutated copy

Requires Python 3.7 or later.

Verify before relying

  • Performance comparison claims against other immutable dict implementations need independent verification.
  • Actual use adoption and community feedback beyond download statistics are not evident from the fact sheet.

Package facts

License MIT License Copyright (c) 2024 University of Illinois Board of Trustees Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies 2 — importlib-metadata, typing-extensions
Maintenance aging — 389 days since the last release
Last repo commit
First released
Downloads 74,056/month — #14,882 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: constantdict-2025.3-py3-none-any.whl

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Topic :: Software Development :: Libraries

Tags

immutable dictionaryhashable dictfrozen dictread-only mappingimmutable data structureconstant dicthashable mapping
immutable-data-structureshashable-collections

More Libraries packages