Skip to main content

AntidoteDB Python clients

Project description

Antidote Python Client

The 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 Database here

Installation

For installing the Python AntidoteDB client, just use pip installer.

pip antidotedb

Documentation

The classes for accessing AntidoteDB are in package antidotedb.

For accessing AntidoteDB, you should start by creating an AntidoteClient object, as in the following example.

from antidotedb import *

server = 'locahost'
port = 8087

clt = AntidoteClient(server, port)

Interactive transactions

start_transaction starts an interactive transactions. On failure, start_transaction method raises an AntidoteException.

tx = clt.start_transaction()

commit method commits a sequence of operations executed in a transaction. On success, the commit method returns True.

ok = tx.commit()

abot method rollbacks the transactions.

tx.abort()

Operations on objects

The Key class allows to specify the AntidoteDB key for an object.

Key( bucket_name, key_name, type_name)

read_objects method allows to read the contents of one (or more) objects. On success, read_objects returns a list of typed objects (more information next). On failure, read_objects returns None.

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_objects method allows to update one (or more) objects. On success/failure, update_objects returns True/False.

key1 = Key( "some_bucket", "some_key", "COUNTER")
res = tx.update_objects( Counter.IncOp(key1, 2))

Counters

The data type name for the Counter data type is: COUNTER.

key = Key( "some_bucket", "some_key", "COUNTER")

The following read only operations are available in a Counter object returned by read_objects method:

  • value(), for accessing the value of an object.

    res = tx.read_objects( key)
    print( res[0].value())
    

The following update operations 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, FATCounter can be used using FATCOUNTER data type name.

Last-writer-wins register

The data type name for the Last-write-wins Register data type is: LWWREG.

key = Key( "some_bucket", "some_key", "LWWREG")

The following read only operations are available in a Register object returned by read_objects method:

  • value(), for accessing the value of an object.

    res = tx.read_objects( key)
    print( res[0].value())
    

The following update operations 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 register

The data type name for the multi-value Register data type is: MVREG.

key = Key( "some_bucket", "some_key", "MVREG")

The following read only operations are available in a MVRegister object returned by read_objects method:

  • 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 following update operations 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))
    

Sets

The data type name for the add-wins set data type is: ORSET.

key = Key( "some_bucket", "some_key", "ORSET")

The data type name for the remove-wins set data type is: RWSET.

key = Key( "some_bucket", "some_key", "RWSET")

The following read only operations are available in a Set object returned by read_objects method:

  • 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 following update operations 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]))
    

Flags

The data type name for the enable-wins flag data type is: FLAG_EW.

key = Key( "some_bucket", "some_key", "FLAG_EW")

The data type name for the disable-wins flag data type is: FLAG_DW.

key = Key( "some_bucket", "some_key", "FLAG_DW")

The following read only operations are available in a Flag object returned by read_objects method:

  • value(), for accessing the value of the flag.

    res = tx.read_objects( key)
    print( res[0].value())
    

The following update operations are available:

  • Flag.UpdateOp( key, val), for setting a value to the flag.

    res = tx.update_objects( Flag.UpdateOp( key, True))
    

Maps

The data type name for the grow-only map data type is: GMAP.

key = Key( "some_bucket", "some_key", "GMAP")

The data type name for the recursive-remove map data type is: RRMAP.

key = Key( "some_bucket", "some_key", "RRMAP")

The following read only operations are available in a Map object returned by read_objects method:

  • 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 following update operations 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 operations

The following update operations are available in all data types:

  • Type.ResetOp(key), for resetting the value.

    res = tx.update_objects( Flag.ResetOp(key))
    

Development / Contributing

Any 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for antidotedb, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size antidotedb-0.1.1-py3-none-any.whl (17.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size antidotedb-0.1.1.tar.gz (14.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page