



Search — datastore 0.3.0 documentation

### Navigation

* [index](genindex.html "General Index")

* [modules](py-modindex.html "Python Module Index") |

* [datastore 0.3.0 documentation](index.html) »

Search

======

 Please activate JavaScript to enable the search

 functionality.

 

 From here you can search these documents. Enter your search

 words into the box below and click "search". Note that the search

 function will automatically search for all of the words. Pages

 containing fewer words won't appear in the result list.

 

### This Page

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/search.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/search.rst)

### Navigation

* [index](genindex.html "General Index")

* [modules](py-modindex.html "Python Module Index") |

* [datastore 0.3.0 documentation](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Index — datastore 0.3.0 documentation

### Navigation

* [index](# "General Index")

* [modules](py-modindex.html "Python Module Index") |

* [datastore 0.3.0 documentation](index.html) »

Index

=====

[**A**](#A)

 | [**C**](#C)

 | [**D**](#D)

 | [**E**](#E)

 | [**F**](#F)

 | [**G**](#G)

 | [**I**](#I)

 | [**K**](#K)

 | [**L**](#L)

 | [**M**](#M)

 | [**N**](#N)

 | [**O**](#O)

 | [**P**](#P)

 | [**Q**](#Q)

 | [**R**](#R)

 | [**S**](#S)

 | [**T**](#T)

 | [**V**](#V)

A

-

|  |  |

| --- | --- |

| 

[appendDatastore() (datastore.core.basic.DatastoreCollection method)](package/datastore.core.html#datastore.core.basic.DatastoreCollection.appendDatastore)

[apply\_filter() (datastore.core.query.Cursor method)](package/datastore.core.html#datastore.core.query.Cursor.apply_filter)

[apply\_limit() (datastore.core.query.Cursor method)](package/datastore.core.html#datastore.core.query.Cursor.apply_limit)

 | 

[apply\_offset() (datastore.core.query.Cursor method)](package/datastore.core.html#datastore.core.query.Cursor.apply_offset)

[apply\_order() (datastore.core.query.Cursor method)](package/datastore.core.html#datastore.core.query.Cursor.apply_order)

 |

C

-

|  |  |

| --- | --- |

| 

[CacheShimDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.CacheShimDatastore)

[chain\_gen() (in module datastore.core.query)](package/datastore.core.html#datastore.core.query.chain_gen)

[child() (datastore.core.key.Key method)](package/datastore.core.html#datastore.core.key.Key.child)

[conditional\_operators (datastore.core.query.Filter attribute)](package/datastore.core.html#datastore.core.query.Filter.conditional_operators)

 | 

[contains() (datastore.core.basic.CacheShimDatastore method)](package/datastore.core.html#datastore.core.basic.CacheShimDatastore.contains)

[(datastore.core.basic.Datastore method)](package/datastore.core.html#datastore.core.basic.Datastore.contains)

[(datastore.core.basic.DictDatastore method)](package/datastore.core.html#datastore.core.basic.DictDatastore.contains)

[(datastore.core.basic.KeyTransformDatastore method)](package/datastore.core.html#datastore.core.basic.KeyTransformDatastore.contains)

[(datastore.core.basic.LoggingDatastore method)](package/datastore.core.html#datastore.core.basic.LoggingDatastore.contains)

[(datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.contains)

[(datastore.core.basic.TieredDatastore method)](package/datastore.core.html#datastore.core.basic.TieredDatastore.contains)

[(datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.contains)

[copy() (datastore.core.query.Query method)](package/datastore.core.html#datastore.core.query.Query.copy)

[Cursor (class in datastore.core.query)](package/datastore.core.html#datastore.core.query.Cursor)

 |

D

-

|  |  |

| --- | --- |

| 

[Datastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.Datastore)

[datastore() (datastore.core.basic.DatastoreCollection method)](package/datastore.core.html#datastore.core.basic.DatastoreCollection.datastore)

[datastore.core.\_\_init\_\_ (module)](package/datastore.core.html#module-datastore.core.__init__)

[datastore.core.basic (module)](package/datastore.core.html#module-datastore.core.basic)

[datastore.core.key (module)](package/datastore.core.html#module-datastore.core.key)

[datastore.core.query (module)](package/datastore.core.html#module-datastore.core.query)

[datastore.core.serialize (module)](package/datastore.core.html#module-datastore.core.serialize)

[datastore.filesystem (module)](package/datastore.filesystem.html#module-datastore.filesystem)

[DatastoreCollection (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.DatastoreCollection)

 | 

[delete() (datastore.core.basic.CacheShimDatastore method)](package/datastore.core.html#datastore.core.basic.CacheShimDatastore.delete)

[(datastore.core.basic.Datastore method)](package/datastore.core.html#datastore.core.basic.Datastore.delete)

[(datastore.core.basic.DictDatastore method)](package/datastore.core.html#datastore.core.basic.DictDatastore.delete)

[(datastore.core.basic.DirectoryDatastore method)](package/datastore.core.html#datastore.core.basic.DirectoryDatastore.delete)

[(datastore.core.basic.InterfaceMappingDatastore method)](package/datastore.core.html#datastore.core.basic.InterfaceMappingDatastore.delete)

[(datastore.core.basic.KeyTransformDatastore method)](package/datastore.core.html#datastore.core.basic.KeyTransformDatastore.delete)

[(datastore.core.basic.LoggingDatastore method)](package/datastore.core.html#datastore.core.basic.LoggingDatastore.delete)

[(datastore.core.basic.NullDatastore method)](package/datastore.core.html#datastore.core.basic.NullDatastore.delete)

[(datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.delete)

[(datastore.core.basic.ShimDatastore method)](package/datastore.core.html#datastore.core.basic.ShimDatastore.delete)

[(datastore.core.basic.TieredDatastore method)](package/datastore.core.html#datastore.core.basic.TieredDatastore.delete)

[(datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.delete)

[deserialized\_gen() (in module datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.deserialized_gen)

[deserializedValue() (datastore.core.serialize.SerializerShimDatastore method)](package/datastore.core.html#datastore.core.serialize.SerializerShimDatastore.deserializedValue)

[dict() (datastore.core.query.Query method)](package/datastore.core.html#datastore.core.query.Query.dict)

[DictDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.DictDatastore)

[directory() (datastore.core.basic.DirectoryDatastore method)](package/datastore.core.html#datastore.core.basic.DirectoryDatastore.directory)

[directory\_values\_generator() (datastore.core.basic.DirectoryDatastore method)](package/datastore.core.html#datastore.core.basic.DirectoryDatastore.directory_values_generator)

[DirectoryDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.DirectoryDatastore)

[dumps() (datastore.core.serialize.map\_serializer class method)](package/datastore.core.html#datastore.core.serialize.map_serializer.dumps)

[(datastore.core.serialize.NonSerializer class method)](package/datastore.core.html#datastore.core.serialize.NonSerializer.dumps)

[(datastore.core.serialize.Serializer class method)](package/datastore.core.html#datastore.core.serialize.Serializer.dumps)

[(datastore.core.serialize.Stack method)](package/datastore.core.html#datastore.core.serialize.Stack.dumps)

[(datastore.core.serialize.prettyjson class method)](package/datastore.core.html#datastore.core.serialize.prettyjson.dumps)

 |

E

-

|  |

| --- |

| 

[ensure\_directory\_exists() (in module datastore.filesystem)](package/datastore.filesystem.html#datastore.filesystem.ensure_directory_exists)

 |

F

-

|  |  |

| --- | --- |

| 

[field (datastore.core.key.Namespace attribute)](package/datastore.core.html#datastore.core.key.Namespace.field)

[FileSystemDatastore (class in datastore.filesystem)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore)

[Filter (class in datastore.core.query)](package/datastore.core.html#datastore.core.query.Filter)

 | 

[filter() (datastore.core.query.Filter class method)](package/datastore.core.html#datastore.core.query.Filter.filter)

[(datastore.core.query.Query method)](package/datastore.core.html#datastore.core.query.Query.filter)

[from\_dict() (datastore.core.query.Query class method)](package/datastore.core.html#datastore.core.query.Query.from_dict)

 |

G

-

|  |  |

| --- | --- |

| 

[generator() (datastore.core.query.Filter method)](package/datastore.core.html#datastore.core.query.Filter.generator)

 | 

[get() (datastore.core.basic.CacheShimDatastore method)](package/datastore.core.html#datastore.core.basic.CacheShimDatastore.get)

[(datastore.core.basic.Datastore method)](package/datastore.core.html#datastore.core.basic.Datastore.get)

[(datastore.core.basic.DictDatastore method)](package/datastore.core.html#datastore.core.basic.DictDatastore.get)

[(datastore.core.basic.InterfaceMappingDatastore method)](package/datastore.core.html#datastore.core.basic.InterfaceMappingDatastore.get)

[(datastore.core.basic.KeyTransformDatastore method)](package/datastore.core.html#datastore.core.basic.KeyTransformDatastore.get)

[(datastore.core.basic.LoggingDatastore method)](package/datastore.core.html#datastore.core.basic.LoggingDatastore.get)

[(datastore.core.basic.NullDatastore method)](package/datastore.core.html#datastore.core.basic.NullDatastore.get)

[(datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.get)

[(datastore.core.basic.ShimDatastore method)](package/datastore.core.html#datastore.core.basic.ShimDatastore.get)

[(datastore.core.basic.SymlinkDatastore method)](package/datastore.core.html#datastore.core.basic.SymlinkDatastore.get)

[(datastore.core.basic.TieredDatastore method)](package/datastore.core.html#datastore.core.basic.TieredDatastore.get)

[(datastore.core.serialize.SerializerShimDatastore method)](package/datastore.core.html#datastore.core.serialize.SerializerShimDatastore.get)

[(datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.get)

 |

I

-

|  |  |

| --- | --- |

| 

[ignore\_list (datastore.filesystem.FileSystemDatastore attribute)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.ignore_list)

[implements\_serializer\_interface() (datastore.core.serialize.Serializer static method)](package/datastore.core.html#datastore.core.serialize.Serializer.implements_serializer_interface)

[insertDatastore() (datastore.core.basic.DatastoreCollection method)](package/datastore.core.html#datastore.core.basic.DatastoreCollection.insertDatastore)

[instance() (datastore.core.key.Key method)](package/datastore.core.html#datastore.core.key.Key.instance)

[InterfaceMappingDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.InterfaceMappingDatastore)

[is\_iterable() (in module datastore.core.query)](package/datastore.core.html#datastore.core.query.is_iterable)

 | 

[isAncestorOf() (datastore.core.key.Key method)](package/datastore.core.html#datastore.core.key.Key.isAncestorOf)

[isAscending() (datastore.core.query.Order method)](package/datastore.core.html#datastore.core.query.Order.isAscending)

[isDescendantOf() (datastore.core.key.Key method)](package/datastore.core.html#datastore.core.key.Key.isDescendantOf)

[isDescending() (datastore.core.query.Order method)](package/datastore.core.html#datastore.core.query.Order.isDescending)

[isTopLevel() (datastore.core.key.Key method)](package/datastore.core.html#datastore.core.key.Key.isTopLevel)

 |

K

-

|  |  |

| --- | --- |

| 

[Key (class in datastore.core.key)](package/datastore.core.html#datastore.core.key.Key)

[keyfn() (datastore.core.query.Order method)](package/datastore.core.html#datastore.core.query.Order.keyfn)

 | 

[KeyTransformDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.KeyTransformDatastore)

 |

L

-

|  |  |

| --- | --- |

| 

[limit\_gen() (in module datastore.core.query)](package/datastore.core.html#datastore.core.query.limit_gen)

[link() (datastore.core.basic.SymlinkDatastore method)](package/datastore.core.html#datastore.core.basic.SymlinkDatastore.link)

[list (datastore.core.key.Key attribute)](package/datastore.core.html#datastore.core.key.Key.list)

[loads() (datastore.core.serialize.map\_serializer class method)](package/datastore.core.html#datastore.core.serialize.map_serializer.loads)

[(datastore.core.serialize.NonSerializer class method)](package/datastore.core.html#datastore.core.serialize.NonSerializer.loads)

[(datastore.core.serialize.Serializer class method)](package/datastore.core.html#datastore.core.serialize.Serializer.loads)

[(datastore.core.serialize.Stack method)](package/datastore.core.html#datastore.core.serialize.Stack.loads)

[(datastore.core.serialize.prettyjson class method)](package/datastore.core.html#datastore.core.serialize.prettyjson.loads)

 | 

[LoggingDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.LoggingDatastore)

[lowercaseKey() (datastore.core.basic.LowercaseKeyDatastore class method)](package/datastore.core.html#datastore.core.basic.LowercaseKeyDatastore.lowercaseKey)

[LowercaseKeyDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.LowercaseKeyDatastore)

 |

M

-

|  |  |

| --- | --- |

| 

[map\_serializer (class in datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.map_serializer)

[monkey\_patch\_bson() (in module datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.monkey_patch_bson)

 | 

[multipleOrderComparison() (datastore.core.query.Order class method)](package/datastore.core.html#datastore.core.query.Order.multipleOrderComparison)

 |

N

-

|  |  |

| --- | --- |

| 

[name (datastore.core.key.Key attribute)](package/datastore.core.html#datastore.core.key.Key.name)

[Namespace (class in datastore.core.key)](package/datastore.core.html#datastore.core.key.Namespace)

[namespace\_delimiter (datastore.core.key.Namespace attribute)](package/datastore.core.html#datastore.core.key.Namespace.namespace_delimiter)

[NamespaceDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.NamespaceDatastore)

[namespaceKey() (datastore.core.basic.NamespaceDatastore method)](package/datastore.core.html#datastore.core.basic.NamespaceDatastore.namespaceKey)

[namespaces (datastore.core.key.Key attribute)](package/datastore.core.html#datastore.core.key.Key.namespaces)

 | 

[nestedPath() (datastore.core.basic.NestedPathDatastore static method)](package/datastore.core.html#datastore.core.basic.NestedPathDatastore.nestedPath)

[NestedPathDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.NestedPathDatastore)

[nestKey() (datastore.core.basic.NestedPathDatastore method)](package/datastore.core.html#datastore.core.basic.NestedPathDatastore.nestKey)

[next() (datastore.core.query.Cursor method)](package/datastore.core.html#datastore.core.query.Cursor.next)

[NonSerializer (class in datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.NonSerializer)

[NullDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.NullDatastore)

 |

O

-

|  |  |

| --- | --- |

| 

[object\_extension (datastore.filesystem.FileSystemDatastore attribute)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.object_extension)

[object\_getattr() (datastore.core.query.Filter static method)](package/datastore.core.html#datastore.core.query.Filter.object_getattr)

[(datastore.core.query.Order static method)](package/datastore.core.html#datastore.core.query.Order.object_getattr)

[(datastore.core.query.Query static method)](package/datastore.core.html#datastore.core.query.Query.object_getattr)

[object\_path() (datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.object_path)

[offset\_gen() (in module datastore.core.query)](package/datastore.core.html#datastore.core.query.offset_gen)

 | 

[Order (class in datastore.core.query)](package/datastore.core.html#datastore.core.query.Order)

[order() (datastore.core.query.Query method)](package/datastore.core.html#datastore.core.query.Query.order)

[order\_operators (datastore.core.query.Order attribute)](package/datastore.core.html#datastore.core.query.Order.order_operators)

 |

P

-

|  |  |

| --- | --- |

| 

[parent (datastore.core.key.Key attribute)](package/datastore.core.html#datastore.core.key.Key.parent)

[path (datastore.core.key.Key attribute)](package/datastore.core.html#datastore.core.key.Key.path)

[path() (datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.path)

 | 

[prettyjson (class in datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.prettyjson)

[put() (datastore.core.basic.CacheShimDatastore method)](package/datastore.core.html#datastore.core.basic.CacheShimDatastore.put)

[(datastore.core.basic.Datastore method)](package/datastore.core.html#datastore.core.basic.Datastore.put)

[(datastore.core.basic.DictDatastore method)](package/datastore.core.html#datastore.core.basic.DictDatastore.put)

[(datastore.core.basic.DirectoryDatastore method)](package/datastore.core.html#datastore.core.basic.DirectoryDatastore.put)

[(datastore.core.basic.InterfaceMappingDatastore method)](package/datastore.core.html#datastore.core.basic.InterfaceMappingDatastore.put)

[(datastore.core.basic.KeyTransformDatastore method)](package/datastore.core.html#datastore.core.basic.KeyTransformDatastore.put)

[(datastore.core.basic.LoggingDatastore method)](package/datastore.core.html#datastore.core.basic.LoggingDatastore.put)

[(datastore.core.basic.NullDatastore method)](package/datastore.core.html#datastore.core.basic.NullDatastore.put)

[(datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.put)

[(datastore.core.basic.ShimDatastore method)](package/datastore.core.html#datastore.core.basic.ShimDatastore.put)

[(datastore.core.basic.SymlinkDatastore method)](package/datastore.core.html#datastore.core.basic.SymlinkDatastore.put)

[(datastore.core.basic.TieredDatastore method)](package/datastore.core.html#datastore.core.basic.TieredDatastore.put)

[(datastore.core.serialize.SerializerShimDatastore method)](package/datastore.core.html#datastore.core.serialize.SerializerShimDatastore.put)

[(datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.put)

 |

Q

-

|  |  |

| --- | --- |

| 

[Query (class in datastore.core.query)](package/datastore.core.html#datastore.core.query.Query)

[query (datastore.core.query.Cursor attribute)](package/datastore.core.html#datastore.core.query.Cursor.query)

 | 

[query() (datastore.core.basic.Datastore method)](package/datastore.core.html#datastore.core.basic.Datastore.query)

[(datastore.core.basic.DictDatastore method)](package/datastore.core.html#datastore.core.basic.DictDatastore.query)

[(datastore.core.basic.DirectoryDatastore method)](package/datastore.core.html#datastore.core.basic.DirectoryDatastore.query)

[(datastore.core.basic.KeyTransformDatastore method)](package/datastore.core.html#datastore.core.basic.KeyTransformDatastore.query)

[(datastore.core.basic.LoggingDatastore method)](package/datastore.core.html#datastore.core.basic.LoggingDatastore.query)

[(datastore.core.basic.NestedPathDatastore method)](package/datastore.core.html#datastore.core.basic.NestedPathDatastore.query)

[(datastore.core.basic.NullDatastore method)](package/datastore.core.html#datastore.core.basic.NullDatastore.query)

[(datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.query)

[(datastore.core.basic.ShimDatastore method)](package/datastore.core.html#datastore.core.basic.ShimDatastore.query)

[(datastore.core.basic.SymlinkDatastore method)](package/datastore.core.html#datastore.core.basic.SymlinkDatastore.query)

[(datastore.core.basic.TieredDatastore method)](package/datastore.core.html#datastore.core.basic.TieredDatastore.query)

[(datastore.core.serialize.SerializerShimDatastore method)](package/datastore.core.html#datastore.core.serialize.SerializerShimDatastore.query)

[(datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.query)

 |

R

-

|  |  |

| --- | --- |

| 

[randomKey() (datastore.core.key.Key class method)](package/datastore.core.html#datastore.core.key.Key.randomKey)

[relative\_object\_path() (datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.relative_object_path)

[relative\_path() (datastore.filesystem.FileSystemDatastore method)](package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore.relative_path)

[removeDatastore() (datastore.core.basic.DatastoreCollection method)](package/datastore.core.html#datastore.core.basic.DatastoreCollection.removeDatastore)

 | 

[removeDuplicateSlashes() (datastore.core.key.Key class method)](package/datastore.core.html#datastore.core.key.Key.removeDuplicateSlashes)

[returned (datastore.core.query.Cursor attribute)](package/datastore.core.html#datastore.core.query.Cursor.returned)

[reverse (datastore.core.key.Key attribute)](package/datastore.core.html#datastore.core.key.Key.reverse)

 |

S

-

|  |  |

| --- | --- |

| 

[sentinel (datastore.core.basic.SymlinkDatastore attribute)](package/datastore.core.html#datastore.core.basic.SymlinkDatastore.sentinel)

[(datastore.core.serialize.map\_serializer attribute)](package/datastore.core.html#datastore.core.serialize.map_serializer.sentinel)

[serialized\_gen() (in module datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.serialized_gen)

[serializedValue() (datastore.core.serialize.SerializerShimDatastore method)](package/datastore.core.html#datastore.core.serialize.SerializerShimDatastore.serializedValue)

[Serializer (class in datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.Serializer)

[serializer (datastore.core.serialize.SerializerShimDatastore attribute)](package/datastore.core.html#datastore.core.serialize.SerializerShimDatastore.serializer)

[SerializerShimDatastore (class in datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.SerializerShimDatastore)

[shard() (datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.shard)

[shard\_query\_generator() (datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.shard_query_generator)

 | 

[shardDatastore() (datastore.core.basic.ShardedDatastore method)](package/datastore.core.html#datastore.core.basic.ShardedDatastore.shardDatastore)

[ShardedDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.ShardedDatastore)

[shim() (in module datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.shim)

[ShimDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.ShimDatastore)

[skipped (datastore.core.query.Cursor attribute)](package/datastore.core.html#datastore.core.query.Cursor.skipped)

[sorted() (datastore.core.query.Order class method)](package/datastore.core.html#datastore.core.query.Order.sorted)

[Stack (class in datastore.core.serialize)](package/datastore.core.html#datastore.core.serialize.Stack)

[SymlinkDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.SymlinkDatastore)

 |

T

-

|  |  |

| --- | --- |

| 

[TieredDatastore (class in datastore.core.basic)](package/datastore.core.html#datastore.core.basic.TieredDatastore)

 | 

[type (datastore.core.key.Key attribute)](package/datastore.core.html#datastore.core.key.Key.type)

 |

V

-

|  |  |

| --- | --- |

| 

[value (datastore.core.key.Namespace attribute)](package/datastore.core.html#datastore.core.key.Namespace.value)

 | 

[valuePasses() (datastore.core.query.Filter method)](package/datastore.core.html#datastore.core.query.Filter.valuePasses)

 |

### This Page

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/genindex.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/genindex.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](# "General Index")

* [modules](py-modindex.html "Python Module Index") |

* [datastore 0.3.0 documentation](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





datastore - simple, unified API for multiple data stores — datastore 0.3.0 documentation

### Navigation

* [index](genindex.html "General Index")

* [modules](py-modindex.html "Python Module Index") |

* [next](api/index.html "Core datastore API") |

* [datastore 0.3.0 documentation](#) »

datastore - simple, unified API for multiple data stores[¶](#datastore-simple-unified-api-for-multiple-data-stores "Permalink to this headline")

================================================================================================================================================

Overview[¶](#overview "Permalink to this headline")

---------------------------------------------------

datastore is a generic layer of abstraction for data store and database access.

It is a **simple** API with the aim to enable application development in a

datastore-agnostic way, allowing datastores to be swapped seamlessly without

changing application code. Thus, one can leverage different datastores with

different strengths without committing the application to one datastore

throughout its lifetime.

In addition, grouped datastores significantly simplify complex data access

patterns, such as caching and sharding.

Documentation[¶](#documentation "Permalink to this headline")

-------------------------------------------------------------

The [*Core datastore API*](api/index.html#api) contains documentation of the core library.

* [Core datastore API](api/index.html)

	+ [Keys](api/key.html)

	+ [Queries](api/query.html)

	+ [Basic Datastores](api/basic.html)

	+ [Shims](api/shims.html)

	+ [Collections](api/collections.html)

	+ [Serialize](api/serialize.html)

	+ [datastore base class](api/index.html#datastore-base-class)

	+ [Examples](api/index.html#examples)

Package Hierarchy:

* [datastore Package](package/datastore.html)

	+ [Subpackages](package/datastore.html#subpackages)

		- [datastore.core](package/datastore.core.html)

			* [datastore.basic](package/datastore.core.html#module-datastore.core.basic)

			* [datastore.key](package/datastore.core.html#module-datastore.core.key)

			* [datastore.query](package/datastore.core.html#module-datastore.core.query)

			* [datastore.serialize](package/datastore.core.html#module-datastore.core.serialize)

		- [datastore.core.util](package/datastore.util.html)

			* [datastore.core.util.fasthash](package/datastore.util.html#datastore-core-util-fasthash)

		- [datastore.filesystem](package/datastore.filesystem.html)

Install[¶](#install "Permalink to this headline")

-------------------------------------------------

From pypi (using pip):

```

sudo pip install datastore

```

From pypi (using setuptools):

```

sudo easy_install datastore

```

From source:

```

git clone https://github.com/jbenet/datastore/

cd datastore

sudo python setup.py install

```

### License[¶](#license "Permalink to this headline")

datastore is under the MIT Licence

### Contact[¶](#contact "Permalink to this headline")

datastore is written by [Juan Batiz-Benet](<https://github.com/jbenet>). It

was originally part of

[`py-dronestore<https://github.com/jbenet/py-dronestore>`\_](#id1)

On December 2011, it was re-written as a standalone project.

Project Homepage: <https://github.com/jbenet/datastore>

Feel free to contact me. But please file issues in github first. Cheers!

Indices and tables[¶](#indices-and-tables "Permalink to this headline")

-----------------------------------------------------------------------

* [*Index*](genindex.html)

* [*Module Index*](py-modindex.html)

* [*Search Page*](search.html)

Hello Worlds[¶](#hello-worlds "Permalink to this headline")

-----------------------------------------------------------

To illustrate the api and how it works across different data storage systems,

here is Hello World in various datastores. Note the common code.

### Hello Dict[¶](#hello-dict "Permalink to this headline")

```

>>> import datastore.core

>>>

>>> ds = datastore.DictDatastore()

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

### Hello filesystem[¶](#hello-filesystem "Permalink to this headline")

```

>>> import datastore.filesystem

>>>

>>> ds = datastore.filesystem.FileSystemDatastore('/tmp/.test\_datastore')

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

### Hello Serialization[¶](#hello-serialization "Permalink to this headline")

```

>>> import datastore.core

>>> import json

>>>

>>> ds\_child = datastore.DictDatastore()

>>> ds = datastore.serialize.shim(ds\_child, json)

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

### Hello Tiered Access[¶](#hello-tiered-access "Permalink to this headline")

```

>>> import pymongo

>>> import datastore.core

>>>

>>> from datastore.mongo import MongoDatastore

>>> from datastore.pylru import LRUCacheDatastore

>>> from datastore.filesystem import FileSystemDatastore

>>>

>>> conn = pymongo.Connection()

>>> mongo = MongoDatastore(conn.test\_db)

>>>

>>> cache = LRUCacheDatastore(1000)

>>> fs = FileSystemDatastore('/tmp/.test\_db')

>>>

>>> ds = datastore.TieredDatastore([cache, mongo, fs])

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

### Hello Sharding[¶](#hello-sharding "Permalink to this headline")

```

>>> import datastore.core

>>>

>>> shards = [datastore.DictDatastore() for i in range(0, 10)]

>>>

>>> ds = datastore.ShardedDatastore(shards)

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

### [Table Of Contents](#)

* [datastore - simple, unified API for multiple data stores](#)

	+ [Overview](#overview)

	+ [Documentation](#documentation)

	+ [Install](#install)

		- [License](#license)

		- [Contact](#contact)

	+ [Indices and tables](#indices-and-tables)

	+ [Hello Worlds](#hello-worlds)

		- [Hello Dict](#hello-dict)

		- [Hello filesystem](#hello-filesystem)

		- [Hello Serialization](#hello-serialization)

		- [Hello Tiered Access](#hello-tiered-access)

		- [Hello Sharding](#hello-sharding)

#### Next topic

[Core datastore API](api/index.html "next chapter")

### This Page

* [Show Source](_sources/index.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/index.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/index.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](genindex.html "General Index")

* [modules](py-modindex.html "Python Module Index") |

* [next](api/index.html "Core datastore API") |

* [datastore 0.3.0 documentation](#) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Python Module Index — datastore 0.3.0 documentation

### Navigation

* [index](genindex.html "General Index")

* [modules](# "Python Module Index") |

* [datastore 0.3.0 documentation](index.html) »

Python Module Index

===================

[**d**](#cap-d)

|  |  |  |

| --- | --- | --- |

|  |  |  |

|  | **d** |  |

| - | datastore |  |

|  | [datastore.core.\_\_init\_\_](package/datastore.core.html#module-datastore.core.__init__) |  |

|  | [datastore.core.basic](package/datastore.core.html#module-datastore.core.basic) |  |

|  | [datastore.core.key](package/datastore.core.html#module-datastore.core.key) |  |

|  | [datastore.core.query](package/datastore.core.html#module-datastore.core.query) |  |

|  | [datastore.core.serialize](package/datastore.core.html#module-datastore.core.serialize) |  |

|  | [datastore.filesystem](package/datastore.filesystem.html#module-datastore.filesystem) |  |

### This Page

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/py-modindex.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/py-modindex.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](genindex.html "General Index")

* [modules](# "Python Module Index") |

* [datastore 0.3.0 documentation](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





datastore — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [datastore 0.3.0 documentation](../index.html) »

datastore[¶](#datastore "Permalink to this headline")

=====================================================

* [datastore Package](datastore.html)

	+ [Subpackages](datastore.html#subpackages)

		- [datastore.core](datastore.core.html)

			* [datastore.basic](datastore.core.html#module-datastore.core.basic)

			* [datastore.key](datastore.core.html#module-datastore.core.key)

			* [datastore.query](datastore.core.html#module-datastore.core.query)

			* [datastore.serialize](datastore.core.html#module-datastore.core.serialize)

		- [datastore.core.util](datastore.util.html)

			* [datastore.core.util.fasthash](datastore.util.html#datastore-core-util-fasthash)

		- [datastore.filesystem](datastore.filesystem.html)

### This Page

* [Show Source](../_sources/package/modules.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/package/modules.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/package/modules.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [datastore 0.3.0 documentation](../index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





datastore.core.util — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](datastore.filesystem.html "datastore.filesystem") |

* [previous](datastore.core.html "datastore.core") |

* [datastore 0.3.0 documentation](../index.html) »

* [datastore Package](datastore.html) »

datastore.core.util[¶](#datastore-core-util "Permalink to this headline")

=========================================================================

datastore.core.util.fasthash[¶](#datastore-core-util-fasthash "Permalink to this headline")

-------------------------------------------------------------------------------------------

### [Table Of Contents](../index.html)

* [datastore.core.util](#)

	+ [datastore.core.util.fasthash](#datastore-core-util-fasthash)

#### Previous topic

[datastore.core](datastore.core.html "previous chapter")

#### Next topic

[datastore.filesystem](datastore.filesystem.html "next chapter")

### This Page

* [Show Source](../_sources/package/datastore.util.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/package/datastore.util.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/package/datastore.util.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](datastore.filesystem.html "datastore.filesystem") |

* [previous](datastore.core.html "datastore.core") |

* [datastore 0.3.0 documentation](../index.html) »

* [datastore Package](datastore.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





datastore.filesystem — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [previous](datastore.util.html "datastore.core.util") |

* [datastore 0.3.0 documentation](../index.html) »

* [datastore Package](datastore.html) »

datastore.filesystem[¶](#module-datastore.filesystem "Permalink to this headline")

==================================================================================

filesystem datastore implementation.

Tested with:

* Journaled HFS+ (Mac OS X 10.7.2)

*class* datastore.filesystem.FileSystemDatastore(*root*, *case\_sensitive=True*)[¶](#datastore.filesystem.FileSystemDatastore "Permalink to this definition")

Bases: [datastore.core.basic.Datastore](datastore.core.html#datastore.core.basic.Datastore "datastore.core.basic.Datastore")

Simple flat-file datastore.

FileSystemDatastore will store objects in independent files in the host’s

filesystem. The FileSystemDatastore is initialized with a root path, under

which to store all objects. Each object will be stored under its own file:

root/key.obj

The key portion also replaces namespace parameter delimiters (:) with

slashes, creating several nested directories. For example, storing objects

under root path ‘/data’ with the following keys:

```

Key('/Comedy:MontyPython/Actor:JohnCleese')

Key('/Comedy:MontyPython/Sketch:ArgumentClinic')

Key('/Comedy:MontyPython/Sketch:CheeseShop')

Key('/Comedy:MontyPython/Sketch:CheeseShop/Character:Mousebender')

```

will yield the file structure:

```

/data/Comedy/MontyPython/Actor/JohnCleese.obj

/data/Comedy/MontyPython/Sketch/ArgumentClinic.obj

/data/Comedy/MontyPython/Sketch/CheeseShop.obj

/data/Comedy/MontyPython/Sketch/CheeseShop/Character/Mousebender.obj

```

Implementation Notes:

> 

> Separating key namespaces (and their parameters) within directories allows

> granular querying for under a specific key. For example, a query with key:

> 

> 

> 

> ```

> Key('/data/Comedy:MontyPython/Sketch:CheeseShop')

> 

> ```

> 

> 

> will query for all objects under Sketch:CheeseShop independently of

> queries for:

> 

> 

> 

> ```

> Key('/data/Comedy:MontyPython/Sketch')

> 

> ```

> 

> 

> Also, using the .obj extension gets around the ambiguity of having both a

> CheeseShop object and directory:

> 

> 

> 

> ```

> /data/Comedy/MontyPython/Sketch/CheeseShop.obj

> /data/Comedy/MontyPython/Sketch/CheeseShop/

> ```

> 

> 

> 

Hello World:

```

>>> import datastore.filesystem

>>>

>>> ds = datastore.filesystem.FileSystemDatastore('/tmp/.test\_datastore')

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

contains(*key*)[¶](#datastore.filesystem.FileSystemDatastore.contains "Permalink to this definition")

Returns whether the object named by key exists.

Optimized to only check whether the file object exists.

Args:

key: Key naming the object to check.

Returns:

boalean whether the object exists

delete(*key*)[¶](#datastore.filesystem.FileSystemDatastore.delete "Permalink to this definition")

Removes the object named by key.

Args:

key: Key naming the object to remove.

get(*key*)[¶](#datastore.filesystem.FileSystemDatastore.get "Permalink to this definition")

Return the object named by key or None if it does not exist.

Args:

key: Key naming the object to retrieve

Returns:

object or None

ignore\_list *= []*[¶](#datastore.filesystem.FileSystemDatastore.ignore_list "Permalink to this definition")

object\_extension *= '.obj'*[¶](#datastore.filesystem.FileSystemDatastore.object_extension "Permalink to this definition")

object\_path(*key*)[¶](#datastore.filesystem.FileSystemDatastore.object_path "Permalink to this definition")

return the object path for key.

path(*key*)[¶](#datastore.filesystem.FileSystemDatastore.path "Permalink to this definition")

Returns the path for given key

put(*key*, *value*)[¶](#datastore.filesystem.FileSystemDatastore.put "Permalink to this definition")

Stores the object value named by key.

Args:

key: Key naming value

value: the object to store.

query(*query*)[¶](#datastore.filesystem.FileSystemDatastore.query "Permalink to this definition")

Returns an iterable of objects matching criteria expressed in query

FSDatastore.query queries all the .obj files within the directory

specified by the query.key.

Args:

query: Query object describing the objects to return.

Raturns:

Cursor with all objects matching criteria

relative\_object\_path(*key*)[¶](#datastore.filesystem.FileSystemDatastore.relative_object_path "Permalink to this definition")

Returns the relative path for object pointed by key.

relative\_path(*key*)[¶](#datastore.filesystem.FileSystemDatastore.relative_path "Permalink to this definition")

Returns the relative path for given key

datastore.filesystem.ensure\_directory\_exists(*directory*)[¶](#datastore.filesystem.ensure_directory_exists "Permalink to this definition")

Ensures directory exists. May make directory and intermediate dirs.

Raises RuntimeError if directory is a file.

#### Previous topic

[datastore.core.util](datastore.util.html "previous chapter")

### This Page

* [Show Source](../_sources/package/datastore.filesystem.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/package/datastore.filesystem.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/package/datastore.filesystem.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [previous](datastore.util.html "datastore.core.util") |

* [datastore 0.3.0 documentation](../index.html) »

* [datastore Package](datastore.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





datastore.core — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](datastore.util.html "datastore.core.util") |

* [previous](datastore.html "datastore Package") |

* [datastore 0.3.0 documentation](../index.html) »

* [datastore Package](datastore.html) »

datastore.core[¶](#datastore-core "Permalink to this headline")

===============================================================

The datastore.core package contains the core parts of datastore,

including the base Datastore classes, Key, serializers, collections, shims, etc.

The core package exists mainly because namespace packages cannot include

members.

datastore is a generic layer of abstraction for data store and database access.

It is a **simple** API with the aim to enable application development in a

datastore-agnostic way, allowing datastores to be swapped seamlessly without

changing application code. Thus, one can leverage different datastores with

different strengths without committing the application to one datastore

throughout its lifetime.

datastore.basic[¶](#module-datastore.core.basic "Permalink to this headline")

-----------------------------------------------------------------------------

*class* datastore.core.basic.CacheShimDatastore(*\*args*, *\*\*kwargs*)[¶](#datastore.core.basic.CacheShimDatastore "Permalink to this definition")

Bases: [datastore.core.basic.ShimDatastore](#datastore.core.basic.ShimDatastore "datastore.core.basic.ShimDatastore")

Wraps a datastore with a caching shim optimizes some calls.

contains(*key*)[¶](#datastore.core.basic.CacheShimDatastore.contains "Permalink to this definition")

Returns whether the object named by key exists.

First checks cache\_datastore.

delete(*key*)[¶](#datastore.core.basic.CacheShimDatastore.delete "Permalink to this definition")

Removes the object named by key.

Writes to both cache\_datastore and child\_datastore.

get(*key*)[¶](#datastore.core.basic.CacheShimDatastore.get "Permalink to this definition")

Return the object named by key or None if it does not exist.

CacheShimDatastore first checks its cache\_datastore.

put(*key*, *value*)[¶](#datastore.core.basic.CacheShimDatastore.put "Permalink to this definition")

Stores the object value named by key`self.

Writes to both ``cache\_datastore` and child\_datastore.

*class* datastore.core.basic.Datastore[¶](#datastore.core.basic.Datastore "Permalink to this definition")

Bases: object

A Datastore represents storage for any key-value pair.

Datastores are general enough to be backed by all kinds of different storage:

in-memory caches, databases, a remote datastore, flat files on disk, etc.

The general idea is to wrap a more complicated storage facility in a simple,

uniform interface, keeping the freedom of using the right tools for the job.

In particular, a Datastore can aggregate other datastores in interesting ways,

like sharded (to distribute load) or tiered access (caches before databases).

While Datastores should be written general enough to accept all sorts of

values, some implementations will undoubtedly have to be specific (e.g. SQL

databases where fields should be decomposed into columns), particularly to

support queries efficiently.

contains(*key*)[¶](#datastore.core.basic.Datastore.contains "Permalink to this definition")

Returns whether the object named by key exists.

The default implementation pays the cost of a get. Some datastore

implementations may optimize this.

Args:

key: Key naming the object to check.

Returns:

boalean whether the object exists

delete(*key*)[¶](#datastore.core.basic.Datastore.delete "Permalink to this definition")

Removes the object named by key.

Args:

key: Key naming the object to remove.

get(*key*)[¶](#datastore.core.basic.Datastore.get "Permalink to this definition")

Return the object named by key or None if it does not exist.

None takes the role of default value, so no KeyError exception is raised.

Args:

key: Key naming the object to retrieve

Returns:

object or None

put(*key*, *value*)[¶](#datastore.core.basic.Datastore.put "Permalink to this definition")

Stores the object value named by key.

How to serialize and store objects is up to the underlying datastore.

It is recommended to use simple objects (strings, numbers, lists, dicts).

Args:

key: Key naming value

value: the object to store.

query(*query*)[¶](#datastore.core.basic.Datastore.query "Permalink to this definition")

Returns an iterable of objects matching criteria expressed in query

Implementations of query will be the largest differentiating factor

amongst datastores. All datastores **must** implement query, even using

query’s worst case scenario, see [:ref:class:`Query`](#id1) for details.

Args:

query: Query object describing the objects to return.

Raturns:

iterable cursor with all objects matching criteria

*class* datastore.core.basic.DatastoreCollection(*stores=*[])[¶](#datastore.core.basic.DatastoreCollection "Permalink to this definition")

Bases: [datastore.core.basic.ShimDatastore](#datastore.core.basic.ShimDatastore "datastore.core.basic.ShimDatastore")

Represents a collection of datastores.

appendDatastore(*store*)[¶](#datastore.core.basic.DatastoreCollection.appendDatastore "Permalink to this definition")

Appends datastore store to this collection.

datastore(*index*)[¶](#datastore.core.basic.DatastoreCollection.datastore "Permalink to this definition")

Returns the datastore at index.

insertDatastore(*index*, *store*)[¶](#datastore.core.basic.DatastoreCollection.insertDatastore "Permalink to this definition")

Inserts datastore store into this collection at index.

removeDatastore(*store*)[¶](#datastore.core.basic.DatastoreCollection.removeDatastore "Permalink to this definition")

Removes datastore store from this collection.

*class* datastore.core.basic.DictDatastore[¶](#datastore.core.basic.DictDatastore "Permalink to this definition")

Bases: [datastore.core.basic.Datastore](#datastore.core.basic.Datastore "datastore.core.basic.Datastore")

Simple straw-man in-memory datastore backed by nested dicts.

contains(*key*)[¶](#datastore.core.basic.DictDatastore.contains "Permalink to this definition")

Returns whether the object named by key exists.

Checks for the object in the collection corresponding to key.path.

Args:

key: Key naming the object to check.

Returns:

boalean whether the object exists

delete(*key*)[¶](#datastore.core.basic.DictDatastore.delete "Permalink to this definition")

Removes the object named by key.

Removes the object from the collection corresponding to key.path.

Args:

key: Key naming the object to remove.

get(*key*)[¶](#datastore.core.basic.DictDatastore.get "Permalink to this definition")

Return the object named by key or None.

Retrieves the object from the collection corresponding to key.path.

Args:

key: Key naming the object to retrieve.

Returns:

object or None

put(*key*, *value*)[¶](#datastore.core.basic.DictDatastore.put "Permalink to this definition")

Stores the object value named by key.

Stores the object in the collection corresponding to key.path.

Args:

key: Key naming value

value: the object to store.

query(*query*)[¶](#datastore.core.basic.DictDatastore.query "Permalink to this definition")

Returns an iterable of objects matching criteria expressed in query

Naively applies the query operations on the objects within the namespaced

collection corresponding to query.key.path.

Args:

query: Query object describing the objects to return.

Raturns:

iterable cursor with all objects matching criteria

*class* datastore.core.basic.DirectoryDatastore(*datastore*)[¶](#datastore.core.basic.DirectoryDatastore "Permalink to this definition")

Bases: [datastore.core.basic.ShimDatastore](#datastore.core.basic.ShimDatastore "datastore.core.basic.ShimDatastore")

Datastore that tracks directory entries, like in a filesystem.

All key changes cause changes in a collection-like directory.

For example:

```

>>> import datastore.core

>>>

>>> dds = datastore.DictDatastore()

>>> rds = datastore.DirectoryDatastore(dds)

>>>

>>> a = datastore.Key('/A')

>>> b = datastore.Key('/A/B')

>>> c = datastore.Key('/A/C')

>>>

>>> rds.get(a)

[]

>>> rds.put(b, 1)

>>> rds.get(b)

1

>>> rds.get(a)

['/A/B']

>>> rds.put(c, 1)

>>> rds.get(c)

1

>>> rds.get(a)

['/A/B', '/A/C']

>>> rds.delete(b)

>>> rds.get(a)

['/A/C']

>>> rds.delete(c)

>>> rds.get(a)

[]

```

delete(*key*)[¶](#datastore.core.basic.DirectoryDatastore.delete "Permalink to this definition")

Removes the object named by key.

DirectoryDatastore removes the directory entry.

directory(*key*)[¶](#datastore.core.basic.DirectoryDatastore.directory "Permalink to this definition")

Retrieves directory entries for given key.

directory\_values\_generator(*key*)[¶](#datastore.core.basic.DirectoryDatastore.directory_values_generator "Permalink to this definition")

Retrieve directory values for given key.

put(*key*, *value*)[¶](#datastore.core.basic.DirectoryDatastore.put "Permalink to this definition")

Stores the object value named by [`](#id3)key`self.

DirectoryDatastore stores a directory entry.

query(*query*)[¶](#datastore.core.basic.DirectoryDatastore.query "Permalink to this definition")

Returns objects matching criteria expressed in query.

DirectoryDatastore uses directory entries.

*class* datastore.core.basic.InterfaceMappingDatastore(*service*, *get='get'*, *put='put'*, *delete='delete'*, *key=<type 'str'>*)[¶](#datastore.core.basic.InterfaceMappingDatastore "Permalink to this definition")

Bases: [datastore.core.basic.Datastore](#datastore.core.basic.Datastore "datastore.core.basic.Datastore")

Represents simple wrapper datastore around an object that, though not a

Datastore, implements data storage through a similar interface. For example,

memcached and redis both implement a get, set, delete interface.

delete(*key*)[¶](#datastore.core.basic.InterfaceMappingDatastore.delete "Permalink to this definition")

Removes the object named by key in service.

Args:

key: Key naming the object to remove.

get(*key*)[¶](#datastore.core.basic.InterfaceMappingDatastore.get "Permalink to this definition")

Return the object in service named by key or None.

Args:

key: Key naming the object to retrieve.

Returns:

object or None

put(*key*, *value*)[¶](#datastore.core.basic.InterfaceMappingDatastore.put "Permalink to this definition")

Stores the object value named by key in service.

Args:

key: Key naming value.

value: the object to store.

*class* datastore.core.basic.KeyTransformDatastore(*\*args*, *\*\*kwargs*)[¶](#datastore.core.basic.KeyTransformDatastore "Permalink to this definition")

Bases: [datastore.core.basic.ShimDatastore](#datastore.core.basic.ShimDatastore "datastore.core.basic.ShimDatastore")

Represents a simple ShimDatastore that applies a transform on all incoming

keys. For example:

```

>>> import datastore.core

>>> def transform(key):

...   return key.reverse

...

>>> ds = datastore.DictDatastore()

>>> kt = datastore.KeyTransformDatastore(ds, keytransform=transform)

None

>>> ds.put(datastore.Key('/a/b/c'), 'abc')

>>> ds.get(datastore.Key('/a/b/c'))

'abc'

>>> kt.get(datastore.Key('/a/b/c'))

None

>>> kt.get(datastore.Key('/c/b/a'))

'abc'

>>> ds.get(datastore.Key('/c/b/a'))

None

```

contains(*key*)[¶](#datastore.core.basic.KeyTransformDatastore.contains "Permalink to this definition")

Returns whether the object named by key is in this datastore.

delete(*key*)[¶](#datastore.core.basic.KeyTransformDatastore.delete "Permalink to this definition")

Removes the object named by keytransform(key).

get(*key*)[¶](#datastore.core.basic.KeyTransformDatastore.get "Permalink to this definition")

Return the object named by keytransform(key).

put(*key*, *value*)[¶](#datastore.core.basic.KeyTransformDatastore.put "Permalink to this definition")

Stores the object names by keytransform(key).

query(*query*)[¶](#datastore.core.basic.KeyTransformDatastore.query "Permalink to this definition")

Returns a sequence of objects matching criteria expressed in query

*class* datastore.core.basic.LoggingDatastore(*child\_datastore*, *logger=None*)[¶](#datastore.core.basic.LoggingDatastore "Permalink to this definition")

Bases: [datastore.core.basic.ShimDatastore](#datastore.core.basic.ShimDatastore "datastore.core.basic.ShimDatastore")

Wraps a datastore with a logging shim.

contains(*key*)[¶](#datastore.core.basic.LoggingDatastore.contains "Permalink to this definition")

Returns whether the object named by key exists.

LoggingDatastore logs the access.

delete(*key*)[¶](#datastore.core.basic.LoggingDatastore.delete "Permalink to this definition")

Removes the object named by key.

LoggingDatastore logs the access.

get(*key*)[¶](#datastore.core.basic.LoggingDatastore.get "Permalink to this definition")

Return the object named by key or None if it does not exist.

LoggingDatastore logs the access.

put(*key*, *value*)[¶](#datastore.core.basic.LoggingDatastore.put "Permalink to this definition")

Stores the object value named by [`](#id5)key`self.

LoggingDatastore logs the access.

query(*query*)[¶](#datastore.core.basic.LoggingDatastore.query "Permalink to this definition")

Returns an iterable of objects matching criteria expressed in query.

LoggingDatastore logs the access.

*class* datastore.core.basic.LowercaseKeyDatastore(*\*args*, *\*\*kwargs*)[¶](#datastore.core.basic.LowercaseKeyDatastore "Permalink to this definition")

Bases: [datastore.core.basic.KeyTransformDatastore](#datastore.core.basic.KeyTransformDatastore "datastore.core.basic.KeyTransformDatastore")

Represents a simple ShimDatastore that lowercases all incoming keys.

For example:

```

>>> import datastore.core

>>> ds = datastore.DictDatastore()

>>> ds.put(datastore.Key('hello'), 'world')

>>> ds.put(datastore.Key('HELLO'), 'WORLD')

>>> ds.get(datastore.Key('hello'))

'world'

>>> ds.get(datastore.Key('HELLO'))

'WORLD'

>>> ds.get(datastore.Key('HeLlO'))

None

>>> lds = datastore.LowercaseKeyDatastore(ds)

>>> lds.get(datastore.Key('HeLlO'))

'world'

>>> lds.get(datastore.Key('HeLlO'))

'world'

>>> lds.get(datastore.Key('HeLlO'))

'world'

```

*classmethod* lowercaseKey(*key*)[¶](#datastore.core.basic.LowercaseKeyDatastore.lowercaseKey "Permalink to this definition")

Returns a lowercased key.

*class* datastore.core.basic.NamespaceDatastore(*namespace*, *\*args*, *\*\*kwargs*)[¶](#datastore.core.basic.NamespaceDatastore "Permalink to this definition")

Bases: [datastore.core.basic.KeyTransformDatastore](#datastore.core.basic.KeyTransformDatastore "datastore.core.basic.KeyTransformDatastore")

Represents a simple ShimDatastore that namespaces all incoming keys.

For example:

```

>>> import datastore.core

>>>

>>> ds = datastore.DictDatastore()

>>> ds.put(datastore.Key('/a/b'), 'ab')

>>> ds.put(datastore.Key('/c/d'), 'cd')

>>> ds.put(datastore.Key('/a/b/c/d'), 'abcd')

>>>

>>> nd = datastore.NamespaceDatastore('/a/b', ds)

>>> nd.get(datastore.Key('/a/b'))

None

>>> nd.get(datastore.Key('/c/d'))

'abcd'

>>> nd.get(datastore.Key('/a/b/c/d'))

None

>>> nd.put(datastore.Key('/c/d'), 'cd')

>>> ds.get(datastore.Key('/a/b/c/d'))

'cd'

```

namespaceKey(*key*)[¶](#datastore.core.basic.NamespaceDatastore.namespaceKey "Permalink to this definition")

Returns a namespaced key: namespace.child(key).

*class* datastore.core.basic.NestedPathDatastore(*\*args*, *\*\*kwargs*)[¶](#datastore.core.basic.NestedPathDatastore "Permalink to this definition")

Bases: [datastore.core.basic.KeyTransformDatastore](#datastore.core.basic.KeyTransformDatastore "datastore.core.basic.KeyTransformDatastore")

Represents a simple ShimDatastore that shards/namespaces incoming keys.

Incoming keys are sharded into nested namespaces. The idea is to use the key

name to separate into nested namespaces. This is akin to the directory

structure that git uses for objects. For example:

```

>>> import datastore.core

>>>

>>> ds = datastore.DictDatastore()

>>> np = datastore.NestedPathDatastore(ds, depth=3, length=2)

>>>

>>> np.put(datastore.Key('/abcdefghijk'), 1)

>>> np.get(datastore.Key('/abcdefghijk'))

1

>>> ds.get(datastore.Key('/abcdefghijk'))

None

>>> ds.get(datastore.Key('/ab/cd/ef/abcdefghijk'))

1

>>> np.put(datastore.Key('abc'), 2)

>>> np.get(datastore.Key('abc'))

2

>>> ds.get(datastore.Key('/ab/ca/bc/abc'))

2

```

nestKey(*key*)[¶](#datastore.core.basic.NestedPathDatastore.nestKey "Permalink to this definition")

Returns a nested key.

*static* nestedPath(*path*, *depth*, *length*)[¶](#datastore.core.basic.NestedPathDatastore.nestedPath "Permalink to this definition")

returns a nested version of basename, using the starting characters.

For example:

```

>>> NestedPathDatastore.nested\_path('abcdefghijk', 3, 2)

'ab/cd/ef'

>>> NestedPathDatastore.nested\_path('abcdefghijk', 4, 2)

'ab/cd/ef/gh'

>>> NestedPathDatastore.nested\_path('abcdefghijk', 3, 4)

'abcd/efgh/ijk'

>>> NestedPathDatastore.nested\_path('abcdefghijk', 1, 4)

'abcd'

>>> NestedPathDatastore.nested\_path('abcdefghijk', 3, 10)

'abcdefghij/k'

```

query(*query*)[¶](#datastore.core.basic.NestedPathDatastore.query "Permalink to this definition")

*class* datastore.core.basic.NullDatastore[¶](#datastore.core.basic.NullDatastore "Permalink to this definition")

Bases: [datastore.core.basic.Datastore](#datastore.core.basic.Datastore "datastore.core.basic.Datastore")

Stores nothing, but conforms to the API. Useful to test with.

delete(*key*)[¶](#datastore.core.basic.NullDatastore.delete "Permalink to this definition")

Remove the object named by key (does nothing).

get(*key*)[¶](#datastore.core.basic.NullDatastore.get "Permalink to this definition")

Return the object named by key or None if it does not exist (None).

put(*key*, *value*)[¶](#datastore.core.basic.NullDatastore.put "Permalink to this definition")

Store the object value named by key (does nothing).

query(*query*)[¶](#datastore.core.basic.NullDatastore.query "Permalink to this definition")

Returns an iterable of objects matching criteria in query (empty).

*class* datastore.core.basic.ShardedDatastore(*stores=*[], *shardingfn=<built-in function hash>*)[¶](#datastore.core.basic.ShardedDatastore "Permalink to this definition")

Bases: [datastore.core.basic.DatastoreCollection](#datastore.core.basic.DatastoreCollection "datastore.core.basic.DatastoreCollection")

Represents a collection of datastore shards.

A datastore is selected based on a sharding function.

Sharding functions should take a Key and return an integer.

WARNING: adding or removing datastores while mid-use may severely affect

consistency. Also ensure the order is correct upon initialization.

While this is not as important for caches, it is crucial for

persistent datastores.

contains(*key*)[¶](#datastore.core.basic.ShardedDatastore.contains "Permalink to this definition")

Returns whether the object is in this datastore.

delete(*key*)[¶](#datastore.core.basic.ShardedDatastore.delete "Permalink to this definition")

Removes the object from the corresponding datastore.

get(*key*)[¶](#datastore.core.basic.ShardedDatastore.get "Permalink to this definition")

Return the object named by key from the corresponding datastore.

put(*key*, *value*)[¶](#datastore.core.basic.ShardedDatastore.put "Permalink to this definition")

Stores the object to the corresponding datastore.

query(*query*)[¶](#datastore.core.basic.ShardedDatastore.query "Permalink to this definition")

Returns a sequence of objects matching criteria expressed in query

shard(*key*)[¶](#datastore.core.basic.ShardedDatastore.shard "Permalink to this definition")

Returns the shard index to handle key, according to sharding fn.

shardDatastore(*key*)[¶](#datastore.core.basic.ShardedDatastore.shardDatastore "Permalink to this definition")

Returns the shard to handle key.

shard\_query\_generator(*query*)[¶](#datastore.core.basic.ShardedDatastore.shard_query_generator "Permalink to this definition")

A generator that queries each shard in sequence.

*class* datastore.core.basic.ShimDatastore(*datastore*)[¶](#datastore.core.basic.ShimDatastore "Permalink to this definition")

Bases: [datastore.core.basic.Datastore](#datastore.core.basic.Datastore "datastore.core.basic.Datastore")

Represents a non-concrete datastore that adds functionality between the

client and a lower level datastore. Shim datastores do not actually store

data themselves; instead, they delegate storage to an underlying child

datastore. The default implementation just passes all calls to the child.

delete(*key*)[¶](#datastore.core.basic.ShimDatastore.delete "Permalink to this definition")

Removes the object named by key.

Default shim implementation simply calls child\_datastore.delete(key)

Override to provide different functionality.

Args:

key: Key naming the object to remove.

get(*key*)[¶](#datastore.core.basic.ShimDatastore.get "Permalink to this definition")

Return the object named by key or None if it does not exist.

Default shim implementation simply returns child\_datastore.get(key)

Override to provide different functionality, for example:

```

def get(self, key):

  value = self.child\_datastore.get(key)

  return json.loads(value)

```

Args:

key: Key naming the object to retrieve

Returns:

object or None

put(*key*, *value*)[¶](#datastore.core.basic.ShimDatastore.put "Permalink to this definition")

Stores the object value named by key.

Default shim implementation simply calls child\_datastore.put(key, value)

Override to provide different functionality, for example:

```

def put(self, key, value):

  value = json.dumps(value)

  self.child\_datastore.put(key, value)

```

Args:

key: Key naming value.

value: the object to store.

query(*query*)[¶](#datastore.core.basic.ShimDatastore.query "Permalink to this definition")

Returns an iterable of objects matching criteria expressed in query.

Default shim implementation simply returns child\_datastore.query(query)

Override to provide different functionality, for example:

```

def query(self, query):

  cursor = self.child\_datastore.query(query)

  cursor.\_iterable = deserialized(cursor.\_iterable)

  return cursor

```

Args:

query: Query object describing the objects to return.

Raturns:

iterable cursor with all objects matching criteria

*class* datastore.core.basic.SymlinkDatastore(*datastore*)[¶](#datastore.core.basic.SymlinkDatastore "Permalink to this definition")

Bases: [datastore.core.basic.ShimDatastore](#datastore.core.basic.ShimDatastore "datastore.core.basic.ShimDatastore")

Datastore that creates filesystem-like symbolic link keys.

A symbolic link key is a way of naming the same value with multiple keys.

For example:

```

>>> import datastore.core

>>>

>>> dds = datastore.DictDatastore()

>>> sds = datastore.SymlinkDatastore(dds)

>>>

>>> a = datastore.Key('/A')

>>> b = datastore.Key('/B')

>>>

>>> sds.put(a, 1)

>>> sds.get(a)

1

>>> sds.link(a, b)

>>> sds.get(b)

1

>>> sds.put(b, 2)

>>> sds.get(b)

2

>>> sds.get(a)

2

>>> sds.delete(a)

>>> sds.get(a)

None

>>> sds.get(b)

None

>>> sds.put(a, 3)

>>> sds.get(a)

3

>>> sds.get(b)

3

>>> sds.delete(b)

>>> sds.get(b)

None

>>> sds.get(a)

3

```

get(*key*)[¶](#datastore.core.basic.SymlinkDatastore.get "Permalink to this definition")

Return the object named by [`](#id7)key. Follows links.

link(*source\_key*, *target\_key*)[¶](#datastore.core.basic.SymlinkDatastore.link "Permalink to this definition")

Creates a symbolic link key pointing from target\_key to source\_key

put(*key*, *value*)[¶](#datastore.core.basic.SymlinkDatastore.put "Permalink to this definition")

Stores the object named by key. Follows links.

query(*query*)[¶](#datastore.core.basic.SymlinkDatastore.query "Permalink to this definition")

Returns objects matching criteria expressed in query. Follows links.

sentinel *= 'datastore\_link'*[¶](#datastore.core.basic.SymlinkDatastore.sentinel "Permalink to this definition")

*class* datastore.core.basic.TieredDatastore(*stores=*[])[¶](#datastore.core.basic.TieredDatastore "Permalink to this definition")

Bases: [datastore.core.basic.DatastoreCollection](#datastore.core.basic.DatastoreCollection "datastore.core.basic.DatastoreCollection")

Represents a hierarchical collection of datastores.

Each datastore is queried in order. This is helpful to organize access

order in terms of speed (i.e. read caches first).

Datastores should be arranged in order of completeness, with the most complete

datastore last, as it will handle query calls.

Semantics:

* get : returns first found value

* put : writes through to all

* delete : deletes through to all

* contains : returns first found value

* query : queries bottom (most complete) datastore

contains(*key*)[¶](#datastore.core.basic.TieredDatastore.contains "Permalink to this definition")

Returns whether the object is in this datastore.

delete(*key*)[¶](#datastore.core.basic.TieredDatastore.delete "Permalink to this definition")

Removes the object from all underlying datastores.

get(*key*)[¶](#datastore.core.basic.TieredDatastore.get "Permalink to this definition")

Return the object named by key. Checks each datastore in order.

put(*key*, *value*)[¶](#datastore.core.basic.TieredDatastore.put "Permalink to this definition")

Stores the object in all underlying datastores.

query(*query*)[¶](#datastore.core.basic.TieredDatastore.query "Permalink to this definition")

Returns a sequence of objects matching criteria expressed in query.

The last datastore will handle all query calls, as it has a (if not

the only) complete record of all objects.

datastore.key[¶](#module-datastore.core.key "Permalink to this headline")

-------------------------------------------------------------------------

*class* datastore.core.key.Key(*key*)[¶](#datastore.core.key.Key "Permalink to this definition")

Bases: object

A Key represents the unique identifier of an object.

Our Key scheme is inspired by file systems and the Google App Engine key

model.

Keys are meant to be unique across a system. Keys are hierarchical,

incorporating more and more specific namespaces. Thus keys can be deemed

‘children’ or ‘ancestors’ of other keys:

```

Key('/Comedy')

Key('/Comedy/MontyPython')

```

Also, every namespace can be parametrized to embed relevant object

information. For example, the Key name (most specific namespace) could

include the object type:

```

Key('/Comedy/MontyPython/Actor:JohnCleese')

Key('/Comedy/MontyPython/Sketch:CheeseShop')

Key('/Comedy/MontyPython/Sketch:CheeseShop/Character:Mousebender')

```

child(*other*)[¶](#datastore.core.key.Key.child "Permalink to this definition")

Returns the child Key by appending namespace other.

```

>>> Key('/Comedy/MontyPython').child('Actor:JohnCleese')

Key('/Comedy/MontyPython/Actor:JohnCleese')

```

instance(*other*)[¶](#datastore.core.key.Key.instance "Permalink to this definition")

Returns an instance Key, by appending a name to the namespace.

isAncestorOf(*other*)[¶](#datastore.core.key.Key.isAncestorOf "Permalink to this definition")

Returns whether this Key is an ancestor of other.

```

>>> john = Key('/Comedy/MontyPython/Actor:JohnCleese')

>>> Key('/Comedy').isAncestorOf(john)

True

```

isDescendantOf(*other*)[¶](#datastore.core.key.Key.isDescendantOf "Permalink to this definition")

Returns whether this Key is a descendant of other.

```

>>> Key('/Comedy/MontyPython').isDescendantOf(Key('/Comedy'))

True

```

isTopLevel()[¶](#datastore.core.key.Key.isTopLevel "Permalink to this definition")

Returns whether this Key is top-level (one namespace).

list[¶](#datastore.core.key.Key.list "Permalink to this definition")

Returns the list representation of this Key.

Note that this method assumes the key is immutable.

name[¶](#datastore.core.key.Key.name "Permalink to this definition")

Returns the name of this Key, the value of the last namespace.

namespaces[¶](#datastore.core.key.Key.namespaces "Permalink to this definition")

Returns the list of namespaces of this Key.

parent[¶](#datastore.core.key.Key.parent "Permalink to this definition")

Returns the parent Key (all namespaces except the last).

```

>>> Key('/Comedy/MontyPython/Actor:JohnCleese').parent

Key('/Comedy/MontyPython')

```

path[¶](#datastore.core.key.Key.path "Permalink to this definition")

Returns the path of this Key, the parent and the type.

*classmethod* randomKey()[¶](#datastore.core.key.Key.randomKey "Permalink to this definition")

Returns a random Key

*classmethod* removeDuplicateSlashes(*path*)[¶](#datastore.core.key.Key.removeDuplicateSlashes "Permalink to this definition")

Returns the path string path without duplicate slashes.

reverse[¶](#datastore.core.key.Key.reverse "Permalink to this definition")

Returns the reverse of this Key.

```

>>> Key('/Comedy/MontyPython/Actor:JohnCleese').reverse

Key('/Actor:JohnCleese/MontyPython/Comedy')

```

type[¶](#datastore.core.key.Key.type "Permalink to this definition")

Returns the type of this Key, the field of the last namespace.

*class* datastore.core.key.Namespace[¶](#datastore.core.key.Namespace "Permalink to this definition")

Bases: str

A Key Namespace is a string identifier.

A namespace can optionally include a field (delimited by ‘:’)

Example namespaces:

```

Namespace('Bruces')

Namespace('Song:PhilosopherSong')

```

field[¶](#datastore.core.key.Namespace.field "Permalink to this definition")

returns the field part of this namespace, if any.

namespace\_delimiter *= ':'*[¶](#datastore.core.key.Namespace.namespace_delimiter "Permalink to this definition")

value[¶](#datastore.core.key.Namespace.value "Permalink to this definition")

returns the value part of this namespace.

datastore.query[¶](#module-datastore.core.query "Permalink to this headline")

-----------------------------------------------------------------------------

*class* datastore.core.query.Cursor(*query*, *iterable*)[¶](#datastore.core.query.Cursor "Permalink to this definition")

Bases: object

Represents a query result generator.

apply\_filter()[¶](#datastore.core.query.Cursor.apply_filter "Permalink to this definition")

Naively apply query filters.

apply\_limit()[¶](#datastore.core.query.Cursor.apply_limit "Permalink to this definition")

Naively apply query limit.

apply\_offset()[¶](#datastore.core.query.Cursor.apply_offset "Permalink to this definition")

Naively apply query offset.

apply\_order()[¶](#datastore.core.query.Cursor.apply_order "Permalink to this definition")

Naively apply query orders.

next()[¶](#datastore.core.query.Cursor.next "Permalink to this definition")

Iterator next. Build up count of returned elements during iteration.

query[¶](#datastore.core.query.Cursor.query "Permalink to this definition")

returned[¶](#datastore.core.query.Cursor.returned "Permalink to this definition")

skipped[¶](#datastore.core.query.Cursor.skipped "Permalink to this definition")

*class* datastore.core.query.Filter(*field*, *op*, *value*)[¶](#datastore.core.query.Filter "Permalink to this definition")

Bases: object

Represents a Filter for a specific field and its value.

Filters are used on queries to narrow down the set of matching objects.

Args:

field: the attribute name (string) on which to apply the filter.

op: the conditional operator to apply (one of

[‘<’, ‘<=’, ‘=’, ‘!=’, ‘>=’, ‘>’]).

value: the attribute value to compare against.

Examples:

```

Filter('name', '=', 'John Cleese')

Filter('age', '>=', 18)

```

conditional\_operators *= ['<', '<=', '=', '!=', '>=', '>']*[¶](#datastore.core.query.Filter.conditional_operators "Permalink to this definition")

Conditional operators that Filters support.

*classmethod* filter(*filters*, *iterable*)[¶](#datastore.core.query.Filter.filter "Permalink to this definition")

Returns the elements in iterable that pass given filters

generator(*iterable*)[¶](#datastore.core.query.Filter.generator "Permalink to this definition")

Generator function that iteratively filters given items.

*static* object\_getattr(*obj*, *field*)[¶](#datastore.core.query.Filter.object_getattr "Permalink to this definition")

Object attribute getter. Can be overridden to match client data model.

See datastore.query.\_object\_getattr().

valuePasses(*value*)[¶](#datastore.core.query.Filter.valuePasses "Permalink to this definition")

Returns whether this value passes this filter

*class* datastore.core.query.Order(*order*)[¶](#datastore.core.query.Order "Permalink to this definition")

Bases: object

Represents an Order upon a specific field, and a direction.

Orders are used on queries to define how they operate on objects

Args:

order: an order in string form. This follows the format: [+-]name

where + is ascending, - is descending, and name is the name

of the field to order by.

Note: if no ordering operator is specified, + is default.

Examples:

```

Order('+name')   # ascending order by name

Order('-age')    # descending order by age

Order('score')   # ascending order by score

```

isAscending()[¶](#datastore.core.query.Order.isAscending "Permalink to this definition")

isDescending()[¶](#datastore.core.query.Order.isDescending "Permalink to this definition")

keyfn(*obj*)[¶](#datastore.core.query.Order.keyfn "Permalink to this definition")

A key function to be used in pythonic sort operations.

*classmethod* multipleOrderComparison(*orders*)[¶](#datastore.core.query.Order.multipleOrderComparison "Permalink to this definition")

Returns a function that will compare two items according to orders

*static* object\_getattr(*obj*, *field*)[¶](#datastore.core.query.Order.object_getattr "Permalink to this definition")

Object attribute getter. Can be overridden to match client data model.

See datastore.query.\_object\_getattr().

order\_operators *= ['-', '+']*[¶](#datastore.core.query.Order.order_operators "Permalink to this definition")

Ordering operators: + is ascending, - is descending.

*classmethod* sorted(*items*, *orders*)[¶](#datastore.core.query.Order.sorted "Permalink to this definition")

Returns the elements in items sorted according to orders

*class* datastore.core.query.Query(*key*, *limit=None*, *offset=0*, *object\_getattr=None*)[¶](#datastore.core.query.Query "Permalink to this definition")

Bases: object

A Query describes a set of objects.

Queries are used to retrieve objects and instances matching a set of criteria

from Datastores. Query objects themselves are simply descriptions,

the actual Query implementations are left up to the Datastores.

copy()[¶](#datastore.core.query.Query.copy "Permalink to this definition")

Returns a copy of this query.

dict()[¶](#datastore.core.query.Query.dict "Permalink to this definition")

Returns a dictionary representing this query.

filter(*\*args*)[¶](#datastore.core.query.Query.filter "Permalink to this definition")

Adds a Filter to this query.

Args:

see Filter constructor

Returns self for JS-like method chaining:

```

query.filter('age', '>', 18).filter('sex', '=', 'Female')

```

*classmethod* from\_dict(*dictionary*)[¶](#datastore.core.query.Query.from_dict "Permalink to this definition")

Constructs a query from a dictionary.

*static* object\_getattr(*obj*, *field*)[¶](#datastore.core.query.Query.object_getattr "Permalink to this definition")

Attribute getter for the objects to operate on.

This function can be overridden in classes or instances of Query, Filter, and

Order. Thus, a custom function to extract values to attributes can be

specified, and the system can remain agnostic to the client’s data model,

without loosing query power.

For example, the default implementation works with attributes and items:

```

def \_object\_getattr(obj, field):

  # check whether this key is an attribute

  if hasattr(obj, field):

    value = getattr(obj, field)

  # if not, perhaps it is an item (raw dicts, etc)

  elif field in obj:

    value = obj[field]

  # return whatever we've got.

  return value

```

Or consider a more complex, application-specific structure:

```

def \_object\_getattr(version, field):

  if field in ['key', 'committed', 'created', 'hash']:

    return getattr(version, field)

  else:

    return version.attributes[field]['value']

```

order(*order*)[¶](#datastore.core.query.Query.order "Permalink to this definition")

Adds an Order to this query.

Args:

see Order constructor

Returns self for JS-like method chaining:

```

query.order('+age').order('-home')

```

datastore.core.query.chain\_gen(*iterables*)[¶](#datastore.core.query.chain_gen "Permalink to this definition")

A generator that chains iterables.

datastore.core.query.is\_iterable(*obj*)[¶](#datastore.core.query.is_iterable "Permalink to this definition")

datastore.core.query.limit\_gen(*limit*, *iterable*)[¶](#datastore.core.query.limit_gen "Permalink to this definition")

A generator that applies a count limit.

datastore.core.query.offset\_gen(*offset*, *iterable*, *skip\_signal=None*)[¶](#datastore.core.query.offset_gen "Permalink to this definition")

A generator that applies an offset, skipping offset elements from

iterable. If skip\_signal is a callable, it will be called with every

skipped element.

datastore.serialize[¶](#module-datastore.core.serialize "Permalink to this headline")

-------------------------------------------------------------------------------------

*class* datastore.core.serialize.NonSerializer[¶](#datastore.core.serialize.NonSerializer "Permalink to this definition")

Bases: [datastore.core.serialize.Serializer](#datastore.core.serialize.Serializer "datastore.core.serialize.Serializer")

Implements serializing protocol but does not serialize at all.

If only storing strings (or already-serialized values).

*classmethod* dumps(*value*)[¶](#datastore.core.serialize.NonSerializer.dumps "Permalink to this definition")

returns value.

*classmethod* loads(*value*)[¶](#datastore.core.serialize.NonSerializer.loads "Permalink to this definition")

returns value.

*class* datastore.core.serialize.Serializer[¶](#datastore.core.serialize.Serializer "Permalink to this definition")

Bases: object

Serializing protocol. Serialized data must be a string.

*classmethod* dumps(*value*)[¶](#datastore.core.serialize.Serializer.dumps "Permalink to this definition")

returns serialized value.

*static* implements\_serializer\_interface()[¶](#datastore.core.serialize.Serializer.implements_serializer_interface "Permalink to this definition")

*classmethod* loads(*value*)[¶](#datastore.core.serialize.Serializer.loads "Permalink to this definition")

returns deserialized value.

*class* datastore.core.serialize.SerializerShimDatastore(*datastore*, *serializer=None*)[¶](#datastore.core.serialize.SerializerShimDatastore "Permalink to this definition")

Bases: [datastore.core.basic.ShimDatastore](#datastore.core.basic.ShimDatastore "datastore.core.basic.ShimDatastore")

Represents a Datastore that serializes and deserializes values.

As data is put, the serializer shim serializes it and put``s it into

the underlying ``child\_datastore. Correspondingly, on the way out (through

get or query) the data is retrieved from the child\_datastore and

deserialized.

Args:

datastore: a child datastore for the ShimDatastore superclass.

serializer: a serializer object (responds to loads and dumps).

deserializedValue(*value*)[¶](#datastore.core.serialize.SerializerShimDatastore.deserializedValue "Permalink to this definition")

Returns deserialized value or None.

get(*key*)[¶](#datastore.core.serialize.SerializerShimDatastore.get "Permalink to this definition")

Return the object named by key or None if it does not exist.

Retrieves the value from the child\_datastore, and de-serializes

it on the way out.

Args:

key: Key naming the object to retrieve

Returns:

object or None

put(*key*, *value*)[¶](#datastore.core.serialize.SerializerShimDatastore.put "Permalink to this definition")

Stores the object value named by key.

Serializes values on the way in, and stores the serialized data into the

child\_datastore.

Args:

key: Key naming value

value: the object to store.

query(*query*)[¶](#datastore.core.serialize.SerializerShimDatastore.query "Permalink to this definition")

Returns an iterable of objects matching criteria expressed in query

De-serializes values on the way out, using a *deserialized\_gen* to

avoid incurring the cost of de-serializing all data at once, or ever, if

iteration over results does not finish (subject to order generator

constraint).

Args:

query: Query object describing the objects to return.

Raturns:

iterable cursor with all objects matching criteria

serializedValue(*value*)[¶](#datastore.core.serialize.SerializerShimDatastore.serializedValue "Permalink to this definition")

Returns serialized value or None.

serializer *= <module 'json' from '/usr/lib/python2.7/json/\_\_init\_\_.pyc'>*[¶](#datastore.core.serialize.SerializerShimDatastore.serializer "Permalink to this definition")

*class* datastore.core.serialize.Stack[¶](#datastore.core.serialize.Stack "Permalink to this definition")

Bases: [datastore.core.serialize.Serializer](#datastore.core.serialize.Serializer "datastore.core.serialize.Serializer"), list

represents a stack of serializers, applying each serializer in sequence.

dumps(*value*)[¶](#datastore.core.serialize.Stack.dumps "Permalink to this definition")

returns serialized value.

loads(*value*)[¶](#datastore.core.serialize.Stack.loads "Permalink to this definition")

Returns deserialized value.

datastore.core.serialize.deserialized\_gen(*serializer*, *iterable*)[¶](#datastore.core.serialize.deserialized_gen "Permalink to this definition")

Generator that yields deserialized objects from iterable.

*class* datastore.core.serialize.map\_serializer[¶](#datastore.core.serialize.map_serializer "Permalink to this definition")

Bases: [datastore.core.serialize.Serializer](#datastore.core.serialize.Serializer "datastore.core.serialize.Serializer")

map serializer that ensures the serialized value is a mapping type.

*classmethod* dumps(*value*)[¶](#datastore.core.serialize.map_serializer.dumps "Permalink to this definition")

returns mapping typed serialized value.

*classmethod* loads(*value*)[¶](#datastore.core.serialize.map_serializer.loads "Permalink to this definition")

Returns mapping type deserialized value.

sentinel *= '@wrapped'*[¶](#datastore.core.serialize.map_serializer.sentinel "Permalink to this definition")

datastore.core.serialize.monkey\_patch\_bson(*bson=None*)[¶](#datastore.core.serialize.monkey_patch_bson "Permalink to this definition")

Patch bson in pymongo to use loads and dumps interface.

*class* datastore.core.serialize.prettyjson[¶](#datastore.core.serialize.prettyjson "Permalink to this definition")

Bases: [datastore.core.serialize.Serializer](#datastore.core.serialize.Serializer "datastore.core.serialize.Serializer")

json wrapper serializer that pretty-prints.

Useful for human readable values and versioning.

*classmethod* dumps(*value*)[¶](#datastore.core.serialize.prettyjson.dumps "Permalink to this definition")

returns json serialized value (pretty-printed).

*classmethod* loads(*value*)[¶](#datastore.core.serialize.prettyjson.loads "Permalink to this definition")

returns json deserialized value.

datastore.core.serialize.serialized\_gen(*serializer*, *iterable*)[¶](#datastore.core.serialize.serialized_gen "Permalink to this definition")

Generator that yields serialized objects from iterable.

datastore.core.serialize.shim(*datastore*, *serializer=None*)[¶](#datastore.core.serialize.shim "Permalink to this definition")

Return a SerializerShimDatastore wrapping datastore.

Can be used as a syntacticly-nicer eay to wrap a datastore with a

serializer:

```

my\_store = datastore.serialize.shim(my\_store, json)

```

### [Table Of Contents](../index.html)

* [datastore.core](#)

	+ [datastore.basic](#module-datastore.core.basic)

	+ [datastore.key](#module-datastore.core.key)

	+ [datastore.query](#module-datastore.core.query)

	+ [datastore.serialize](#module-datastore.core.serialize)

#### Previous topic

[datastore Package](datastore.html "previous chapter")

#### Next topic

[datastore.core.util](datastore.util.html "next chapter")

### This Page

* [Show Source](../_sources/package/datastore.core.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/package/datastore.core.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/package/datastore.core.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](datastore.util.html "datastore.core.util") |

* [previous](datastore.html "datastore Package") |

* [datastore 0.3.0 documentation](../index.html) »

* [datastore Package](datastore.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





datastore Package — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](datastore.core.html "datastore.core") |

* [previous](../api/serialize.html "Serialize") |

* [datastore 0.3.0 documentation](../index.html) »

datastore Package[¶](#datastore-package "Permalink to this headline")

=====================================================================

Subpackages[¶](#subpackages "Permalink to this headline")

---------------------------------------------------------

* [datastore.core](datastore.core.html)

	+ [datastore.basic](datastore.core.html#module-datastore.core.basic)

	+ [datastore.key](datastore.core.html#module-datastore.core.key)

	+ [datastore.query](datastore.core.html#module-datastore.core.query)

	+ [datastore.serialize](datastore.core.html#module-datastore.core.serialize)

* [datastore.core.util](datastore.util.html)

	+ [datastore.core.util.fasthash](datastore.util.html#datastore-core-util-fasthash)

* [datastore.filesystem](datastore.filesystem.html)

### [Table Of Contents](../index.html)

* [datastore Package](#)

	+ [Subpackages](#subpackages)

#### Previous topic

[Serialize](../api/serialize.html "previous chapter")

#### Next topic

[datastore.core](datastore.core.html "next chapter")

### This Page

* [Show Source](../_sources/package/datastore.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/package/datastore.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/package/datastore.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](datastore.core.html "datastore.core") |

* [previous](../api/serialize.html "Serialize") |

* [datastore 0.3.0 documentation](../index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Queries — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](basic.html "Basic Datastores") |

* [previous](key.html "Keys") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

Queries[¶](#queries "Permalink to this headline")

=================================================

In addition to the key-value store get and set semantics, datastore

provides an interface to retrieve multiple records at a time through the use

of queries. The datastore Query model gleans a common set of operations

performed when querying. To avoid pasting here years of database research,

let’s summarize the operations datastore supports.

Query Operations:

> 

> * namespace - scope the query, usually by object type

> * filters - select a subset of values by applying constraints

> * orders - sort the results by applying sort conditions

> * limit - impose a numeric limit on the number of results

> * offset - skip a number of results (for efficient pagination)

> 

> 

> 

datastore combines these operations into a simple Query class that allows

applications to define their constraints in a simple, generic, and pythonic

way without introducing datastore specific calls, languages, etc.

Of course, different datastores provide relational query support across a wide

spectrum, from full support in traditional databases to none at all in

key-value stores. Datastore aims to provide a common, simple interface for

the sake of application evolution over time and keeping large code bases

free of tool-specific code. It would be ridiculous to claim to support

high-performance queries on architectures that obviously do not.

Instead, datastore provides the interface, ideally translating queries to their

native form (e.g. into SQL for MySQL or a MongoDB query).

However, on the

wrong datastore, queries can potentially incur the high cost of performing the

aforemantioned [*query operations*](#api-query-operations) on the data set

directly in python.

It is the client’s responsibility to select the right tool for the job: pick a

data storage solution that fits the application’s needs now, and wrap it with a

datastore implementation. Some applications, particularly in early development

stages, can afford to incurr the cost of queries on non-relational databases

(e.g. using a [FileSystemDatastore](../package/datastore.filesystem.html#datastore.filesystem.FileSystemDatastore "datastore.filesystem.FileSystemDatastore") and not worry about a database

at all). When it comes time to switch the tool for performance, updating the

application code can be as simple as swapping the datastore in one place, not

all over the application code base. This gain in engineering time, both at

initial development and during later iterations, can significantly offest the

cost of the layer of abstraction.

**tl;dr:**

queries are supported across datastores. They are very cheap on top

of relational databases, and very expensive otherwise. Pick the right tool for

the job!

Query classes[¶](#query-classes "Permalink to this headline")

-------------------------------------------------------------

### Query[¶](#query "Permalink to this headline")

### Filter[¶](#filter "Permalink to this headline")

### Order[¶](#order "Permalink to this headline")

### Cursor[¶](#cursor "Permalink to this headline")

### Generators[¶](#generators "Permalink to this headline")

Note on generators: naive datastore queries use generators to delay

performing work (such as filtering). Thus, no up-front cost is paid, but rather

the cost comes at iteration. This is particularly useful in that even when

working on large datasets, the naive query implementation can work as

generators do not require having loading the entire dataset in memory upfront.

When I say they can work, I do not imply quickly, just that they can work at

all.

The **crucial exception**, of course, is orders. If

any order is placed on a query, the naive query implementation loses the benefit

of delaying the work. That is because one cannot properly sort an entire

dataset using a generator (sure, a generator could still be used to avoid

paying the cost of sorting the *entire* dataset upfront, but that could still

require putting the entire dataset in memory in the worst case).

Specific datastore implementations should keep this in mind, performing as much

work as possible in low-level, storage engine specific ways, and do the rest

using generators. In particular, always try to push ordering into the

underlying layer.

### Other[¶](#other "Permalink to this headline")

Examples[¶](#examples "Permalink to this headline")

---------------------------------------------------

TODO

### [Table Of Contents](../index.html)

* [Queries](#)

	+ [Query classes](#query-classes)

		- [Query](#query)

		- [Filter](#filter)

		- [Order](#order)

		- [Cursor](#cursor)

		- [Generators](#generators)

		- [Other](#other)

	+ [Examples](#examples)

#### Previous topic

[Keys](key.html "previous chapter")

#### Next topic

[Basic Datastores](basic.html "next chapter")

### This Page

* [Show Source](../_sources/api/query.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/api/query.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/api/query.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](basic.html "Basic Datastores") |

* [previous](key.html "Keys") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Basic Datastores — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](shims.html "Shims") |

* [previous](query.html "Queries") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

Basic Datastores[¶](#basic-datastores "Permalink to this headline")

===================================================================

DictDatastore[¶](#dictdatastore "Permalink to this headline")

-------------------------------------------------------------

Example:

```

>>> import pprint

>>> from datastore import DictDatastore, Key, Query

>>> ds = DictDatastore()

>>> for i in range(0, 3):

...   key = Key('/%d' % i)

...   ds.put(key.child('A'), '%d a value' % i)

...   ds.put(key.child('B'), '%d b value' % i)

...

>>> pprint.pprint(ds.\_items)

{'/0': {Key('/0/A'): '0 a value', Key('/0/B'): '0 b value'},

 '/1': {Key('/1/A'): '1 a value', Key('/1/B'): '1 b value'},

 '/2': {Key('/2/A'): '2 a value', Key('/2/B'): '2 b value'}}

>>> ds.get(Key('/1/A'))

'1 a value'

>>> for item in ds.query(Query(Key('/2'))):

...   print item

...

2 b value

2 a value

```

InterfaceMappingDatastore[¶](#interfacemappingdatastore "Permalink to this headline")

-------------------------------------------------------------------------------------

Example:

```

>>> import pylibmc

>>> from datastore import InterfaceMappingDatastore, Key

>>> mc = pylibmc.Client(['127.0.0.1'])

>>> mc\_ds = InterfaceMappingDatastore(mc, put='set', key=str)

>>> mc\_ds.put(Key('Hello'), 'World')

>>> mc\_ds.get(Key('Hello'))

'World'

>>> mc.get('/Hello')

'World'

>>> mc.set('/Hello', 'Goodbye!')

True

>>> mc\_ds.get(Key('/Hello'))

'Goodbye!'

```

### [Table Of Contents](../index.html)

* [Basic Datastores](#)

	+ [DictDatastore](#dictdatastore)

	+ [InterfaceMappingDatastore](#interfacemappingdatastore)

#### Previous topic

[Queries](query.html "previous chapter")

#### Next topic

[Shims](shims.html "next chapter")

### This Page

* [Show Source](../_sources/api/basic.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/api/basic.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/api/basic.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](shims.html "Shims") |

* [previous](query.html "Queries") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Keys — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](query.html "Queries") |

* [previous](index.html "Core datastore API") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

Keys[¶](#keys "Permalink to this headline")

===========================================

All objects stored through datastore are described by a key. This key

uniquely identifies a particular object, and provides namespacing for queries.

The datastore.Key class below provides the required functionality.

One can define another Key class with a different format that conforms to the

same interface (particularly stringifying, hashes, namespacing, and ancestry).

Key[¶](#key "Permalink to this headline")

-----------------------------------------

Namespace[¶](#namespace "Permalink to this headline")

-----------------------------------------------------

### [Table Of Contents](../index.html)

* [Keys](#)

	+ [Key](#key)

	+ [Namespace](#namespace)

#### Previous topic

[Core datastore API](index.html "previous chapter")

#### Next topic

[Queries](query.html "next chapter")

### This Page

* [Show Source](../_sources/api/key.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/api/key.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/api/key.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](query.html "Queries") |

* [previous](index.html "Core datastore API") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Serialize — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](../package/datastore.html "datastore Package") |

* [previous](collections.html "Collections") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

Serialize[¶](#serialize "Permalink to this headline")

=====================================================

Serializing shemes are often application-specific, and thus libraries often

avoid imposing one. At the same time, it would be ideal if a variety of

serializers were available and trivially pluggable into the data storage

pattern through a simple interface.

The [pickle](http://docs.python.org/library/pickle.html#pickle "(in Python v2.7)") protocol has established the

pickle.loads() and pickle.dumps() serialization interface,

which other serializers (like [json](http://docs.python.org/library/json.html#json "(in Python v2.7)")) have adopted. This significantly

simplifies things, but specific calls to serializers need to be added whenever

inserting of extracting data with data storage libraries.

To flexibly solve this issue, datastore defines a

datastore.SerializerShimDatastore which can be layered on top of

any other datastore.

As data is put, the serializer shim serializes it and put``s it into

the underlying ``child\_datastore. Correspondingly, on the way out (through

get or query) the data is retrieved from the child\_datastore and

deserialized.

SerializerShimDatastore[¶](#serializershimdatastore "Permalink to this headline")

---------------------------------------------------------------------------------

### datastore.serialize.shim[¶](#datastore-serialize-shim "Permalink to this headline")

Serializers[¶](#serializers "Permalink to this headline")

---------------------------------------------------------

The serializers that datastore.SerializerShimDatastore accepts

must respond to the protocol outlined in

datastore.serialize.Serializer (the [pickle](http://docs.python.org/library/pickle.html#pickle "(in Python v2.7)") protocol).

### serialize.Serializer[¶](#serialize-serializer "Permalink to this headline")

### serialize.NonSerializer[¶](#serialize-nonserializer "Permalink to this headline")

### serialize.prettyjson[¶](#serialize-prettyjson "Permalink to this headline")

### serialize.Stack[¶](#serialize-stack "Permalink to this headline")

### serialize.map\_serializer[¶](#serialize-map-serializer "Permalink to this headline")

### Generators[¶](#generators "Permalink to this headline")

Examples[¶](#examples "Permalink to this headline")

---------------------------------------------------

TODO

### [Table Of Contents](../index.html)

* [Serialize](#)

	+ [SerializerShimDatastore](#serializershimdatastore)

		- [datastore.serialize.shim](#datastore-serialize-shim)

	+ [Serializers](#serializers)

		- [serialize.Serializer](#serialize-serializer)

		- [serialize.NonSerializer](#serialize-nonserializer)

		- [serialize.prettyjson](#serialize-prettyjson)

		- [serialize.Stack](#serialize-stack)

		- [serialize.map\_serializer](#serialize-map-serializer)

		- [Generators](#generators)

	+ [Examples](#examples)

#### Previous topic

[Collections](collections.html "previous chapter")

#### Next topic

[datastore Package](../package/datastore.html "next chapter")

### This Page

* [Show Source](../_sources/api/serialize.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/api/serialize.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/api/serialize.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](../package/datastore.html "datastore Package") |

* [previous](collections.html "Collections") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Collections — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](serialize.html "Serialize") |

* [previous](shims.html "Shims") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

Collections[¶](#collections "Permalink to this headline")

=========================================================

Grouping datastores into datastore collections can

significantly simplify complex access patterns. For example, caching datastores

can be checked before accessing more costly datastores, or a group of

equivalent datastores can act as shards containing large data sets.

As [*shims*](shims.html#api-shims), datastore collections also derive from

*datastore*, and must implement the four datastore

operations (get, put, delete, query).

DatastoreCollection[¶](#datastorecollection "Permalink to this headline")

-------------------------------------------------------------------------

Collections may derive from DatastoreCollection

TieredDatastore[¶](#tiereddatastore "Permalink to this headline")

-----------------------------------------------------------------

Example:

```

>>> import pymongo

>>> import datastore.core

>>>

>>> from datastore.mongo import MongoDatastore

>>> from datastore.pylru import LRUCacheDatastore

>>> from datastore.filesystem import FileSystemDatastore

>>>

>>> conn = pymongo.Connection()

>>> mongo = MongoDatastore(conn.test\_db)

>>>

>>> cache = LRUCacheDatastore(1000)

>>> fs = FileSystemDatastore('/tmp/.test\_db')

>>>

>>> ds = datastore.TieredDatastore([cache, mongo, fs])

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

ShardedDatastore[¶](#shardeddatastore "Permalink to this headline")

-------------------------------------------------------------------

Example:

```

>>> import datastore.core

>>>

>>> shards = [datastore.DictDatastore() for i in range(0, 10)]

>>>

>>> ds = datastore.ShardedDatastore(shards)

>>>

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

### [Table Of Contents](../index.html)

* [Collections](#)

	+ [DatastoreCollection](#datastorecollection)

	+ [TieredDatastore](#tiereddatastore)

	+ [ShardedDatastore](#shardeddatastore)

#### Previous topic

[Shims](shims.html "previous chapter")

#### Next topic

[Serialize](serialize.html "next chapter")

### This Page

* [Show Source](../_sources/api/collections.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/api/collections.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/api/collections.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](serialize.html "Serialize") |

* [previous](shims.html "Shims") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Core datastore API — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](key.html "Keys") |

* [previous](../index.html "datastore - simple, unified API for multiple data stores") |

* [datastore 0.3.0 documentation](../index.html) »

Core datastore API[¶](#core-datastore-api "Permalink to this headline")

=======================================================================

* [Keys](key.html)

	+ [Key](key.html#key)

	+ [Namespace](key.html#namespace)

* [Queries](query.html)

	+ [Query classes](query.html#query-classes)

	+ [Examples](query.html#examples)

* [Basic Datastores](basic.html)

	+ [DictDatastore](basic.html#dictdatastore)

	+ [InterfaceMappingDatastore](basic.html#interfacemappingdatastore)

* [Shims](shims.html)

	+ [ShimDatastore](shims.html#shimdatastore)

	+ [KeyTransformDatastore](shims.html#keytransformdatastore)

	+ [LowercaseKeyDatastore](shims.html#lowercasekeydatastore)

	+ [NamespaceDatastore](shims.html#namespacedatastore)

	+ [SymlinkDatastore](shims.html#symlinkdatastore)

* [Collections](collections.html)

	+ [DatastoreCollection](collections.html#datastorecollection)

	+ [TieredDatastore](collections.html#tiereddatastore)

	+ [ShardedDatastore](collections.html#shardeddatastore)

* [Serialize](serialize.html)

	+ [SerializerShimDatastore](serialize.html#serializershimdatastore)

	+ [Serializers](serialize.html#serializers)

	+ [Examples](serialize.html#examples)

datastore base class[¶](#datastore-base-class "Permalink to this headline")

---------------------------------------------------------------------------

Examples[¶](#examples "Permalink to this headline")

---------------------------------------------------

### Hello World[¶](#hello-world "Permalink to this headline")

```

>>> import datastore.core

>>> ds = datastore.DictDatastore()

>>> hello = datastore.Key('hello')

>>> ds.put(hello, 'world')

>>> ds.contains(hello)

True

>>> ds.get(hello)

'world'

>>> ds.delete(hello)

>>> ds.get(hello)

None

```

### [Table Of Contents](../index.html)

* [Core datastore API](#)

	+ [datastore base class](#datastore-base-class)

	+ [Examples](#examples)

		- [Hello World](#hello-world)

#### Previous topic

[datastore - simple, unified API for multiple data stores](../index.html "previous chapter")

#### Next topic

[Keys](key.html "next chapter")

### This Page

* [Show Source](../_sources/api/index.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/api/index.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/api/index.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](key.html "Keys") |

* [previous](../index.html "datastore - simple, unified API for multiple data stores") |

* [datastore 0.3.0 documentation](../index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)





Shims — datastore 0.3.0 documentation

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](collections.html "Collections") |

* [previous](basic.html "Basic Datastores") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

Shims[¶](#shims "Permalink to this headline")

=============================================

Sometimes common functionality can be compartmentalized into logic that can

be plugged in or not. For example, serializing and deserializing data as it is

stored or extracted is a very common operation. Likewise, applications may need

to perform routine operations as data makes its way from the top-level logic to

the underlying storage.

To address this use case in an elegant way, datastore uses the notion of a

shim datastore, which implements all four main

*datastore operations* in terms of an underlying child

datastore. For example, a json serializer datastore could implement get

and put as:

```

def get(self, key):

  value = self.child\_datastore.get(key)

  return json.loads(value)

def put(self, key, value):

  value = json.dumps(value)

  self.child\_datastore.put(key, value)

```

ShimDatastore[¶](#shimdatastore "Permalink to this headline")

-------------------------------------------------------------

To implement a shim datastore, derive from datastore.ShimDatastore

and override any of the operations.

KeyTransformDatastore[¶](#keytransformdatastore "Permalink to this headline")

-----------------------------------------------------------------------------

LowercaseKeyDatastore[¶](#lowercasekeydatastore "Permalink to this headline")

-----------------------------------------------------------------------------

NamespaceDatastore[¶](#namespacedatastore "Permalink to this headline")

-----------------------------------------------------------------------

SymlinkDatastore[¶](#symlinkdatastore "Permalink to this headline")

-------------------------------------------------------------------

### [Table Of Contents](../index.html)

* [Shims](#)

	+ [ShimDatastore](#shimdatastore)

	+ [KeyTransformDatastore](#keytransformdatastore)

	+ [LowercaseKeyDatastore](#lowercasekeydatastore)

	+ [NamespaceDatastore](#namespacedatastore)

	+ [SymlinkDatastore](#symlinkdatastore)

#### Previous topic

[Basic Datastores](basic.html "previous chapter")

#### Next topic

[Collections](collections.html "next chapter")

### This Page

* [Show Source](../_sources/api/shims.txt)

* [Show on GitHub](https://github.com/jbenet/datastore/blob/master/docs/api/shims.rst)

* [Edit on GitHub](https://github.com/jbenet/datastore/edit/master/docs/api/shims.rst)

### Quick search

 Enter search terms or a module, class or function name.

 

### Navigation

* [index](../genindex.html "General Index")

* [modules](../py-modindex.html "Python Module Index") |

* [next](collections.html "Collections") |

* [previous](basic.html "Basic Datastores") |

* [datastore 0.3.0 documentation](../index.html) »

* [Core datastore API](index.html) »

 © Copyright 2011, Juan Batiz-Benet.

 Created using [Sphinx](http://sphinx.pocoo.org/) 1.1.3+.

 

  

  

  

 .rtd-badge {

 position: fixed;

 display: block;

 bottom: 5px;

 height: 40px;

 text-indent: -9999em;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -moz-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 -webkit-box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 rgba(255, 255, 255, 0.2) inset;

 }

 #version\_menu {

 position: fixed;

 display: none;

 bottom: 11px;

 right: 166px;

 list-style-type: none;

 margin: 0;

 }

 .footer\_popout:hover #version\_menu {

 display: block;

 }

 #version\_menu li {

 display: block;

 float: right;

 }

 #version\_menu li a {

 display: block;

 padding: 6px 10px 4px 10px;

 margin: 7px 7px 0 0;

 font-weight: bold;

 font-size: 14px;

 height: 20px;

 line-height: 17px;

 text-decoration: none;

 color: #fff;

 background: #8ca1af url(../images/gradient-light.png) bottom left repeat-x;

 border-radius: 3px;

 -moz-border-radius: 3px;

 -webkit-border-radius: 3px;

 box-shadow: 0 1px 1px #465158;

 -moz-box-shadow: 0 1px 1px #465158;

 -webkit-box-shadow: 0 1px 1px #465158;

 text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);

 }

 #version\_menu li a:hover {

 text-decoration: none;

 background-color: #697983;

 box-shadow: 0 1px 0px #465158;

 -moz-box-shadow: 0 1px 0px #465158;

 -webkit-box-shadow: 0 1px 0px #465158;

 }

 .rtd-badge.rtd {

 background: #3b4449 url(//media.readthedocs.org//images/badge-rtd.png) scroll 0px -46px no-repeat;

 border: 1px solid #282E32;

 width: 41px;

 right: 5px;

 }

 .footer\_popout:hover .rtd-badge.rtd {

 background-position: top left;

 width: 160px;

 }

 .rtd-badge.revsys { background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline-sponsored {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 290px;

 right: 173px;

 }

 .rtd-badge.revsys-inline {

 position: inherit;

 margin-left: auto;

 margin-right: 175px;

 margin-bottom: 5px;

 background: #465158 url(//media.readthedocs.org//images/badge-revsys-sm.png) top left no-repeat;

 border: 1px solid #1C5871;

 width: 205px;

 right: 173px;

 }

 [Brought to you by Read the Docs](//readthedocs.org/projects/datastore/?fromdocs=datastore)

* [latest](/en/latest/)

