Skip to main content

Accretive data structures.

Project description

Project Version PyPI - Status Tests Status Code Coverage Percentage Python Versions Project License

🔒 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.

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.

Installation 📦

pip install accretive

More Flair

GitHub last commit Hatch pre-commit Bandit Pylint Pyright Ruff PyPI - Implementation PyPI - Wheel

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

accretive-2.2a0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

accretive-2.2a0-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

Details for the file accretive-2.2a0.tar.gz.

File metadata

  • Download URL: accretive-2.2a0.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

Hashes for accretive-2.2a0.tar.gz
Algorithm Hash digest
SHA256 0476c4f359646e7cebba88813f97653e13e7830d78f16bc0c9542928434d04e9
MD5 23ded152889f9efc3e5b18f7925341a9
BLAKE2b-256 a5a6a549ca36ec19cd03a1d09c14fa06018d04f2883a0887863bb678d3bd6ec1

See more details on using hashes here.

Provenance

The following attestation bundles were made for accretive-2.2a0.tar.gz:

Publisher: releaser.yaml on emcd/python-accretive

Attestations:

File details

Details for the file accretive-2.2a0-py3-none-any.whl.

File metadata

  • Download URL: accretive-2.2a0-py3-none-any.whl
  • Upload date:
  • Size: 28.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for accretive-2.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2073a9ed630d9ca1030dc5a867ae0faece595c57a2e556b572fb345cf87a75b
MD5 5cae47e3b002c7b30fcdf9fcb6f5232d
BLAKE2b-256 5f4b17af8ba28f5219bb0129ce33551b4558ecafd6ecd5ab8dc30453db4bdc83

See more details on using hashes here.

Provenance

The following attestation bundles were made for accretive-2.2a0-py3-none-any.whl:

Publisher: releaser.yaml on emcd/python-accretive

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page