itypes
itypes is a Python library providing simple immutable container types and custom immutable objects. It prioritizes simplicity over performance, offering a way to create data structures that cannot be modified after creation. The current version is 1.2.0, released in April 2020, indicating a slow release cadence with limited recent development activity.
Warnings
- breaking Attempting to modify attributes of `itypes` objects directly (e.g., `obj.attribute = value`) will raise a `TypeError` because they are designed to be immutable. Instead, use methods provided by the object (like `.set()` for `Configuration`) which return a new object with the desired changes.
- gotcha The library is explicitly "designed for simplicity over performance". If your application requires high-performance immutable data structures, the author suggests exploring alternatives like `pyrsistent`.
- gotcha The project shows limited recent development activity. The last release (1.2.0) was in April 2020, and the last code push on GitHub was approximately 7 years ago (as of 2026). This may imply a lack of support for newer Python versions or delayed bug fixes.
Install
-
pip install itypes
Imports
- Configuration
from itypes import Configuration
- Object
from itypes import Object
Quickstart
import itypes
# Immutable dictionary-like object
config = itypes.Configuration('worker-process', {'hostname': 'example.com', 'dynos': 4})
print(f"Original config title: {config.title}")
print(f"Original config dynos: {config.get('dynos')}")
# Attempting to change an attribute directly will raise an error
try:
config.title = 'New Title'
except TypeError as e:
print(f"Caught expected error: {e}")
# To 'modify', a new object is returned
new_config = config.set('dynos', 2)
print(f"New config dynos: {new_config.get('dynos')}")
print(f"Original config dynos (unchanged): {config.get('dynos')}")
# Custom immutable object
class Document(itypes.Object):
def __init__(self, title, content):
self._title = title
self._content = content
@property
def title(self):
return self._title
@property
def content(self):
return self._content
doc = Document(title='Immutability', content='For simplicity')
print(f"Document title: {doc.title}")
# Attempting to change a public property directly will raise an error
try:
doc.title = 'Changed Title'
except TypeError as e:
print(f"Caught expected error on custom object: {e}")