This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

DictLiteStore

A dynamic-schema sqlite backend for storing python dicts in a queriable database.

All values within the dict are stored as json values in the database, but the keys are mapped into table columns, So you can query things , while it’s still very easy to parse.

When you try to add a dict which has keys which aren’t in the table already, it will automatically add those columns.

So a dict:

{'author': 'dan',
 'project': 'DictLiteStore',
 'categories': ['python', 'dict', 'persistance']
}

becomes in the database:

AUTHOR PROJECT CATEGORIES
"dan" "DictLiteStore" ["python", "dict", "persistance"]

This is quite cool, as you can then use regular SQL to query stuff.

SELECT * FROM 'dict_store' WHERE 'author' == '"dan"'

for instance. (Note the quotes around the query value.) There is a simple wrapper around the sql select function (get) that you can use if you don’t want to run type sql yourself. See the Usage section below.

Since the data is in json form, even for lists (like categories) you can fairly easily query it too. Search for all rows with ‘python’ in categories, say. Sqllite full-text searches are reasonably fast. You don’t get the performance benefits of one-to-many relationship queries, but if you’re in a performance critical environment, you should probably be looking at a ‘real’ SQL server anyway.

When the data is returned from sqllite, if you use the ‘get’ function in the DictLiteStore module, it will re-convert jsonified values (say that ‘categories’ list) back into a python list. This is quite useful. :-)

DictLiteStore was initially just an experiment for a later part of marlinespike’s cacheing system, but as a stand-alone module, is useful for many data storage systems.

Usage:

Take a dict of data:

foo = {'title': 'Foo the first', 'dict':'Bar Bar Bar'}

with DictLiteStore('data.db', 'table_of_random_stuff') as bucket:
    bucket.store(foo)

Now the dictionary ‘foo’ is stored as a row in data.db You can either use SQLlite queries directly to access the data, or there is a very simple SELECT wrapper which can be helpful for simple stuff:

bucket.get(('title','LIKE',NoJSON('%Foo%')))

returns

[{'title':'Foo the first','dict':'Bar Bar Bar'}]

To update the table, you also use the update() method:

bucket.update({'title':'updated title'})

would update all rows to have the new title. We can use the ‘where’ clause like in get to limit the damage:

bucket.update({'title': 'updated title'},
              True,
              ('title', '==', 'old title'))

What’s that random ‘True’ there for, you want to know?

The update method needs to know if you want it to write the dict (insert it) into the table if the where clause fails. If you want to ONLY update, and not insert if there is no matching row, then run update like this:

bucket.update({'title':'updated title'},
              False,
              ('title','==','old title'))

Notes:

  • All data is serialised into json before writing, and deserialised on the way out. This means strings do get extra quotes around them. There could be a way to do this better, but I’m not quite sure of the most efficient. (Try and deserialise, if it doesn’t work, leave as string? Too many false positives, I’d have thought…)
  • All non-jsonable data is stringified first, and then json’d.
  • Currenly very little error-checking happens. Before production, this needs a lot of shoring-up around the edges.
  • I need to do some performance experiments! How well does this actually work, speed wise?
Release History

Release History

0.9.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
DictLiteStore-0.9.3.tar.gz (7.0 kB) Copy SHA256 Checksum SHA256 Source Oct 15, 2013

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