A Key-Value database interface for python using SQLAlchemy.
This is a Python module that provides an interface, the KeyValueDatabaseInterface()
class, for a simple Key-Value
Database. If such a database does not exists, it creates ones using SQLAlchemy.
The interface has several CRUD methods so that it can interface with the database.
Some methods of the KeyValueDatabaseInterface()
class return an object of type KeyValue()
, which is a class used
to abstract the Key-Value entries in the database. This can and probably will change in the future so that the
implementation can be hidden. Instead, a dictionary or a tuple will probably be returned instead.
By default the module uses SQLite3 as a database, but it can support any of the ones
supported by SQLALchemy.
Currently SQLite defaults as the default database. It’s a local database saved to a .db
file. You can open the
database file and view the content using DB Browser for SQLite.
Google provides document on the Python Protobuf classes: https://developers.google.com/protocol-buffers/docs/reference/python.
The Message() class
is of particular use.
KeyValueDatabaseInterface()
: An interface class for a simple Key-Value Relational Database. Has several different
CRUD methods
get_all()
: A method that returns all the Key-Value pairs in the database
get(key)
: Returns the entry associated with the key.
get_multiple(keys)
: Returns a list of entries associated with the provided keys.
insert(self, key, value)
: Insert a single entry into the database.
insert_multiple(kv_values)
: Insert multiple Key-Value entries.
update(key, value)
: Updates the entry associated with the key with the value provided.
remove(keys)
: Remove the entries associate with the keys provided.
There are two example python files in the project:
example.py
shows how to use the custom Key-Value interface; andexample_protobuf.py
shows how add a serialized protocol buffer.