0. Write a plugin function with a decorator
Plugins are native python functions, that take in a single parameter. The following example should be save in a file my-plugin.py
import transport
import numpy
as np
_index = 0
@transport.Plugin(name='autoincrement')
def _incr (_data):
global _index
_data['_id'] = _index + np.arange(_data.shape[0])
_index = _data.shape[0]
return _data
1. Register & test the plugin
The plugin utility will make a copy of the file and allow it to be reused against any supported database techology.
More information is available when running
$ transport plugins add myplugin my-plugin.py
Once registered it is important to see if the function can be tested
$ plugin-ix registry list --folder ~/.data-transport
Using our first plugin
Plugins are used as pipelines i.e you can add more than one and they will execute accordingly in the order in which they are expressed.
import transport
dbreader = transport.get.reader(label="address-db",plugins=["_incr@myplugin"])
_df = dbreader.read()
The code above shows how a simple plugin function can be applied to a data
address-db, is the database label that points to the url with data
myplugin, points to a copy of "incr" in "my-plugin.py"