Skip to main content

Documentation Index

Fetch the complete documentation index at: https://datagen.dev/llms.txt

Use this file to discover all available pages before exploring further.

Installation

pip install datagen-python-sdk
Requires Python 3.10+.

Client Configuration

from datagen_sdk import DatagenClient

client = DatagenClient(
    api_key=None,           # Default: reads from DATAGEN_API_KEY env var
    base_url="https://api.datagen.dev",
    timeout=30,             # Request timeout in seconds
    retries=0,              # Retry attempts for failed requests
    backoff_seconds=0.5     # Initial backoff (exponential with 2^attempt multiplier)
)
ParameterTypeDefaultDescription
api_keyOptional[str]NoneAPI key. Falls back to DATAGEN_API_KEY env var
base_urlstr"https://api.datagen.dev"DataGen API base URL
timeoutint30Request timeout in seconds
retriesint0Number of retry attempts
backoff_secondsfloat0.5Initial backoff time for retries

Tool Execution

execute_tool

Execute an MCP tool by its alias name.
result = client.execute_tool(
    tool_alias_name: str,
    parameters: Optional[Dict[str, Any]] = None
) -> Any
ParameterTypeRequiredDescription
tool_alias_namestrYesTool alias (e.g., "mcp_Gmail_gmail_send_email")
parametersDict[str, Any]NoTool-specific parameters
Returns: Tool execution result (type varies by tool). Raises: DatagenAuthError, DatagenToolError, DatagenHttpError

Custom Tool Deployment

deploy_custom_tool

Deploy a Python workflow as an API endpoint.
result = client.deploy_custom_tool(
    name: str,
    code: str,
    description: Optional[str] = None,
    input_schema: Optional[Dict[str, Any]] = None,
    output_vars: Optional[List[str]] = None,
    expected_tools: Optional[List[str]] = None,
    additional_imports: Optional[List[str]] = None,
    deployment_type: str = "private",
    default_input_vars: Optional[Dict[str, Any]] = None,
    mcp_server_names: Optional[List[str]] = None,
    required_secrets: Optional[List[str]] = None,
) -> Dict[str, Any]
ParameterTypeRequiredDefaultDescription
namestrYesAPI name for the tool
codestrYesPython code to deploy
descriptionstrNoNoneTool description
input_schemaDictNoNoneOpenAPI/JSON Schema for inputs
output_varsList[str]NoNoneOutput variable names
expected_toolsList[str]NoNoneRequired MCP tools
additional_importsList[str]NoNonePython packages
deployment_typestrNo"private""private" or "public"
default_input_varsDictNoNoneDefault input values
mcp_server_namesList[str]NoNoneMCP server names
required_secretsList[str]NoNoneRequired secret names
Returns: Dict with deployment_uuid and deployment details. Raises: DatagenDeploymentError

update_custom_tool

Update an existing custom tool. Only provided fields are updated.
result = client.update_custom_tool(
    deployment_uuid: str,
    name: Optional[str] = None,
    description: Optional[str] = None,
    code: Optional[str] = None,
    input_schema: Optional[Dict[str, Any]] = None,
    output_vars: Optional[List[str]] = None,
    default_input_vars: Optional[Dict[str, Any]] = None,
    additional_imports: Optional[List[str]] = None,
    expected_tools: Optional[List[str]] = None,
    required_secrets: Optional[List[str]] = None,
) -> Dict[str, Any]
ParameterTypeRequiredDescription
deployment_uuidstrYesUUID of the tool to update
namestrNoUpdated name
descriptionstrNoUpdated description
codestrNoUpdated Python code
input_schemaDictNoUpdated input schema
output_varsList[str]NoUpdated output variables
default_input_varsDictNoUpdated default inputs
additional_importsList[str]NoUpdated imports
expected_toolsList[str]NoUpdated required tools
required_secretsList[str]NoUpdated required secrets
Returns: Dict with updated deployment details. Raises: DatagenDeploymentError

get_custom_tool

Get details of a custom tool.
result = client.get_custom_tool(deployment_uuid: str) -> Dict[str, Any]

list_custom_tools

List all custom tools.
result = client.list_custom_tools(
    sort_by: str = "created_at",
    order_by: str = "desc",
    skip: int = 0,
    limit: int = 100,
) -> List[Dict[str, Any]]
ParameterTypeDefaultDescription
sort_bystr"created_at"Sort field
order_bystr"desc""asc" or "desc"
skipint0Pagination offset
limitint100Max results

Custom Tool Execution

run_custom_tool

Run a custom tool synchronously (blocks until complete).
result = client.run_custom_tool(
    deployment_uuid: str,
    input_vars: Optional[Dict[str, Any]] = None,
    execution_timeout: int = 120,
) -> Dict[str, Any]
ParameterTypeRequiredDefaultDescription
deployment_uuidstrYesTool UUID
input_varsDictNoNoneInput variables
execution_timeoutintNo120Max execution time in seconds
Returns: Dict with run_uuid, status, and output_vars. Raises: DatagenDeploymentError

run_custom_tool_async

Run a custom tool asynchronously (returns immediately).
result = client.run_custom_tool_async(
    deployment_uuid: str,
    input_vars: Optional[Dict[str, Any]] = None,
    execution_timeout: int = 120,
) -> Dict[str, Any]
Same parameters as run_custom_tool. Returns: Dict with run_uuid and status: "pending". Raises: DatagenDeploymentError

check_run_status

Check the status of a custom tool run.
result = client.check_run_status(run_uuid: str) -> Dict[str, Any]
Returns: Dict with run_uuid and status ("pending", "running", "completed", or "failed").

get_run

Get full details of a custom tool run including output.
result = client.get_run(run_uuid: str) -> Dict[str, Any]
Returns: Dict with complete run details including output_vars.

wait_for_run

Poll until an async run completes or fails.
result = client.wait_for_run(
    run_uuid: str,
    timeout: int = 300,
    poll_interval: float = 2.0,
) -> Dict[str, Any]
ParameterTypeDefaultDescription
run_uuidstrRun UUID
timeoutint300Max wait time in seconds
poll_intervalfloat2.0Seconds between status checks
Returns: Final run result with output_vars. Raises: DatagenDeploymentError on failure or timeout.

Secret Management

list_secrets

List all secrets (values are never returned).
result = client.list_secrets() -> List[Dict[str, Any]]
Returns: List of secret metadata (name, masked_value, provider, etc.).

set_secret

Create or update a secret.
result = client.set_secret(
    name: str,
    value: str,
    display_name: Optional[str] = None,
    description: Optional[str] = None,
    category: str = "api_key",
    force: bool = False,
) -> Dict[str, Any]
ParameterTypeRequiredDefaultDescription
namestrYesSecret name (alphanumeric, underscores, hyphens)
valuestrYesSecret value
display_namestrNoNoneHuman-readable name
descriptionstrNoNoneDescription
categorystrNo"api_key"Secret category
forceboolNoFalseIf True, updates existing secret
Raises: DatagenSecretError if secret exists and force=False.

Error Types

All exceptions inherit from DatagenError.
ExceptionDescription
DatagenErrorBase exception class
DatagenAuthErrorAuthentication failed (401/403) or missing API key
DatagenToolErrorTool execution failed
DatagenHttpErrorHTTP-level errors (4xx/5xx)
DatagenDeploymentErrorCustom tool deployment or run failed
DatagenSecretErrorSecret management errors
from datagen_sdk import (
    DatagenClient,
    DatagenError,
    DatagenAuthError,
    DatagenToolError,
    DatagenHttpError,
    DatagenDeploymentError,
    DatagenSecretError,
)