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!

Stores a model as a dictionary

Project Description


ModelDict is a very efficient way to store things like settings in your database. The entire model is transformed into a dictionary (lazily) as well as stored in your cache. It’s invalidated only when it needs to be (both in process and based on CACHE_BACKEND).

It was originally created by Disqus, but due to the inactivity we at YPlan have taken over maintenance on this fork.


Tested with all combinations of:

  • Python: 2.7, 3.5
  • Django: 1.8, 1.9, 1.10


Install it with pip:

pip install django-modeldict-yplan

Make sure you pip uninstall django-modeldict first if you’re upgrading from the original to this fork - the packages clash.

Example Usage

# You'll need a model with fields to use as key and value in the dict
class Setting(models.Model):
    key = models.CharField(max_length=32)
    value = models.CharField(max_length=200)

# Create the ModelDict...
settings = ModelDict(Setting, key='key', value='value', instances=False)

# And you can treat it like a normal dict:

# Missing values = KeyError
>>> KeyError

# Sets supported
settings['foo'] = 'hello'

# Fetch the current value using normal dictionary access
>>> 'hello'

# ...or by normal model queries
>>> 'hello'


Pending release

  • New release notes here

1.5.4 (2016-10-28)

1.5.3 (2016-09-20)

  • Stop rounding time.time() down to the nearest integer, so we are more fine grained around expiration. It might also fix a subtle timing bug around re-fetching the remote cache unnecessarily.

1.5.2 (2016-07-31)

  • Fixed update missing when _local_last_updated could be set even when it wasn’t updated
  • Fixed update missing from integer rounding in time comparison
  • Fixed CachedDict.__repr__ so it works for other subclasses of CachedDict than ModelDict (don’t assume self.model exists)

1.5.1 (2016-06-13)

  • Fixed local cache never expiring if value was checked too often.
  • Use Django’s cache.set_many for more efficient storage.

1.5.0 (2016-01-11)

  • Forked by YPlan
  • Fixed concurrency TOCTTOU bug for threaded Django servers.
  • Stopped including the ‘tests’ directory in package
  • Django 1.8 and 1.9 supported.
  • Python 3 support added.
  • Fixed setdefault() to return the value that was set/found, as per normal dict semantics. Thanks @olevinsky.

1.4.1 (2012-12-04)

  • Last release by Disqus

Release History

This version
History Node


History Node


History Node


History Node


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
(13.5 kB) Copy SHA256 Hash SHA256
Wheel 2.7 Oct 28, 2016
(14.9 kB) Copy SHA256 Hash SHA256
Source None Oct 28, 2016

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 DreamHost DreamHost Log Hosting