pylabelbase is our official API wrapper.


pip install pylabelbase


First, import pylabelbase and initialize with your API key:

from pylabelbase import LabelbaseAPI

api_key = "your_api_key" # 
api = LabelbaseAPI(api_key) # cloud-hosted Labelbase
api = LabelbaseAPI(api_key, base_url="") # your locally hosted Labelbase

Working with Labelbases

# List all labelbases
labelbases = api.list_labelbases()

# Create a new labelbase
new_labelbase = api.create_labelbase(name="New Labelbase")

# Update a labelbase
api.update_labelbase(labelbase_id=1, name="Updated Name")

# Change current active labelbase

# Delete a labelbase

Managing Labels (CRUD)

# Create a new label
label = api.create_label(label_type="tx", ref="transaction_ref", label="Transaction Label")

# Get (read) a label
retrieved_label = api.get_label(label_id=label['id'])

# Update a label
api.update_label(label_id=label['id'], label="Updated Label")

# Delete a label

Additional Features

Find Label by Reference and Type

The find_label_by_ref_and_type method allows you to find the first label that matches a given reference and type within a labelbase. This is particularly useful in scenarios where a labelbase might have multiple labels with the same reference and type combination.

label = api.find_label_by_ref_and_type(ref="reference_here", type="type_here")

Get or Create Label by Reference and Type

The get_or_create_label_by_ref_and_type method retrieves the first label that matches the provided reference and type. If no such label exists, it creates a new label with the specified parameters.

label = api.get_or_create_label_by_ref_and_type(ref="reference_here", type="type_here", additional_param1="value1")

Update or Create Label by Reference and Type

The update_or_create_label_by_ref_and_type method updates the first label matching the specified reference and type. If no label is found, it creates a new label. This method ensures that only the intended fields are updated, while others remain unchanged.

label = api.update_or_create_label_by_ref_and_type(ref="reference_here", type="type_here", additional_param1="value1")


pylabelbase is released under the MIT License.