Developer interface

URI

for mysql: 'mysql://username:password@hostname:port/database.collection_name'

for sqlite: 'sqlite://path-to-sqlite-file:collection_name' or 'sqlite://memory:collection_name'

In case when sqlite is in use two variants of collection is possible: store data in file or store data in memory.

Serializers (serializers.py)

It used for serialization data in kvlite databases. Default serializer is cPickleSerializer.
Serializer is the class or module to serialize documents with, must have methods or functions named
dumps and loads. Select which serializer use in database can be defined via open(uri, serializer=cPickleSerializer) function

class cPickleSerializer(object)

standard Python module cPickle is used for data serialization

class CompressedJsonSerializer(object)

JSON format, compressed by zlib module is used for data serialization

Please note that there's no way to store which serializer was used for collection. The collision is possible when during putting data to collection was used one serializer but during getting data was used another one.

Collection Utils (utils.py)

open(uri, serializer=cPickleSerializer)

open collection by URI,

if collection does not exist kvlite will try to create it

serializer: cPickleSerializer is the default,

returns MysqlCollection or SqliteCollection object in case of successful opening or creation new collection

remove(uri)

remove collection by URI

get_uuid(amount=100)

return the list of uuids. By amount argument you can define how many UUIDs will be generated and returned. By default get_uuid returns 100 UUIDs

The structure shows the list of fields in documents, its names, types and amount of documents
with this field type.

tmp_name()

generate temporary collection name

>>> kvlite.tmp_name()
'attjhhxv22'>>>

Collection (collections.py)

Classes MysqlCollection and SqliteCollection inherited from BaseCollection class and have the same methods. No needs to create these classes directly, all access to required collection can be provided via kvlite.open() function.

get_uuid()

return one uuid.

By amount argument you can define how many UUIDs will be generated and
stored in cache if it's empty. By default 100 UUIDs will be generated.

For mysql connection, the generation of UUIDs is more fast than kvlite.get_uuid()

put key/value to storage. The key has limitation - only 40 bytes length. The value can be string, list or tuple, dictionary. The method put() allows to add many key/value pairs per one call: collection.put([(k1,v1),(k2,v2),(k3,v3)])

delete(k)

delete key/value pair

keys()

returns the list of all keys in collection

count()

returns the amount of documents in collection

commit()

as kvlite based on transactional databases, commit() is used for commitment changes in collection

close()

close connection to database

CollectionManager (managers.py)

Sometimes it will needed to manage collections: create, check if exists, remove. For these operations you can use CollectionManager. This class has the next methods:

parse_uri(uri)

depends on type of database, the function parse_uri() can returns deferent result based on which backend is used