Installation & Setup
Installation & Setup
This guide covers installing the Klira AI SDK across different environments and setting up your first integration.
Quick Installation
For most users, the simplest installation method is using pip:
pip install kliraInstallation Options
Standard Installation
The standard installation includes the core SDK with basic functionality:
# Standard installationpip install klira
# With specific versionpip install klira==0.1.0
# Upgrade to latest versionpip install --upgrade kliraFramework-Specific Installations
Install with optional dependencies for specific frameworks:
# For LangChain integrationpip install klira[langchain]
# For CrewAI integrationpip install klira[crewai]
# For LlamaIndex integrationpip install klira[llama-index]
# For all framework integrationspip install klira[all]Development Installation
For contributors or advanced users who want the latest features:
# Clone the repositorygit clone https://github.com/klira-ai/klira-sdk.gitcd klira-sdk
# Install in development modepip install -e .
# Install with development dependenciespip install -e .[dev]System Requirements
Python Version
- Python 3.10 or higher (tested on 3.10, 3.11, 3.12, 3.13)
- Operating Systems: Windows, macOS, Linux
Core Dependencies
The SDK automatically installs these core dependencies:
traceloop-sdk- OpenTelemetry integrationopentelemetry-*- Observability instrumentationpydantic- Data validation and serializationcolorama- Cross-platform colored terminal outputpyyaml- YAML configuration file support
Optional Dependencies
Framework-specific dependencies (installed with extras):
# LangChain ecosystempip install klira[langchain] # Installs: langchain, langchain-openai, langchain-community
# CrewAI ecosystempip install klira[crewai] # Installs: crewai, crewai-tools
# LlamaIndex ecosystempip install klira[llama-index] # Installs: llama-index, llama-index-core
# OpenAI integrationpip install klira[openai] # Installs: openai>=1.0.0
# Anthropic integrationpip install klira[anthropic] # Installs: anthropic
# All integrationspip install klira[all] # Installs all optional dependenciesEnvironment Setup
1. API Key Configuration
Klira AI requires an API key for operation. Set it using one of these methods:
Environment Variable (Recommended):
# Windows PowerShell$env:KLIRA_API_KEY="your-api-key-here"
# Windows Command Promptset KLIRA_API_KEY=your-api-key-here
# Linux/macOSexport KLIRA_API_KEY="your-api-key-here"Configuration File:
Create a .env file in your project root:
KLIRA_API_KEY=your-api-key-hereKLIRA_APP_NAME=my-applicationKLIRA_ENABLED=trueProgrammatic Configuration:
import osfrom klira.sdk import Klira
klira = Klira.init( app_name="MyApp", api_key=os.getenv("KLIRA_API_KEY"), # Recommended: use environment variable enabled=True)2. OpenTelemetry Configuration (Optional)
Configure custom OpenTelemetry endpoints if needed:
# Custom OTLP endpointexport KLIRA_OPENTELEMETRY_ENDPOINT="https://your-otlp-endpoint.com"
# Disable telemetry entirelyexport KLIRA_TRACING_ENABLED=false3. Policy Configuration (Optional)
Set custom policy directories:
# Custom policies directoryexport KLIRA_POLICIES_PATH="/path/to/your/policies"
# Disable policy enforcementexport KLIRA_POLICY_ENFORCEMENT=falseInstallation Verification
Verify your installation with this simple test:
import osfrom klira.sdk import Klirafrom klira.sdk.decorators import workflowfrom klira.sdk.utils.context import set_hierarchy_context
# Initialize SDKklira = Klira.init( app_name="InstallationTest", api_key=os.getenv("KLIRA_API_KEY"), enabled=True)
# Set user contextset_hierarchy_context(user_id="test_user")
# Test decorator@workflow(name="test_workflow", organization_id="test", project_id="test")def test_function(): return "Klira AI SDK is working!"
# Run testresult = test_function()print(f" Installation successful: {result}")Run the test:
python test_installation.pyExpected output:
Installation successful: Klira AI SDK is working!Framework-Specific Setup
OpenAI Agents SDK
# Install Klira AI with OpenAI supportpip install klira[openai]
# Set OpenAI API key (if using OpenAI LLMs)export OPENAI_API_KEY="your-openai-api-key"import osfrom klira.sdk import Klirafrom klira.sdk.decorators import tool, workflowfrom klira.sdk.utils.context import set_hierarchy_contextfrom agents import Agent, Runner
# Initialize Klira AIklira = Klira.init( app_name="OpenAI-Agents-App", api_key=os.getenv("KLIRA_API_KEY"), enabled=True)
# Set user contextset_hierarchy_context(user_id="user_123")
@tool(name="calculator")def calculate(expression: str) -> str: return str(eval(expression))
agent = Agent( name="MathBot", instructions="You are a helpful math assistant", tools=[calculate])
@workflow(name="math_workflow")async def run_agent(query: str): result = await Runner.run(agent, query) return result.final_outputLangChain
# Install Klira AI with LangChain supportpip install klira[langchain]import osfrom klira.sdk import Klirafrom klira.sdk.decorators import workflow, toolfrom klira.sdk.utils.context import set_hierarchy_contextfrom langchain.agents import AgentExecutor, create_openai_tools_agentfrom langchain_openai import ChatOpenAI
# Initialize Klira AIklira = Klira.init( app_name="LangChain-App", api_key=os.getenv("KLIRA_API_KEY"), enabled=True)
# Set user contextset_hierarchy_context(user_id="user_123")
@tool(name="weather_tool")def get_weather(city: str) -> str: return f"Weather in {city}: Sunny, 75°F"
llm = ChatOpenAI()tools = [get_weather]agent = create_openai_tools_agent(llm, tools, "You are a weather assistant")agent_executor = AgentExecutor(agent=agent, tools=tools)
@workflow(name="weather_workflow")def run_weather_agent(query: str): return agent_executor.invoke({"input": query})["output"]CrewAI
# Install Klira AI with CrewAI supportpip install klira[crewai]import osfrom klira.sdk import Klirafrom klira.sdk.decorators import crew, task, agentfrom klira.sdk.utils.context import set_hierarchy_contextfrom crewai import Agent, Task, Crew, Process
# Initialize Klira AIklira = Klira.init( app_name="CrewAI-App", api_key=os.getenv("KLIRA_API_KEY"), enabled=True)
# Set user contextset_hierarchy_context(user_id="user_123")
@agent(name="researcher")def create_researcher(): return Agent( role="Researcher", goal="Research topics thoroughly", backstory="You are an expert researcher", verbose=True )
@task(name="research_task")def create_research_task(agent, topic): return Task( description=f"Research {topic} comprehensively", agent=agent, expected_output="A detailed research report" )
@crew(name="research_crew")def create_crew(): researcher = create_researcher() task = create_research_task(researcher, "AI trends")
return Crew( agents=[researcher], tasks=[task], process=Process.sequential, verbose=True )Virtual Environment Setup
For production deployments, use virtual environments:
Using venv (Python standard library)
# Create virtual environmentpython -m venv klira-env
# Activate (Windows)klira-env\Scripts\activate
# Activate (Linux/macOS)source klira-env/bin/activate
# Install Klira AIpip install klira
# Deactivate when donedeactivateUsing conda
# Create conda environmentconda create -n klira-env python=3.11
# Activate environmentconda activate klira-env
# Install Klira AIpip install klira
# Deactivate when doneconda deactivateUsing Poetry (Recommended for Development)
# Initialize Poetry projectpoetry init
# Add Klira AI dependencypoetry add klira
# Install dependenciespoetry install
# Run in Poetry environmentpoetry run python your_script.pyExample pyproject.toml:
[tool.poetry]name = "my-klira-app"version = "0.1.0"description = "My application using Klira AI SDK"
[tool.poetry.dependencies]python = "^3.10"klira = "^0.1.0"langchain = { version = "^0.1.0", optional = true }crewai = { version = "^0.1.0", optional = true }
[tool.poetry.extras]langchain = ["langchain"]crewai = ["crewai"]all = ["langchain", "crewai"]Docker Setup
For containerized deployments:
Basic Dockerfile
# DockerfileFROM python:3.11-slim
WORKDIR /app
# Install system dependenciesRUN apt-get update && apt-get install -y \ gcc \ && rm -rf /var/lib/apt/lists/*
# Copy requirementsCOPY requirements.txt .
# Install Python dependenciesRUN pip install --no-cache-dir -r requirements.txt
# Copy application codeCOPY . .
# Set environment variablesENV KLIRA_API_KEY=""ENV KLIRA_APP_NAME="dockerized-app"
# Run applicationCMD ["python", "main.py"]requirements.txt
klira==0.1.0# Add other dependencies as neededlangchain>=0.1.0openai>=1.0.0Docker Compose
version: '3.8'
services: klira-app: build: . environment: - KLIRA_API_KEY=${KLIRA_API_KEY} - KLIRA_APP_NAME=my-dockerized-app - KLIRA_TRACING_ENABLED=true ports: - "8000:8000" volumes: - ./policies:/app/policies:ro # Mount custom policiesCommon Installation Issues
Issue 1: Python Version Compatibility
Error: ERROR: Package 'klira' requires a different Python
Solution: Ensure you’re using Python 3.10 or higher:
python --version # Should be 3.10+pip --version # Should use the correct Python versionIssue 2: Dependency Conflicts
Error: ERROR: pip's dependency resolver does not currently have a backtracking strategy
Solutions:
# Option 1: Upgrade pippip install --upgrade pip
# Option 2: Use --force-reinstallpip install --force-reinstall klira
# Option 3: Create fresh virtual environmentpython -m venv fresh-envfresh-env\Scripts\activate # Windowspip install kliraIssue 3: Network/Proxy Issues
Error: ERROR: Could not fetch URL
Solutions:
# Configure proxy (if needed)pip install --proxy http://proxy.company.com:8080 klira
# Use trusted hosts (if SSL issues)pip install --trusted-host pypi.org --trusted-host pypi.python.org klira
# Upgrade certificatespip install --upgrade certifiIssue 4: Permission Issues
Error: ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied
Solutions:
# Option 1: Install for user onlypip install --user klira
# Option 2: Use virtual environment (recommended)python -m venv klira-envklira-env\Scripts\activatepip install kliraNext Steps
After installation, proceed to:
- Quick Start Guide - Get up and running in 5 minutes
- First Example - Complete walkthrough with working code
- Configuration - Detailed configuration options
Getting Help
If you encounter issues:
- Check the Troubleshooting Guide
- Search GitHub Issues
- Contact Support
Supported Python Versions: 3.10, 3.11, 3.12