Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Case insensitive derivable dictionary

Project Description


You can install the newest version of pydicti from PyPI:

pip install pydicti

Alternatively, you can just take the file and redistribute it with your application.


  • class dicti: default case insensitive dictionary type
  • class odicti: ordered case insensitive dictionary type
  • def build_dicti: create a case insensitive dictionary class
  • def Dicti: create a case insensitive copy of a dictionary


Objects of type dicti are dictionaries that feature case insensitive item access:

>>> d = dicti(Hello='foo', world='bar')
>>> d['heLLO']
>>> 'WOrld' in d

Internally however, the keys retain their original case:

>>> sorted(d.keys())
['Hello', 'world']


The type odicti instanciates order-preserving case insensitive dictionaries. It is available if either collections.OrderedDict or ordereddict.OrderedDict exists:

>>> odicti(zip('abc', range(3)))
Dicti(OrderedDict([('a', 0), ('b', 1), ('c', 2)]))


With build_dicti you can create custom case insensitive dictionaries. This function is what is used to create the pydicti.dicti and pydicti.odicti types. Note that calling build_dicti several times with the same argument will result in identical types:

>>> build_dicti(dict) is dicti
>>> build_dicti(OrderedDict) is odicti

build_dicti uses subclassing to inherit the semantics of the given base dictionary type:

>>> issubclass(odicti, OrderedDict)


The function Dicti is convenient for creating case insensitive copies of dictionary instances:

>>> o = OrderedDict(zip('abcdefg', range(7)))
>>> oi = Dicti(o)
>>> type(oi) is odicti


The subclassing approach allows to plug your dictionary instance into places where typechecking with isinstance is used, like in the json module:

>>> import json
>>> d == json.loads(json.dumps(d), object_hook=dicti)

Above python26 you can use json.loads(s, object_pairs_hook=odicti) to deserialize ordered dictionaries.


The equality comparison tries preserves the semantics of the base type as well as reflexitivity. This has impact on the transitivity of the comparison operator:

>>> i = dicti(oi)
>>> roi = odicti(reversed(list(oi.items())))
>>> roi == i and i == oi
>>> oi != roi and roi != oi  # NOT transitive!
>>> oi == i and i == oi      # reflexive

The coercion rules in python allow this to work pretty well when performing comparisons between types that are subclasses of each other. Be careful otherwise, however.


Copyright © 2013 Thomas Gläßle <>

This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See the COPYING file for more details.

This program is free software. It comes without any warranty, to the extent permitted by applicable law.



Date: 08.09.2016

  • fix UnicodeDecodeError in setup when UTF-8 is not the default encoding


Date: 18.05.2016

  • fix pickling on py 3.5
  • the ‘name’ parameter to build_dicti can now be a qualname


Date: 01.02.2014

  • add coverage reports
  • use more extensive unit tests
  • add support for pickle


Date: 26.01.2014

  • add support for python26
  • make dependency on OrderedDict optional
  • migrate to setuptools in order to use testing commands
  • support ordereddict.OrderedDict as fallback


Date: 29.12.2013

  • fix dicti.pop
  • support deepcopy(dicti)
  • make nosetest automatically execute the doctests
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pydicti-0.0.6.tar.gz (9.5 kB) Copy SHA256 Checksum SHA256 Source Sep 8, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting