A case-insensitive list for Python
Maintained. Last release 3 months ago, commits in 7 of the last 26 weeks. Weaker on release cadence and contributor spread.
pip install nocasedictnocasedict - A case-insensitive ordered dictionary for Python
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.14 on all Python versions it supports (except for being case-insensitive, of course).
The case-insensitivity is achieved by matching any key values as their casefolded values. By default, the casefolding is performed with str.casefold() for unicode string keys and with bytes.lower() for byte string keys. 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.