LucoPy
LucoPy is a Python SDK designed to facilitate interaction with the Luco data observability tool's API. It provides functionality for submitting data quality results, reporting metrics, and managing data slots. The current stable version is 1.3.14, which was released on September 27, 2023.
Common errors
-
API call failed: Authentication token missing or invalid.
cause The `LucoApi` client could not obtain a valid authenticated access token to make API requests, usually due to missing or incorrect authentication parameters (`base_url`, `tenant_id`, `client_id`, `client_secret`, `resource_id`) during initialization, or invalid credentials.fixVerify that all required authentication parameters are correctly provided to the `LucoApi` constructor, either directly or via the specified environment variables (e.g., `LUCO_BASE_ID`, `LUCO_TENANT_ID`, `LUCO_CLIENT_ID`, `LUCO_CLIENT_SECRET`, `LUCO_RESOURCE_ID`). Check for typos or expired secrets. -
AttributeError or KeyError when accessing result from `api.submission.get_metrics()`.
cause This error occurs in LucoPy versions 1.3.3 to 1.3.5 because the return format of `Submission.get_metrics()` was changed.fixUpdate your `lucopy` package to version 1.3.6 or newer (`pip install --upgrade LucoPy`) to use the corrected method signature. Alternatively, if upgrading is not an option, review the specific return format for your exact `lucopy` version (1.3.3-1.3.5) and adjust your code accordingly.
Warnings
- breaking The return format of the `Submission.get_metrics()` method changed in LucoPy versions 1.3.3, 1.3.4, and 1.3.5. This was a potential breaking change for users.
- gotcha LucoPy attempts to load authentication credentials (tenant ID, client ID, client secret, resource ID, base URL) from environment variables if not provided directly during `LucoApi` instantiation. Failure to set these or provide them as arguments will result in authentication errors.
Install
-
pip install LucoPy
Imports
- LucoApi
from LucoPy import LucoApi
Quickstart
import os
from LucoPy import LucoApi
# --- Configuration ---
# It is highly recommended to set these as environment variables.
# Example: export LUCO_BASE_URL="https://your-luco-instance.com/api"
BASE_URL = os.environ.get('LUCO_BASE_URL', 'https://api.luco.data')
TENANT_ID = os.environ.get('LUCO_TENANT_ID', '') # Directory (tenant) ID
CLIENT_ID = os.environ.get('LUCO_CLIENT_ID', '') # Application (client) ID for LucoPy
CLIENT_SECRET = os.environ.get('LUCO_CLIENT_SECRET', '') # Secret value for LucoPy App Registration
RESOURCE_ID = os.environ.get('LUCO_RESOURCE_ID', '') # Application (client) ID of the target API
if not all([TENANT_ID, CLIENT_ID, CLIENT_SECRET, RESOURCE_ID]):
print("Warning: Authentication credentials not fully provided. API calls may fail.")
try:
# Initialize the Luco API client
api = LucoApi(
base_url=BASE_URL,
tenant_id=TENANT_ID,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
resource_id=RESOURCE_ID
)
print(f"Successfully initialized LucoApi client for base URL: {BASE_URL}")
# Example: Check API health (if such an endpoint exists and is public, or requires auth)
# Note: A real health check might require specific authentication.
# For a simple test, we'll just show the client is ready.
# In a real scenario, you would perform operations like:
# from LucoPy.quality import CheckResult, CollectionResult
# check = CheckResult(check_name='MyDataCheck', success=True, observed_value='OK')
# collection = CollectionResult(collection_name='DailyChecks', checks=[check])
# api.submit_quality(collection)
print("LucoPy client ready. You can now make API calls (e.g., submit_quality, get_metrics).")
except Exception as e:
print(f"Error initializing LucoApi: {e}")
print("Please ensure your BASE_URL and authentication credentials are correct.")