Python

Using the Marple Python SDK

We created an SDK for Python that makes it easier to use our API. Install the marpledata module:

pip install marpledata

Usage

First setup the connection using an access token:

from marple import Marple
m = Marple(ACCESS_TOKEN)
m.check_connection()

Calling API endpoints is as easy as:

m.get('/version')
m.post('/sources/info', json={'id': 98})

Uploading data can be done in various ways:

  • Upload a file using the SDK

  • A pandas dataframe

  • Write data in chunks

These three commands will all upload a file test.csv to the /examplefolder in your workspace:

source_id = m.upload_data_file('.../test.csv', '/example', metadata={'key': 'value'})
source_id = m.upload_data_pandas(dataframe, 'test', '/example')

for row in dataframe.itertuples(index=False):
    data_dict = row._asdict()
    m.add_data(data_dict)
    
source_id = m.send_data('test', 'example')

Once your data is uploaded, it needs to be imported. During importing, Marple will efficiently store the data, to enable fast visualisation later on. Here you can find more info about the available plugins and there config settings.

path = '/example/test.csv' # path to the file in the Marple library
m.post(
  '/library/file/import', 
  json={'path': path, 'plugin': plugin, 'config': {'common': [{'name': 'time_offset', 'value': time_offset}]}}
)

Depending on the size of the dataset, importing can take a while. To check the import status:

The returned status is a number in [0, 100], representing the progress of the import in %. 100 means the import has finished.

status = m.check_import_status(source_id)

Negative status codes inform you about the following events:

  • -3 = Finalising, Marple is improving its cache to make the file faster

  • -2 = Waiting in the importing queue

  • -1 = Failed, something went wrong. Check the UI for more details about the error message

More details can be found at https://pypi.org/project/marpledata

Last updated