Python client for interacting with Kubiya platform APIs
The Kubiya Client SDK provides a comprehensive Python interface to all Kubiya platform services, enabling you to programmatically manage agents, workflows, integrations, secrets, and knowledge.What it provides:
Type-safe Python interfaces to platform services
Automatic authentication and request handling
Streaming support for real-time updates
Comprehensive error handling with specific exceptions
from kubiya import ControlPlaneClient# Initialize the client (reads KUBIYA_API_KEY from environment)client = ControlPlaneClient()# Or pass the API key directlyclient = ControlPlaneClient( api_key="your-api-key", base_url="https://control-plane.kubiya.ai")# Use platform servicesagents = client.agents.list()teams = client.teams.list()secrets = client.secrets.list()
client = ControlPlaneClient( api_key="your-api-key", base_url="https://control-plane.kubiya.ai", timeout=300, # Request timeout in seconds max_retries=3, # Maximum number of retry attempts org_name="your-org" # Organization name for API calls)
# Activate GitHub App integrationresult = client.integrations.activate("github_app")if result.get("success"): print(f"Install GitHub App at: {result.get('install_url')}")# List active integrationsintegrations = client.integrations.list()# Get credentials for a specific integrationcredentials = client.integrations.get_integration_credentials( vendor="aws", id="aws")
# Query knowledgeresponse = client.knowledge.query( prompt="How do I deploy a Kubernetes application?")print(response)# Stream search resultsfor event in client.knowledge.query( prompt="Best practices for container security", stream=True): print(event)
For non-blocking operations, use the async client:
Copy
Ask AI
from kubiya import StreamingKubiyaClientimport asyncioasync def main(): async with StreamingKubiyaClient(api_key="your-api-key") as client: # Async workflow execution async for event in client.execute_workflow_stream(workflow_dict): print(f"Event: {event}")asyncio.run(main())
def validate_workflow(workflow_def): if not isinstance(workflow_def, dict): raise ValueError("Workflow definition must be a dictionary") if "name" not in workflow_def: raise ValueError("Workflow must have a name") return workflow_def# Use validationvalidated_workflow = validate_workflow(my_workflow)result = client.workflows.execute(validated_workflow, params)
# List items with paginationlimit = 10offset = 0while True: agents = client.agents.list(limit=limit, offset=offset) if not agents: break for agent in agents: print(f"Agent: {agent['name']}") offset += limit
For advanced orchestration and infrastructure use cases, the SDK also includes a ControlPlaneClient for accessing internal services like the context graph, models, and skills.Learn about Control Plane Client →