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.1rc0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

accretive-2.1rc0-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

Details for the file accretive-2.1rc0.tar.gz.

File metadata

  • Download URL: accretive-2.1rc0.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.1rc0.tar.gz
Algorithm Hash digest
SHA256 9fa0e925c614f7d062d5ab9364978eaf617f1e9204bc85e6fa3cd615cc4c519a
MD5 f1c24b309a8de9a6e74935f098e9fc0f
BLAKE2b-256 8fd4d6b61ac79f087ec464f23d999d36ea6ffb2f557ec43ce2c12a1e14d6c242

See more details on using hashes here.

Provenance

The following attestation bundles were made for accretive-2.1rc0.tar.gz:

Publisher: releaser.yaml on emcd/python-accretive

Attestations:

File details

Details for the file accretive-2.1rc0-py3-none-any.whl.

File metadata

  • Download URL: accretive-2.1rc0-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.1rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 815193a9ac03904b0a69adcb56b9ed30e97320a03540b60cbbd9b545e63335df
MD5 f7ee9aa6abfc450fdb718ea8d9b3600a
BLAKE2b-256 1590954455fa9810240d3de24c66dfee1b7684aebf4b6c6248061ae04204090d

See more details on using hashes here.

Provenance

The following attestation bundles were made for accretive-2.1rc0-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