Dinemic has released Python wrapper for libdinemic. Now you can use robustness of this tool directly in Python3.

Update

Official documentation for pydinemic and instructions for stable version could be found here

Installation

First, get latest version of libdinemic from packages.dinemic.io:

wget https://packages.dinemic.io/nightly/ubuntu-18.04/current/libdinemic_19.07.72903994_amd64.deb
sudo dpkg -i libdinemic_19.07.72903994_amd64.deb

then install Boost::Python dependency:

sudo apt install python3-dev libboost-python-dev

and finally install dinemic:

sudo pip3 install dinemic

First steps

Now, when dinemic is installed, we can write some code in Python. Let’s start with database model:

import dinemic

# Let's start Dinemic agent
dinemic.launch()

class MyModel(dinemic.DModel):
    name = dinemic.DField('Name', False)
    # Encrypted field keeping our salary
    salary = dinemic.DField('Salary', True)

my_model = MyModel('MyModel', [])

Above code will create new instance of MyModel class, without any additional authorized keys. We can recreate this object anywhere, from owned ID:

my_existing_model = MyModel('MyModel:qj203fr...', '')
my_existing_model.name = 'Bob'

Above code will create local instance of MyModel class, but it won’t be able to create signed changes until we have valid cryptographic keys from machine, where it was created

Listeners

Another feature of dinemic is to use listeners mechanism known from C++ Dinemic framework. To monitor changes in your model or any part of database, just inherit Listener class:

import dinemic
dinemic.launch()

class Listener(dinemic.DAction):
    create = False
    created = False
    update = False
    updated = False
    
    def on_create(self, object_id, key):
        # Do something when object is going to be created
        pass

    def on_created(self, object_id, key):
        # Do something when object was created
        pass
    
    def on_update(self, object_id, key, old_value, new_value):
        print('Hey! I'm going to change to: ' + new_value)

and then we could assign this listener to our data model:

    
listener = Listener()
listener.apply('MyModel:[id]')
listener.apply('MyModel:[id]:*')

Acknowledgements

The dinemic module is still under development. It should gain some more features known from C++ Dinemic framework soon, like authorized keys support, better filtering of signed/unsigned updates on models and so on.

Keep checking our website to be up to date