Skip to main content

Python SDK

The labii-sdk package provides resource objects for common Labii API operations. For custom endpoints that do not have a resource method, use the lower-level client available through labii.api.

Install​

pip install labii-sdk

The package requires Python 3.8 or later.

Quick start​

Import LabiiObject.

from labii_sdk.sdk import LabiiObject

Create an SDK object with your company SID and API key.

labii = LabiiObject(
organization__sid="{{organization_sid}}",
api_key="{{api_key}}",
)

For a dedicated Labii deployment, also set base_url.

Call a resource method.

tables = labii.Table.list(serializer="list")

Initialize the SDK​

LabiiObject accepts these arguments:

  • organization__sid: The company SID used by organization-level list endpoints.
  • base_url: The API base URL. The default is https://www.labii.dev.
  • email and password: Credentials retained by the API client for token login.
  • api_key: A bearer API key.
  • api: An existing APIObject. When supplied, the SDK uses that client instead of creating one.
from labii_sdk.api_client import APIObject
from labii_sdk.sdk import LabiiObject

api = APIObject(
base_url="https://www.labii.dev",
api_key="{{api_key}}",
organization__sid="{{organization_sid}}",
)

labii = LabiiObject(
organization__sid="{{organization_sid}}",
api=api,
)

To authenticate with an email and password instead of an API key, initialize the object with those credentials and call labii.api.login() before making authenticated requests.

Resource objects​

Every resource object exposes create, list, retrieve, modify, and delete. The API can reject a method that the corresponding endpoint does not support.

The current SDK defines these resources:

  • Accounts: Profile, APIKey
  • Companies: Organization, Personnel, Team, OrganizationWidget, SAML, Backup, Certification, Invoice, Subscription, Credit, Seat, Provider
  • Workspaces and applications: Workspace, WorkspacePermission, Application
  • Tables: Table, Column, Section, Filter, Record, Cell, Signer, Version, Visitor, Activity, Permission
  • Other resources: Widget, Workflow, Dashboard, Notification, Video, Shortenurl, Ticket, GPT, Conversation, Question

The Python SDK calls the row resource Record. Use labii.Record, not labii.Row.

See the API reference for supported endpoints and required query parameters.

Standard methods​

list​

list returns a paginated response.

response = labii.Record.list(
page=1,
page_size=10,
all_pages=False,
level="organization",
serializer="list",
query="table__sid={{table_sid}}&is_archived=false",
)

for row in response["results"]:
print(row["sid"], row["name"])

Arguments:

  • page: Page number. The default is 1.
  • page_size: Results per page. The default is 10.
  • all_pages: When True, the client follows pagination and combines all results. The default is False.
  • level: List scope. The default is organization.
  • serializer: Response representation. The default is list.
  • query: Query string without a leading ?.

create​

Pass the request body as a Python dictionary. Add query when the endpoint requires a parent resource.

workspace = labii.Workspace.create({
"name": "Research",
"description": "Research workspace",
})

row = labii.Record.create(
{
"name": "Sample 1",
"workspaces": [{"sid": "{{workspace_sid}}"}],
},
query="table__sid={{table_sid}}",
)

retrieve​

Pass the resource SID.

workspace = labii.Workspace.retrieve("{{workspace_sid}}")
row = labii.Record.retrieve("{{row_sid}}")

modify​

Pass the resource SID and fields to update.

workspace = labii.Workspace.modify(
"{{workspace_sid}}",
{"name": "Updated research workspace"},
)

delete​

Pass the resource SID. The endpoint must support deletion.

labii.WorkspacePermission.delete("{{workspace_permission_sid}}")

All standard methods accept an optional query string.

Create rows in bulk​

Record.bulk_create accepts any number of rows and sends them in batches of 50. The query must include table__sid.

rows = [
{"name": "Sample 1", "workspaces": [{"sid": "{{workspace_sid}}"}]},
{"name": "Sample 2", "workspaces": [{"sid": "{{workspace_sid}}"}]},
]

results = labii.Record.bulk_create(
rows,
query="table__sid={{table_sid}}",
)

for result in results:
if "error" in result:
print(f"Row {result['index'] + 1} failed: {result['error']}")
else:
print(f"Created {result['sid']}")

Each result contains the input index and either sid and name or an error. If an entire batch fails, the SDK returns an error result for every row in that batch.

File upload​

upload creates a record in the Files table, uploads the file, and returns the created or updated record when the upload succeeds.

file_record = labii.upload(
"/path/to/results.csv",
[{"sid": "{{workspace_sid}}"}],
)

Arguments:

  • file_path: Full path to the file.
  • workspaces: Workspace objects in the form [{"sid": "{{workspace_sid}}"}].

The current LabiiObject does not expose a watch_folder method.

Utilities​

Switch company​

switch_organization updates the company SID on both the SDK object and its API client.

labii.switch_organization("{{organization_sid}}")

Get column SIDs by name​

get_columns returns a dictionary that maps column names to SIDs.

columns = labii.get_columns(
"table__sid={{table_sid}}&name__in=volume,concentration,storage"
)

print(columns["volume"])