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.
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.
Installation 📦
pip install accretive
Examples 💡
Accretive Namespace 🗃️
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.AttributeImmutabilityError: Cannot reassign or delete existing attribute 'apples'. >>> del ns.apples # ❌ Attempted deletion raises error. Traceback (most recent call last): ... accretive.exceptions.AttributeImmutabilityError: Cannot reassign or delete existing attribute 'apples'. >>> ns accretive.namespaces.Namespace( apples = 12, bananas = 6, cherries = 42 )
Accretive Dictionary 📖
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.EntryImmutabilityError: Cannot alter or remove existing entry for 'bananas'. >>> del dct[ 'bananas' ] # ❌ Attempted removal raises error. Traceback (most recent call last): ... accretive.exceptions.EntryImmutabilityError: Cannot alter or remove existing entry for 'bananas'. >>> dct accretive.dictionaries.Dictionary( {'apples': 12, 'bananas': 6, 'cherries': 42, 'blueberries': 96, 'strawberries': 24} )
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.
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
File details
Details for the file accretive-2.1.tar.gz
.
File metadata
- Download URL: accretive-2.1.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80f93cb4ca7d7d56e0778a9596287e6c99014315ac8378c2e865ab88f7263d24 |
|
MD5 | 5a436eebcaf81bd4c272dade966acd74 |
|
BLAKE2b-256 | 992b97d8e6d847fde37f058965caa7f9a84643924b150d7e5b70282ffc54666e |
Provenance
The following attestation bundles were made for accretive-2.1.tar.gz
:
Publisher:
releaser.yaml
on emcd/python-accretive
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
accretive-2.1.tar.gz
- Subject digest:
80f93cb4ca7d7d56e0778a9596287e6c99014315ac8378c2e865ab88f7263d24
- Sigstore transparency entry: 150047782
- Sigstore integration time:
- Predicate type:
File details
Details for the file accretive-2.1-py3-none-any.whl
.
File metadata
- Download URL: accretive-2.1-py3-none-any.whl
- Upload date:
- Size: 28.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a6d491c328ed9cf0a7b501ff20bfe5fcff1141bebd5e3e28bb64031777d4a04 |
|
MD5 | 6aba9da95e526556651c4b19458e7de5 |
|
BLAKE2b-256 | d2d1448cd5f97eaa6922338fddd411470fcee7ac8d64f9deafff1d25f2527fcd |
Provenance
The following attestation bundles were made for accretive-2.1-py3-none-any.whl
:
Publisher:
releaser.yaml
on emcd/python-accretive
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
accretive-2.1-py3-none-any.whl
- Subject digest:
1a6d491c328ed9cf0a7b501ff20bfe5fcff1141bebd5e3e28bb64031777d4a04
- Sigstore transparency entry: 150047784
- Sigstore integration time:
- Predicate type: