Skip to main content

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()

Session guarantees

By 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 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

Release files for antidotedb 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for antidotedb 0.1.3
File Size Uploaded
antidotedb-0.1.3.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for antidotedb 0.1.3
File Interpreter ABI Platform
antidotedb-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 32.8 kB

Release files / antidotedb-0.1.3.tar.gz

Download URL antidotedb-0.1.3.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6f4225370a8ead230f95d598e0d4d07e56736dbf78008ed52a620ed1ad3dab3c
BLAKE2b-256 checksum
How to use checksums
19e234665921656bea6cd5a2fd2396ebac89c7ac79be22a4ae0b357a1ac10ba3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

Release files / antidotedb-0.1.3-py3-none-any.whl

Download URL antidotedb-0.1.3-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e0562fb0c209cd4b87473e47ae1f0084cb9f33a6db1ecb25b1ce5c36776db32
BLAKE2b-256 checksum
How to use checksums
3eb1eb307153bc941af1138011ac89b18964f37e383071236479e02de4277230
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.8

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page