Metadata-Version: 2.3
Name: frigid
Version: 1.0a0
Summary: Immutable data structures.
Project-URL: Homepage, https://github.com/emcd/python-frigid
Project-URL: Documentation, https://emcd.github.io/python-frigid
Project-URL: Source Code, https://github.com/emcd/python-frigid
Project-URL: Download, https://pypi.org/project/frigid/#files
Project-URL: Issue Tracker, https://github.com/emcd/python-frigid/issues
Author-email: Eric McDonald <emcd@users.noreply.github.com>
License: Apache-2.0
Keywords: api,dictionary,immutability,immutable,namespace
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development
Requires-Python: >=3.10
Requires-Dist: typing-extensions
Description-Content-Type: text/x-rst

.. vim: set fileencoding=utf-8:
.. -*- coding: utf-8 -*-
.. +--------------------------------------------------------------------------+
   |                                                                          |
   | Licensed under the Apache License, Version 2.0 (the "License");          |
   | you may not use this file except in compliance with the License.         |
   | You may obtain a copy of the License at                                  |
   |                                                                          |
   |     http://www.apache.org/licenses/LICENSE-2.0                           |
   |                                                                          |
   | Unless required by applicable law or agreed to in writing, software      |
   | distributed under the License is distributed on an "AS IS" BASIS,        |
   | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
   | See the License for the specific language governing permissions and      |
   | limitations under the License.                                           |
   |                                                                          |
   +--------------------------------------------------------------------------+

*******************************************************************************
                                  frigid
*******************************************************************************

.. image:: https://img.shields.io/pypi/v/frigid
   :alt: Project Version
   :target: https://pypi.org/project/frigid/

.. image:: https://img.shields.io/pypi/status/frigid
   :alt: PyPI - Status
   :target: https://pypi.org/project/frigid/

.. image:: https://github.com/emcd/python-frigid/actions/workflows/tester.yaml/badge.svg?branch=master&event=push
   :alt: Tests Status
   :target: https://github.com/emcd/python-frigid/actions/workflows/tester.yaml

.. image:: https://emcd.github.io/python-frigid/coverage.svg
   :alt: Code Coverage Percentage
   :target: https://github.com/emcd/python-frigid/actions/workflows/tester.yaml

.. image:: https://img.shields.io/pypi/pyversions/frigid
   :alt: Python Versions
   :target: https://pypi.org/project/frigid/

.. image:: https://img.shields.io/pypi/l/frigid
   :alt: Project License
   :target: https://github.com/emcd/python-frigid/blob/master/LICENSE.txt


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


Key Features ⭐
===============================================================================

* 📖 **Immutable Dictionary**: Like a regular `dict
  <https://docs.python.org/3/library/stdtypes.html#dict>`_, but entries cannot
  be modified or removed. Also has variant for validation on initialization.
  And provides set operations not found on `MappingProxyType
  <https://docs.python.org/3/library/types.html#types.MappingProxyType>`_.
* 📇 **Immutable Namespace**: Similar to `SimpleNamespace
  <https://docs.python.org/3/library/types.html#types.SimpleNamespace>`_, but
  attributes are immutable from creation.
* 🧱 **Additional Types**: Classes (including abstract base classes), modules,
  and objects with immutable behavior.
* 🏗️ **Flexible Initialization**: Support for unprotected attributes during
  initialization; useful for compatibility with class decorators, such as
  `dataclasses
  <https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass>`_.


Note on Immutability 📢
===============================================================================

   Enforcement of immutability is quite difficult in Python. While this library
   enforces 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 frigid


Examples 💡
===============================================================================


Immutable Namespace 📇
-------------------------------------------------------------------------------

An immutable namespace, similar to ``types.SimpleNamespace``, is available.
This namespace is initialized from keyword arguments and becomes completely
immutable. (Keyword arguments shown below; see documentation for additional
forms of initialization.)

>>> from frigid import Namespace
>>> ns = Namespace( apples = 12, bananas = 6 )
>>> ns.cherries = 42    # ❌ Attempted assignment raises error.
Traceback (most recent call last):
...
frigid.exceptions.AttributeImmutabilityError: Cannot assign attribute 'cherries'.
>>> del ns.apples       # ❌ Attempted deletion raises error.
Traceback (most recent call last):
...
frigid.exceptions.AttributeImmutabilityError: Cannot delete attribute 'apples'.
>>> ns
frigid.namespaces.Namespace( apples = 12, bananas = 6 )


Immutable Dictionary 📖
-------------------------------------------------------------------------------

An immutable dictionary, similar to ``dict``, is available. This dictionary is
initialized from iterables and keyword arguments and becomes completely
immutable. (Keyword arguments shown below; see documentation for additional
forms of initialization.)

>>> from frigid import Dictionary
>>> dct = Dictionary( apples = 12, bananas = 6)
>>> dct['cherries'] = 42  # ❌ Attempted assignment raises error.
Traceback (most recent call last):
...
frigid.exceptions.EntryImmutabilityError: Cannot assign entry for 'cherries'.
>>> del dct['bananas']    # ❌ Attempted removal raises error.
Traceback (most recent call last):
...
frigid.exceptions.EntryImmutabilityError: Cannot delete entry for 'bananas'.
>>> dct
frigid.dictionaries.Dictionary( {'apples': 12, 'bananas': 6} )


Use Cases 🎯
===============================================================================

* 🔒 **Configuration Objects**: Objects which must maintain consistent state
  throughout program execution.
* 📊 **Value Objects**: Objects which represent values and should be immutable,
  like numbers or strings.
* 🧱 **Immutable Collections**: Many scenarios requiring collections with
  complete immutability guarantees.


`More Flair <https://www.imdb.com/title/tt0151804/characters/nm0431918>`_
===============================================================================

.. image:: https://img.shields.io/github/last-commit/emcd/python-frigid
   :alt: GitHub last commit
   :target: https://github.com/emcd/python-frigid

.. image:: https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg
   :alt: Hatch
   :target: https://github.com/pypa/hatch

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit
   :alt: pre-commit
   :target: https://github.com/pre-commit/pre-commit

.. image:: https://img.shields.io/badge/security-bandit-yellow.svg
   :alt: Bandit
   :target: https://github.com/PyCQA/bandit

.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
   :alt: Pylint
   :target: https://github.com/pylint-dev/pylint

.. image:: https://microsoft.github.io/pyright/img/pyright_badge.svg
   :alt: Pyright
   :target: https://microsoft.github.io/pyright/

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
   :alt: Ruff
   :target: https://github.com/astral-sh/ruff

.. image:: https://img.shields.io/badge/hypothesis-tested-brightgreen.svg
   :alt: Hypothesis
   :target: https://hypothesis.readthedocs.io/en/latest/

.. image:: https://img.shields.io/pypi/implementation/frigid
   :alt: PyPI - Implementation
   :target: https://pypi.org/project/frigid/

.. image:: https://img.shields.io/pypi/wheel/frigid
   :alt: PyPI - Wheel
   :target: https://pypi.org/project/frigid/