Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/domdfcoding/cawdrey

Several useful custom dictionaries for Python 📖 🐍
https://github.com/domdfcoding/cawdrey

counter dict dictionary frozen frozendict frozenordereddict immutable map mapping mappingproxytype orderedfrozendict python python3

Last synced: 21 days ago
JSON representation

Several useful custom dictionaries for Python 📖 🐍

Awesome Lists containing this project

README

        

==========
Cawdrey
==========

.. start short_desc

**Several useful custom dictionaries for Python 📖 🐍**

.. end short_desc

.. start shields

.. list-table::
:stub-columns: 1
:widths: 10 90

* - Docs
- |docs| |docs_check|
* - Tests
- |actions_linux| |actions_windows| |actions_macos| |coveralls|
* - PyPI
- |pypi-version| |supported-versions| |supported-implementations| |wheel|
* - Anaconda
- |conda-version| |conda-platform|
* - Activity
- |commits-latest| |commits-since| |maintained| |pypi-downloads|
* - QA
- |codefactor| |actions_flake8| |actions_mypy|
* - Other
- |license| |language| |requires|

.. |docs| image:: https://img.shields.io/readthedocs/cawdrey/latest?logo=read-the-docs
:target: https://cawdrey.readthedocs.io/en/latest
:alt: Documentation Build Status

.. |docs_check| image:: https://github.com/domdfcoding/cawdrey/workflows/Docs%20Check/badge.svg
:target: https://github.com/domdfcoding/cawdrey/actions?query=workflow%3A%22Docs+Check%22
:alt: Docs Check Status

.. |actions_linux| image:: https://github.com/domdfcoding/cawdrey/workflows/Linux/badge.svg
:target: https://github.com/domdfcoding/cawdrey/actions?query=workflow%3A%22Linux%22
:alt: Linux Test Status

.. |actions_windows| image:: https://github.com/domdfcoding/cawdrey/workflows/Windows/badge.svg
:target: https://github.com/domdfcoding/cawdrey/actions?query=workflow%3A%22Windows%22
:alt: Windows Test Status

.. |actions_macos| image:: https://github.com/domdfcoding/cawdrey/workflows/macOS/badge.svg
:target: https://github.com/domdfcoding/cawdrey/actions?query=workflow%3A%22macOS%22
:alt: macOS Test Status

.. |actions_flake8| image:: https://github.com/domdfcoding/cawdrey/workflows/Flake8/badge.svg
:target: https://github.com/domdfcoding/cawdrey/actions?query=workflow%3A%22Flake8%22
:alt: Flake8 Status

.. |actions_mypy| image:: https://github.com/domdfcoding/cawdrey/workflows/mypy/badge.svg
:target: https://github.com/domdfcoding/cawdrey/actions?query=workflow%3A%22mypy%22
:alt: mypy status

.. |requires| image:: https://dependency-dash.repo-helper.uk/github/domdfcoding/cawdrey/badge.svg
:target: https://dependency-dash.repo-helper.uk/github/domdfcoding/cawdrey/
:alt: Requirements Status

.. |coveralls| image:: https://img.shields.io/coveralls/github/domdfcoding/cawdrey/master?logo=coveralls
:target: https://coveralls.io/github/domdfcoding/cawdrey?branch=master
:alt: Coverage

.. |codefactor| image:: https://img.shields.io/codefactor/grade/github/domdfcoding/cawdrey?logo=codefactor
:target: https://www.codefactor.io/repository/github/domdfcoding/cawdrey
:alt: CodeFactor Grade

.. |pypi-version| image:: https://img.shields.io/pypi/v/cawdrey
:target: https://pypi.org/project/cawdrey/
:alt: PyPI - Package Version

.. |supported-versions| image:: https://img.shields.io/pypi/pyversions/cawdrey?logo=python&logoColor=white
:target: https://pypi.org/project/cawdrey/
:alt: PyPI - Supported Python Versions

.. |supported-implementations| image:: https://img.shields.io/pypi/implementation/cawdrey
:target: https://pypi.org/project/cawdrey/
:alt: PyPI - Supported Implementations

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

.. |conda-version| image:: https://img.shields.io/conda/v/domdfcoding/cawdrey?logo=anaconda
:target: https://anaconda.org/domdfcoding/cawdrey
:alt: Conda - Package Version

.. |conda-platform| image:: https://img.shields.io/conda/pn/domdfcoding/cawdrey?label=conda%7Cplatform
:target: https://anaconda.org/domdfcoding/cawdrey
:alt: Conda - Platform

.. |license| image:: https://img.shields.io/github/license/domdfcoding/cawdrey
:target: https://github.com/domdfcoding/cawdrey/blob/master/LICENSE
:alt: License

.. |language| image:: https://img.shields.io/github/languages/top/domdfcoding/cawdrey
:alt: GitHub top language

.. |commits-since| image:: https://img.shields.io/github/commits-since/domdfcoding/cawdrey/v0.5.1
:target: https://github.com/domdfcoding/cawdrey/pulse
:alt: GitHub commits since tagged version

.. |commits-latest| image:: https://img.shields.io/github/last-commit/domdfcoding/cawdrey
:target: https://github.com/domdfcoding/cawdrey/commit/master
:alt: GitHub last commit

.. |maintained| image:: https://img.shields.io/maintenance/yes/2024
:alt: Maintenance

.. |pypi-downloads| image:: https://img.shields.io/pypi/dm/cawdrey
:target: https://pypi.org/project/cawdrey/
:alt: PyPI - Downloads

.. end shields

Contents
=============

* ``frozendict``: An immutable dictionary that cannot be changed after creation.
* ``FrozenOrderedDict``: An immutable ``OrderedDict`` where the order of keys is preserved, but that cannot be changed after creation.
* ``AlphaDict``: A ``FrozenOrderedDict`` where the keys are stored in alphabetical order.
* ``bdict``: A dictionary where ``key, value`` pairs are stored both ways round.

This package also provides two base classes for creating your own custom dictionaries:

* ``FrozenBase``: An Abstract Base Class for Frozen dictionaries.

* ``MutableBase``: An Abstract Base Class for mutable dictionaries.

|

Other Dictionary Packages
===========================

If you're looking to unflatten a dictionary, such as to go from this:

.. code-block:: python

{"foo.bar": "val"}

to this:

.. code-block:: python

{"foo": {"bar": "val"}}

check out `unflatten`_, `flattery`_ or `morph`_ to accomplish that.

.. _unflatten: https://github.com/dairiki/unflatten
.. _morph: https://github.com/metagriffin/morph
.. _flattery: https://github.com/acg/python-flattery

`indexed`_ provides an OrderedDict where the values can be accessed by their index as well as by their keys.

.. _indexed: https://github.com/niklasf/indexed.py

There's also `python-benedict`_, which provides a custom dictionary with **keylist/keypath** support, **I/O** shortcuts (``Base64``, ``CSV``, ``JSON``, ``TOML``, ``XML``, ``YAML``, ``pickle``, ``query-string``) and many **utilities**.

.. _python-benedict: https://github.com/fabiocaccamo/python-benedict

Installation
===========================

.. start installation

``Cawdrey`` can be installed from PyPI or Anaconda.

To install with ``pip``:

.. code-block:: bash

$ python -m pip install cawdrey

To install with ``conda``:

* First add the required channels

.. code-block:: bash

$ conda config --add channels https://conda.anaconda.org/conda-forge
$ conda config --add channels https://conda.anaconda.org/domdfcoding

* Then install

.. code-block:: bash

$ conda install cawdrey

.. end installation

And Finally:
==============

`Why "Cawdrey"? `_