The dataculpa-client
is a Python library that allows you to easily send monitoring events to your Data Culpa instance from your Python applications and scripts. It simplifies the process of interacting with the Data Culpa event API endpoint.
You can install the client library using pip:
pip install dataculpa-client
Note: Ensure you are installing the package from the correct repository or source if it's a private package. If you have built the wheel file locally, you would typically install it using pip install /path/to/your/dataculpa_client-0.1.0-py3-none-any.whl
.
The client is configured using environment variables. Before using the client, ensure the following environment variables are set:
DATACULPA_API_BASE_URL
: The base URL of your Data Culpa application (e.g., https://app.dataculpa.com
).DATACULPA_API_KEY
: Your API key obtained from the Data Culpa web interface.DATACULPA_API_CLIENT_SECRET
: Your API client secret obtained alongside your API key.Example of setting environment variables in your shell:
export DATACULPA_API_BASE_URL="https://your-dataculpa-app-url.com"
export DATACULPA_API_KEY="your_actual_api_key"
export DATACULPA_API_CLIENT_SECRET="your_actual_client_secret"
Once installed and configured, you can use the DataCulpaEvent
class to send events. The client sends an event upon instantiation.
from dataculpa_client import DataCulpaEvent
import os # Recommended for production to load sensitive data from env vars
# Ensure environment variables are set as described in Configuration section
# os.environ['DATACULPA_API_BASE_URL'] = "..."
# os.environ['DATACULPA_API_KEY'] = "..."
# os.environ['DATACULPA_API_CLIENT_SECRET'] = "..."
monitor_name = "your_monitor_name" # e.g., "user_signup_process", "data_pipeline_stage1"
object_name = "your_object_name" # e.g., specific user ID, file name, transaction ID
payload = {
"status": "success",
"details": "User XYZ signed up successfully.",
"user_id": "xyz123",
"elapsed_time_ms": 150
}
try:
event = DataCulpaEvent(
monitor_name=monitor_name,
object_name=object_name,
payload=payload
)
print(f"Event sent successfully for monitor '{monitor_name}', object '{object_name}'.")
except Exception as e:
print(f"Failed to send Data Culpa event: {e}")
The monitor_name
typically represents a specific process or component you are monitoring (e.g., user_login_flow
, daily_data_ingestion
).
The object_name
identifies the specific instance or entity related to the event (e.g., a user ID, a transaction ID, a filename).
The payload
is a dictionary containing any relevant data for the event. This can be any JSON-serializable structure.
The client will raise an exception if it fails to send the event (e.g., due to network issues, incorrect API endpoint, authentication failure, or server-side errors). It's recommended to wrap the DataCulpaEvent
instantiation in a try-except block to handle potential errors gracefully.