Package: antidotedb
Antidote Python ClientThe repository contains classes for using Antidote Database service in Python. It provides the
client implementation to use Antidote Database.You can learn more about Antidote DatabasehereInstallationFor installing the Python AntidoteDB client, just use pip installer.pip antidotedbDocumentationThe classes for accessing AntidoteDB are in packageantidotedb.For accessing AntidoteDB, you should start by creating anAntidoteClientobject, as in the following
example.from antidotedb import *

server = 'locahost'
port = 8087

clt = AntidoteClient(server, port)Interactive transactionsstart_transactionstarts an interactive transactions. On failure,start_transactionmethod raises anAntidoteException.tx = clt.start_transaction()commitmethod commits a sequence of operations executed in a transaction. On success,
thecommitmethod returnsTrue.ok = tx.commit()abotmethod rollbacks the transactions.tx.abort()Session guaranteesBy default, the client will not maintain a session across consecutive transactions, i.e.,
there will be no causal dependency established between two consecutive transaction.To set these dependencies, star a transactionas follows:tx = clt.start_transaction(min_snapshot=clt.last_commit)Operations on objectsTheKeyclass allows to specify the AntidoteDB key for an object.Key( bucket_name, key_name, type_name)read_objectsmethod allows to read the contents of one (or more) objects. On success,read_objectsreturns a list of typed objects (more information next). On failure,read_objectsreturnsNone.key = Key( "some_bucket", "some_key_counter", "COUNTER")
res = tx.read_objects( key)
print( res[0].value())It is also possible to read more than one object.key1 = Key( "some_bucket", "some_key", "COUNTER")
key2 = Key( "some_bucket", "some_other_key", "MVREG")
res = tx.read_objects( [key1,key2])
print( res[0].value())
print( res[1].values())update_objectsmethod allows to update one (or more) objects. On success/failure,update_objectsreturnsTrue/False.key1 = Key( "some_bucket", "some_key", "COUNTER")
res = tx.update_objects( Counter.IncOp(key1, 2))CountersThe data type name for the Counter data type is:COUNTER.key = Key( "some_bucket", "some_key", "COUNTER")The followingread onlyoperations are available in aCounterobject
returned byread_objectsmethod:value(), for accessing the value of an object.res = tx.read_objects( key)
print( res[0].value())The followingupdateoperations are available:Counter.IncOp(key, value), for incrementing a counter.res = tx.update_objects( Counter.IncOp(key, 2))The other counter data type supported by AntidoteDB,FATCountercan be used
usingFATCOUNTERdata type name.Last-writer-wins registerThe data type name for the Last-write-wins Register data type is:LWWREG.key = Key( "some_bucket", "some_key", "LWWREG")The followingread onlyoperations are available in aRegisterobject
returned byread_objectsmethod:value(), for accessing the value of an object.res = tx.read_objects( key)
print( res[0].value())The followingupdateoperations are available:Register.AssignOp( key, val), for assigning a new value to the register.val = bytes("lightkone",'utf-8')

res = tx.update_objects( Register.AssignOp( key, val))Multi-value registerThe data type name for the multi-value Register data type is:MVREG.key = Key( "some_bucket", "some_key", "MVREG")The followingread onlyoperations are available in aMVRegisterobject
returned byread_objectsmethod:values(), for accessing the values of an object. The multiple values are returned in a list.res = tx.read_objects( key)
print( res[0].values())The followingupdateoperations are available:Register.AssignOp( key, val), for assigning a new value to the register.val = bytes("lightkone",'utf-8')

res = tx.update_objects( Register.AssignOp( key, val))SetsThe data type name for theadd-wins setdata type is:ORSET.key = Key( "some_bucket", "some_key", "ORSET")The data type name for theremove-wins setdata type is:RWSET.key = Key( "some_bucket", "some_key", "RWSET")The followingread onlyoperations are available in aSetobject
returned byread_objectsmethod:values(), for accessing the value of the set. The multiple values are returned in a list.res = tx.read_objects( key)
print( res[0].values())The followingupdateoperations are available:Set.AddOp( key, val), for adding values to the set.val1 = bytes("lightkone",'utf-8')
val2 = bytes("syncfree",'utf-8')

res = tx.update_objects( Set.AddOp( key, [val1,val2]))Set.RemoveOp( key, val), for removing values from the set.val1 = bytes("lightkone",'utf-8')
val2 = bytes("syncfree",'utf-8')

res = tx.update_objects( Set.RemoveOp( key, [val1,val2]))FlagsThe data type name for theenable-wins flagdata type is:FLAG_EW.key = Key( "some_bucket", "some_key", "FLAG_EW")The data type name for thedisable-wins flagdata type is:FLAG_DW.key = Key( "some_bucket", "some_key", "FLAG_DW")The followingread onlyoperations are available in aFlagobject
returned byread_objectsmethod:value(), for accessing the value of the flag.res = tx.read_objects( key)
print( res[0].value())The followingupdateoperations are available:Flag.UpdateOp( key, val), for setting a value to the flag.res = tx.update_objects( Flag.UpdateOp( key, True))MapsThe data type name for thegrow-only mapdata type is:GMAP.key = Key( "some_bucket", "some_key", "GMAP")The data type name for therecursive-remove mapdata type is:RRMAP.key = Key( "some_bucket", "some_key", "RRMAP")The followingread onlyoperations are available in aMapobject
returned byread_objectsmethod:value(), for accessing the contents of the map. The map is represented by a Python
dictionary that maps a key to the object.res = tx.read_objects( key)
print( res[0].value())The followingupdateoperations are available:Map.UpdateOp(key,ops), for removing a key from the map.k1 = bytes("k1",'utf-8')
k2 = bytes("k2",'utf-8')
val = bytes("lightkone",'utf-8')

res = tx.update_objects( Map.RemoveOp( key, [Key( "", k1, "COUNTER")]))Map.RemoveOp(key,ops), for executing a set of operations in the objects stored in the map.k1 = bytes("k1",'utf-8')

res = tx.update_objects( Map.RemoveOp( key, [Key( "", k1, "COUNTER")]))Generic operationsThe followingupdateoperations are available in all data types:Type.ResetOp(key), for resetting the value.res = tx.update_objects( Flag.ResetOp(key))Development / ContributingAny help on developing this code is welcome. Feel free to open pull requests or open issues.Testing the AntidoteDB client required an Antidote instance running.
You can use Docker to start an instance in your local machine:docker run -d -p "8087:8087" antidotedb/antidote