Skip to main content
Package Version PyPI - Status Tests Status Code Coverage Percentage Project License Python Versions

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

Additional Indicia

GitHub last commit Copier Hatch pre-commit Pyright Ruff PyPI - Implementation PyPI - Wheel

Other Projects by This Author 🌟

  • python-absence (absence on PyPI)

    🕳️ A Python library package which provides a sentinel for absent values - a falsey, immutable singleton that represents the absence of a value in contexts where None or False may be valid values.

  • python-classcore (classcore on PyPI)

    🏭 A Python library package which provides foundational class factories and decorators for providing classes with attributes immutability and concealment and other custom behaviors.

  • python-dynadoc (dynadoc on PyPI)

    📝 A Python library package which bridges the gap between rich annotations and automatic documentation generation with configurable renderers and support for reusable fragments.

  • python-falsifier (falsifier on PyPI)

    🎭 A very simple Python library package which provides a base class for falsey objects - objects that evaluate to False in boolean contexts.

  • python-frigid (frigid on PyPI)

    🔒 A Python library package which provides immutable data structures - collections which cannot be modified after creation.

  • python-icecream-truck (icecream-truck on PyPI)

    🍦 Flavorful Debugging - A Python library which enhances the powerful and well-known icecream package with flavored traces, configuration hierarchies, customized outputs, ready-made recipes, and more.

  • python-mimeogram (mimeogram on PyPI)

    📨 A command-line tool for exchanging collections of files with Large Language Models - bundle multiple files into a single clipboard-ready document while preserving directory structure and metadata… good for code reviews, project sharing, and LLM interactions.

Metadata

Release files for accretive 4.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for accretive 4.2.1
File Size Uploaded
accretive-4.2.1.tar.gz 21.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for accretive 4.2.1
File Interpreter ABI Platform
accretive-4.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 51.5 kB

Release files / accretive-4.2.1.tar.gz

Download URL accretive-4.2.1.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
af535b99905753842bda6cda55d087a02a946c796d3a29c5bab3013594fef965
BLAKE2b-256 checksum
How to use checksums
8617c022483fa40b197717e941ecdc7e8b54cad3069bc84ffa95583e0cab6d67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2025.

Transparency log

Release files / accretive-4.2.1-py3-none-any.whl

Download URL accretive-4.2.1-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
656ae75f06463eeb16117a43a57efb5ac10f7fbcb37d74256ffbf74f3f898591
BLAKE2b-256 checksum
How to use checksums
e1cdb427717b43cb926bddf4c48c366ef9ea09dcaa060973bf3c29cdddf52c1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2025.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page