Skip to main content

A case-insensitive ordered dictionary for Python

Project description

Version on Pypi Actions status Docs build status (master) Test coverage (master)

Overview

Class NocaseDict is a case-insensitive ordered dictionary that preserves the original lexical case of its keys.

Example:

$ python
>>> from nocasedict import NocaseDict

>>> dict1 = NocaseDict({'Alpha': 1, 'Beta': 2})

>>> dict1['ALPHA']  # Lookup by key is case-insensitive
1

>>> print(dict1)  # Keys are returned with the original lexical case
NocaseDict({'Alpha': 1, 'Beta': 2})

The NocaseDict class supports the functionality of the built-in dict class of Python 3.8 on all Python versions it supports with the following exceptions (and the case-insensitivity of course):

  • The iter..(), view..() and has_key() methods are only present on Python 2, consistent with the built-in dict class.

  • The keys(), values() and items() methods return a list on Python 2 and a dictionary view on Python 3, consistent with the built-in dict class.

The case-insensitivity is achieved by matching any key values as their casefolded values. By default, the casefolding is performed as follows:

The default casefolding can be overridden with a user-defined casefold method.

Functionality can be added using mixin classes:

  • HashableMixin mixin class: Adds case-insensitive hashability.

  • KeyableByMixin mixin generator function: Adds ability to get the key from an attribute of the value object.

Why yet another case-insensitive dictionary: We found that all previously existing case-insensitive dictionary packages on Pypi either had flaws, were not well maintained, or did not support the Python versions we needed.

Installation

To install the latest released version of the nocasedict package into your active Python environment:

$ pip install nocasedict

This will also install any prerequisite Python packages.

For more details and alternative ways to install, see Installation.

Documentation

Change History

Contributing

For information on how to contribute to the nocasedict project, see Contributing.

License

The nocasedict project is provided under the GNU Lesser General Public License (LGPL) version 2.1, or (at your option) any later version.

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

nocasedict-1.1.1.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

nocasedict-1.1.1-py2.py3-none-any.whl (23.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nocasedict-1.1.1.tar.gz.

File metadata

  • Download URL: nocasedict-1.1.1.tar.gz
  • Upload date:
  • Size: 42.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.3 requests/2.27.1 setuptools/44.1.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/2.7.16

File hashes

Hashes for nocasedict-1.1.1.tar.gz
Algorithm Hash digest
SHA256 a3c669f148b93d91b50c39400868cbf69c66ee986a5025fdfce09b19eef67710
MD5 d24bd0fc9cb4e6e8ec29d7d98a2e1e37
BLAKE2b-256 2009761749f32a7e9e8fe9d21938695045db5eb42d89f696ec7de33f8bdfb1a3

See more details on using hashes here.

File details

Details for the file nocasedict-1.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: nocasedict-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.3 requests/2.27.1 setuptools/44.1.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/2.7.16

File hashes

Hashes for nocasedict-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d4e0fab6a106f0cd5a653029a27874d0ff14f4af0c25edb4dd18c0ff3557340c
MD5 29305c451f941ae95b670afa01e3e3df
BLAKE2b-256 b43fe02fa85b82c702390fa19926194488e5b3a1e751d811ad48fe858ca96122

See more details on using hashes here.

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