Accretive data structures.
Project description
🌌 A Python library package which provides accretive data structures - collections which can grow but never shrink.
Key Features ⭐
📖 Accretive Dictionary: Like a regular dict, but entries cannot be modified or removed once added. Also has variants with defaults and validation.
🗃️ Accretive Namespace: Similar to SimpleNamespace, but attributes become immutable after assignment.
🧱 Additional Types: Classes (including abstract base classes), modules, and objects with accretive 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.
Installation 📦
Method: Install Python Package
Install via uv pip command:
uv pip install accretive
Or, install via pip:
pip install accretive
Note on Immutability 📢
Enforcement of immutability is quite difficult in Python. While this library encourages 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.
Examples 💡
Accretive Namespaces 🗃️
An accretive 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 accretive import Namespace >>> ns = Namespace( apples = 12, bananas = 6 ) >>> ns.cherries = 42 # ✅ Allows new attributes. >>> ns.apples = 14 # ❌ Attempted reassignment raises error. Traceback (most recent call last): ... accretive.exceptions.AttributeImmutability: Could not assign or delete existing attribute 'apples'. >>> del ns.apples # ❌ Attempted deletion raises error. Traceback (most recent call last): ... accretive.exceptions.AttributeImmutability: Could not assign or delete existing attribute 'apples'. >>> ns accretive.namespaces.Namespace( apples = 12, bananas = 6, cherries = 42 )
Accretive Dictionaries 📖
An accretive 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 accretive import Dictionary
>>> dct = Dictionary( apples = 12, bananas = 6 )
>>> dct[ 'cherries' ] = 42 # ✅ Allows new entries.
>>> dct.update( blueberries = 96, strawberries = 24 )
accretive.dictionaries.Dictionary( {'apples': 12, 'bananas': 6, 'cherries': 42, 'blueberries': 96, 'strawberries': 24} )
>>> dct[ 'bananas' ] = 11 # ❌ Attempted alteration raises error.
Traceback (most recent call last):
...
accretive.exceptions.EntryImmutability: Could not alter or remove existing entry for 'bananas'.
>>> del dct[ 'bananas' ] # ❌ Attempted removal raises error.
Traceback (most recent call last):
...
accretive.exceptions.EntryImmutability: Could not alter or remove existing entry for 'bananas'.
>>> dct
accretive.dictionaries.Dictionary( {'apples': 12, 'bananas': 6, 'cherries': 42, 'blueberries': 96, 'strawberries': 24} )
Accretive Objects 🧱
The accretive decorator can be applied to any class to make its instances enforce attribute immutability after assignment.
>>> from accretive import with_standard_behaviors >>> @with_standard_behaviors ... class Config: ... def __init__( self, debug = False ): ... self.debug = debug ... >>> config = Config( debug = True ) >>> config.verbose = True # ✅ Allows new attributes >>> config.debug = False # ❌ Attempted reassignment raises error Traceback (most recent call last): ... accretive.exceptions.AttributeImmutability: Could not assign or delete existing attribute 'debug'.
Use Cases 🎯
📝 Configuration Registries: Registries which can accumulate entries but never remove them, thereby guaranteeing sticky state.
🔌 Plugin Systems: Register extensions which are then guaranteed to be available from the time of registration to the end of the process.
🔒 Immutable Collections: Many scenarios requiring grow-only collections with immutability guarantees.
Contribution 🤝
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.
More Flair
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file accretive-4.1.tar.gz.
File metadata
- Download URL: accretive-4.1.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4ae4ac5d17317c1a1864712114cff949c2be04f59c9add46195147926415271
|
|
| MD5 |
168ba515cd659b799e0db4db568ff685
|
|
| BLAKE2b-256 |
69821b66b70ee10f5951252402aced73ccf6d2e084083441d4d66d2f9bbe66f0
|
Provenance
The following attestation bundles were made for accretive-4.1.tar.gz:
Publisher:
releaser.yaml on emcd/python-accretive
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
accretive-4.1.tar.gz -
Subject digest:
f4ae4ac5d17317c1a1864712114cff949c2be04f59c9add46195147926415271 - Sigstore transparency entry: 264089836
- Sigstore integration time:
-
Permalink:
emcd/python-accretive@9bb1dfe51687cd75a96c7488dbc096d267249a63 -
Branch / Tag:
refs/tags/v4.1 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@9bb1dfe51687cd75a96c7488dbc096d267249a63 -
Trigger Event:
push
-
Statement type:
File details
Details for the file accretive-4.1-py3-none-any.whl.
File metadata
- Download URL: accretive-4.1-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7241ca2b9c23c0f3488b06007635fe519f91c3ffa9bba05383d19c864ac5160
|
|
| MD5 |
4f04c66048d802e8c485027b49f00870
|
|
| BLAKE2b-256 |
7faeb5418e16ac6444764ffa373f1f36fbc105b446fd79e7a79ed1559784fb1b
|
Provenance
The following attestation bundles were made for accretive-4.1-py3-none-any.whl:
Publisher:
releaser.yaml on emcd/python-accretive
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
accretive-4.1-py3-none-any.whl -
Subject digest:
c7241ca2b9c23c0f3488b06007635fe519f91c3ffa9bba05383d19c864ac5160 - Sigstore transparency entry: 264089837
- Sigstore integration time:
-
Permalink:
emcd/python-accretive@9bb1dfe51687cd75a96c7488dbc096d267249a63 -
Branch / Tag:
refs/tags/v4.1 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@9bb1dfe51687cd75a96c7488dbc096d267249a63 -
Trigger Event:
push
-
Statement type: