SDK (python)
Labii SDK
SDK is the toolkit with prebuilt Labii components that developers use to interact with Labii APIs. Full documentation available at https://docs.labii.com/api/overview

Usage

  1. 1.
    Install the Labii SDK
pip install labii-sdk
2. Import the package
from labii_sdk.sdk import LabiiObject
3. Initial the API object
labii = LabiiObject()
4. Start querying
# login
labii.api.login()
# get a list of tables
labii.Tables.list()

Initial SDK

During SDK initiation, the following parameters can be customized:
  • base_url, the server base URL, defaults to https://www.labii.dev. If you are using a different data center, make sure to change the base_url setting.
  • email and password, the email or password to get authenticated. If no email or password is provided, a pop-up will appear.
  • organization__sid, your organization sid. You can find it by logging into Labii (https://www.labii.com/login/) and going to Side menu -> Settings -> Organization -> Sid
api = LabiiObject(
base_url="https://www.labii.dev",
email=None,
password=None,
organization__sid=None
)

Objects

Labii objects for interaction. Learn more at https://docs.labii.com/api/overview#objects
  • Organization
  • Application
  • Subscription
  • People
  • Team
  • SAML
  • OrganizationWidget
  • Backup
  • Project
  • ProjectMember
  • Table
  • Column
  • Section
  • Filter
  • Record
  • Cell
  • Version
  • Visitor
  • Activity
  • Workflow
  • Step
  • Widget

Methods

A list of methods for interacting with objects.

create

Create a object.
# Create a project
labii.Project.create({name="test", ...})
# Create a table
labii.Table.create({name_singular="test", ...})
# Create a row
labii.Record.create{{name="test", ...}, query="table__sid=xxx"}

retrieve

Return a object
  • sid, the sid of the object
  • query (optional), additional query to limit the results.
# Return a project
labii.Project.retrieve("psvy0a40x18c0rwBGLQV1")
# Return a record
labii.Row.retrieve("psvy0a40x18c0rwBGLQV1")

list

Get a list of objects
  • page (default=1), the page number to return.
  • page_size (default=10), the number of items to be paginated.
  • all_pages (bool, default=False), Whether all pages should be returned. When False, only return the data for the first page. Only applies to list views.
  • level (default to "organization"), the scope of records to retrieve. Learn more at https://docs.labii.com/api/overview#levels
  • serializer (default to "list"), the scope of fields of the return data. Learn more at https://docs.labii.com/api/overview#serializer
    • name, return only sid and name, very fast
    • list, return selected fields of the objects, fast
    • detail, return all fields of the objects, slow
  • query (optional), additional query to limit the results.
# Return first page of experiment records
labii.Row.list(
page=1,
page_size=10,
all_pages=False,
level="organization",
serializer="name",
query="table__sid=psvy0a40x18c0rwBGLQV1&is_archived=false"
)
# Return list of projects
labii.Project.list()

modify

Edit an object
  • sid, the sid of the object
  • data (dict), a JSON dict data to post. Learn more at https://docs.labii.com/api/methods
  • query (optional), additional query to limit the results.
# modify the name of a project
labii.Project.modify(
sid="psvy0a40x18c0rwBGLQV1",
data={"name": "new name"}
)

delete

Remove an object
  • sid, the sid of the object
  • query (optional), additional query to limit the results.
Not all objects can be deleted. A 405 error will be displayed if an object cannot be deleted.
# remove the permission of a user
labii.ProjectMember.delete("psvy0a40x18c0rwBGLQV1")

upload

Upload the content of a file.
  • sid, the sid of the file record
  • filename , the file name with full path.
A file record should be created first
# create a file record
response = labii.Record.create(
{
"name": "test.txt"
},
query="table__sid=[file table sid]"
)
# upload the file content
file_record = labii.Record.upload(response["sid"], "/tmp/test.txt")

watch_folder

You can use this function to watch a particular folder. As soon as the file(s) are present, the function will upload each file to Labii and move the file to the "uploaded" subfolder. This function allows you to upload files generated by a machine/equipment automatically.
Version 1.9 or later is required to use this function.
  • folder_path, optional, the folder (including the path) to watch. default to current path.
  • project__sids, optional, list of project sids. Files will be uploaded to these projects if they are defined. When the sids are not defined, you will be asked for them.
  • interval, optional, time interval to check the folder, default to 5 seconds.
// Watch a results folder
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(organization__sid="xxx") # do not forgot to provide the base_url if not us data center
labii.api.login(email="xxx", password="xxx")
labii.Record.watch_folder(folder_path="./results", project__sids="xxx")