Installation

Install the latest version of the Praxos Python SDK:
pip install -U praxos-python
Current Version: 0.3.2+ Python Compatibility: Python 3.8+ Dependencies: pydantic, httpx For development installation from source:
git clone https://github.com/praxos/praxos-python
cd praxos-python
pip install -e .

Getting Started

To start using the Praxos client, you’ll need to initialize it with your API key:
from praxos_python import SyncClient

client = SyncClient(api_key="your-api-key")

Configuration Options

The client accepts several configuration options:
  • api_key (required): Your Praxos API key
  • base_url (optional): Custom base URL for the API (default: “https://api.praxos.ai/”)
  • params (optional): Additional query parameters to include in all requests
  • timeout (optional): Request timeout in seconds (default: 10.0)
# Advanced client configuration
client = SyncClient(
    api_key="prx_your_api_key_here",
    base_url="https://api.praxos.ai/",
    timeout=30.0,
    params={"version": "v1"}  # Optional global parameters
)

API Key Validation

The client includes built-in API key validation:
# Validate your API key
try:
    is_valid = client.validate_api_key()
    print(f"API key is valid: {is_valid}")
except APIKeyInvalidError:
    print("Invalid API key - please check your credentials")

Environment Management

Creating an Environment

# Create a new environment
environment = client.create_environment(name="my-environment")

# Create an environment with description and ontologies
environment = client.create_environment(
    name="my-environment",
    description="Environment for processing customer data",
    ontologies=["customer-ontology-id"]  # List of ontology IDs or SyncOntology objects
)

Retrieving Environments

# Get all environments
environments = client.get_environments()

# Get a specific environment by ID
environment = client.get_environment(id="env-123")

# Get a specific environment by name
environment = client.get_environment(name="my-environment")

Ontology Management

Ontologies define the structure and types of data that your environment can process. They use Pydantic models to define schemas for entity extraction and validation.

Creating an Ontology

from pydantic import BaseModel, Field
from typing import Optional

# Define your data schemas using Pydantic models
class Person(BaseModel):
    name: str = Field(description="Full name of the person")
    age: Optional[int] = Field(description="Age in years")
    email: Optional[str] = Field(description="Email address")

class Organization(BaseModel):
    name: str = Field(description="Organization name")
    industry: Optional[str] = Field(description="Industry sector")
    employees: Optional[int] = Field(description="Number of employees")

# Create an ontology with multiple schemas
ontology = client.create_ontology(
    name="business-ontology",
    description="Ontology for business entities",
    schemas=[Person, Organization]
)

Retrieving Ontologies

# Get all ontologies
ontologies = client.get_ontologies()

# Get a specific ontology by ID
ontology = client.get_ontology(id="onto-123")

# Get a specific ontology by name
ontology = client.get_ontology(name="business-ontology")

Error Handling

The client includes built-in error handling for common API issues:
  • APIError: General API errors
  • APIKeyInvalidError: Invalid API key errors
Example error handling:
from praxos_python.exceptions import APIError, APIKeyInvalidError

try:
    environment = client.create_environment(name="my-environment")
except APIKeyInvalidError:
    print("Invalid API key")
except APIError as e:
    print(f"API error: {e.message}")

Additional Imports

The SDK provides several model classes and utilities that you can import:
from praxos_python import (
    SyncClient,
    SyncEnvironment, 
    SyncSource,
    SyncOntology,
    APIError
)

# For message handling in conversations
from praxos_python.types import Message

# For search result handling
from praxos_python.models import Context

Resource Management

The client implements Python’s context manager protocol, allowing you to use it with the with statement:
with SyncClient(api_key="your-api-key") as client:
    environment = client.create_environment(name="my-environment")
    # Client will be automatically closed when exiting the context