π A Python library package which provides immutable data structures - collections which cannot be modified after creation.
- π Immutable Dictionary: Like a regular dict, but entries cannot be modified or removed. Also has variant for validation on initialization. And provides set operations not found on MappingProxyType.
- ποΈ Immutable Namespace: Similar to SimpleNamespace, but attributes are immutable from creation.
- π§± Additional Types: Classes (including abstract base classes), modules, and objects with immutable behavior.
- ποΈ Flexible Initialization: Support for unprotected attributes during initialization; useful for compatibility with class decorators, such as dataclasses.
- π Flexible Mutability: Support for declaring specific attributes as mutable, enabling selective modification while maintaining immutability for other attributes.
Install via uv pip
command:
uv pip install frigid
Or, install via pip:
pip install frigid
Enforcement of immutability is quite difficult in Python. While this library enforces immutability by default, it can be circumvented by anyone who has intermediate knowledge of Python machinery and who is determined to circumvent the immutability. Use the library in the spirit of making programs safer, but understand that it cannot truly prevent unwanted state tampering.
An immutable namespace, similar to types.SimpleNamespace, is available.
This namespace can be initialized from multiple iterables and from keyword
arguments. (Keyword arguments shown below; see documentation for additional
forms of initialization.)
>>> from frigid import Namespace
>>> ns = Namespace( apples = 12, bananas = 6 )
>>> ns.cherries = 42 # β Attempted assignment raises error.
Traceback (most recent call last):
...
frigid.exceptions.AttributeImmutability: Could not assign or delete attribute 'cherries'.
>>> del ns.apples # β Attempted deletion raises error.
Traceback (most recent call last):
...
frigid.exceptions.AttributeImmutability: Could not assign or delete attribute 'apples'.
>>> ns
frigid.namespaces.Namespace( apples = 12, bananas = 6 )An immutable dictionary, similar to dict, is available. This dictionary can
be initialized from multiple iterables and from keyword arguments. (Keyword
arguments shown below; see documentation for additional forms of
initialization.)
>>> from frigid import Dictionary
>>> dct = Dictionary( apples = 12, bananas = 6)
>>> dct['cherries'] = 42 # β Attempted assignment raises error.
Traceback (most recent call last):
...
frigid.exceptions.EntryImmutability: Cannot assign entry for 'cherries'.
>>> del dct['bananas'] # β Attempted removal raises error.
Traceback (most recent call last):
...
frigid.exceptions.EntryImmutability: Cannot delete entry for 'bananas'.
>>> dct
frigid.dictionaries.Dictionary( {'apples': 12, 'bananas': 6} )The with_standard_behaviors decorator can be applied to any class to make
its instances fully immutable after initialization.
>>> from frigid import with_standard_behaviors
>>> @with_standard_behaviors( )
... class Config:
... def __init__( self, debug = False ):
... self.debug = debug
...
>>> config = Config( debug = True )
>>> config.verbose = True # β Attempted addition raises error
Traceback (most recent call last):
...
frigid.exceptions.AttributeImmutability: Could not assign or delete attribute 'verbose'.
>>> config.debug = False # β Attempted reassignment raises error
Traceback (most recent call last):
...
frigid.exceptions.AttributeImmutability: Could not assign or delete attribute 'debug'.- π Configuration Objects: Objects which must maintain consistent state throughout program execution.
- π Value Objects: Objects which represent values and should be immutable, like numbers or strings.
- π§± Immutable Collections: Many scenarios requiring collections with complete immutability guarantees.
Contribution to this project is welcome! However, it must follow the code of conduct for the project.
Please file bug reports and feature requests in the issue tracker or submit pull requests to improve the source code or documentation.
For development guidance and standards, please see the development guide.
python-absence (absence on PyPI)
π³οΈ A Python library package which provides a sentinel for absent values - a falsey, immutable singleton that represents the absence of a value in contexts where
NoneorFalsemay be valid values.python-accretive (accretive on PyPI)
π A Python library package which provides accretive data structures - collections which can grow but never shrink.
python-classcore (classcore on PyPI)
π A Python library package which provides foundational class factories and decorators for providing classes with attributes immutability and concealment and other custom behaviors.
python-detextive (detextive on PyPI)
π΅οΈ A Python library which provides consolidated text detection capabilities for reliable content analysis. Offers MIME type detection, character set detection, and line separator processing.
python-dynadoc (dynadoc on PyPI)
π A Python library package which bridges the gap between rich annotations and automatic documentation generation with configurable renderers and support for reusable fragments.
python-falsifier (falsifier on PyPI)
π A very simple Python library package which provides a base class for falsey objects - objects that evaluate to
Falsein boolean contexts.python-icecream-truck (icecream-truck on PyPI)
π¦ Flavorful Debugging - A Python library which enhances the powerful and well-known
icecreampackage with flavored traces, configuration hierarchies, customized outputs, ready-made recipes, and more.python-librovore (librovore on PyPI)
π² Documentation Search Engine - An intelligent documentation search and extraction tool that provides both a command-line interface for humans and an MCP (Model Context Protocol) server for AI agents. Search across Sphinx and MkDocs sites with fuzzy matching, extract clean markdown content, and integrate seamlessly with AI development workflows.
python-mimeogram (mimeogram on PyPI)
π¨ A command-line tool for exchanging collections of files with Large Language Models - bundle multiple files into a single clipboard-ready document while preserving directory structure and metadata... good for code reviews, project sharing, and LLM interactions.