--- id: constantdict version: "2025.3" 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) license_treatment: permissive maintenance: aging --- # constantdict — An immutable dict class. License: permissive · Maintenance: aging · Downloads: 74.1K/mo ## 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 above — 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 pip install constantdict uv add constantdict 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_current - Install friction: low - Maintenance: aging - Downloads: 74.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags immutable dictionary, hashable dict, frozen dict, read-only mapping, immutable data structure, constant dict, hashable mapping, immutable-data-structures, hashable-collections [View on SkillFed](https://skillfed.io/packages/constantdict) · [View on PyPI](https://pypi.org/project/constantdict/)