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!

Indexed Dictionary Class

Project Description


indicted - Indexed Document Class


Find an list element, which is a dict, by a keys value


Take for example the following data. This structure is being used to reduce
relationships between a parent object and sub objects. This allows us to create
indexes that help with relationships rather than making multiple calls to a
database. This is just an example structure of a document. This specific
structure will benifit heavily from a multi-value index on **subdata._id**.

"_id" : ObjectId("4f3eb7cac4f804960a859467"),
"subdata" : [
"_id" : ObjectId("4f3eb7cac4f804960a859468"),
"bits" : 1234
"_id" : ObjectId("4f3eb7cac4f804960a859469"),
"bits" : 5678

If we access the **subdata** key in the root of this document we will be given
an array when using standard Dict/List types.

[{u'_id': ObjectId('4f3eb7cac4f804960a859468'), u'bits': 1234.0},
{u'_id': ObjectId('4f3eb7cac4f804960a859469'), u'bits': 5678.0}]

Ideally we would want to return the list element that matches a specific **_id**
if the list contains dictionaries that have a key matching that ObjectId. This
is where indicted and Inist comes in. InDict is a simple Dict wrapper
that uses InList for all list type values. As InList is initialized and
modified it keeps an internal dictionary of **_id** references relating to list
positions. An extra function called **InList.find** is used to pull out a
referenced object if it finds one. **None** is returned otherwise.

import pprint
import pymongo

from bson import ObjectId

from indicted import InDict

class MongoInDict(InDict):
INDEXKEY = '_id'

connection = pymongo.Connection(document_class=MongoInDict)
database = connection.test

data =



{u'_id': ObjectId('4f3eb7cac4f804960a859469'), u'bits': 5678.0}

There is also **indicted.OrderedInDict** that inherits
**collections.OrderedDict**. This is incredibly useful for maintaining the
document key ordering of your documents.


Currently this module only creates references during the initialization of the
list. This will be addressed soon.


* Dot notation
* JSON encoding/decoding/pretty printing helpers

Release History

This version
History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(3.5 kB) Copy SHA256 Hash SHA256
Source None Nov 2, 2012

Supported By

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 Google Google Cloud Servers