Skip to content

Python SDK Overview

ai-lib-python (v1.1.0) is the Python runtime for AI-Protocol. Unlike Rust’s workspace crates, Python ships as one package with clear execution / policy module separation:

LayerModulesRole
Execution (E)client, protocol, pipeline, transport, types, structured, optional capability modulesManifest loading, operator pipeline, httpx transport
Policy (P)resilience, cache, routing, plugins, guardrails, batch, telemetry, tokensRetry, rate limits, routing — opt-in beside the client

For chat, AiClient does not call ProviderDriver. It:

  1. Loads a provider manifest (ProtocolLoader)
  2. Builds a Pipeline from manifest operators
  3. Sends HTTP via HttpTransport (httpx)
  4. Emits unified StreamingEvent values (Pydantic models)

Provider-specific logic still exists (SSE decoders, optional drivers, standalone service clients), but the default integration path is manifest + pipeline.

Always exported from ai_lib_python:

  • AiClient, AiClientBuilder, ChatResponse, CallStats
  • Message, MessageRole, MessageContent, ContentBlock, StreamingEvent, ToolCall, ToolDefinition
  • AiLibError, ProtocolError, TransportError
  • Feature probes: HAS_VISION, HAS_AUDIO, HAS_TELEMETRY, HAS_TOKENIZER, HAS_WATCHDOG, HAS_KEYRING, require_extra

Import subpackages explicitly when needed: resilience, structured, embeddings, mcp, computer_use, drivers, etc.

  • Manifest loading: V1 + V2 paths (dist/v2/providers/*.json, v2/providers/*.yaml, …)
  • Standard error codes: 13 codes (E1001–E9999)
  • Structured output: structured module
  • Text-tool / TTC: types under ai_lib_python.types.text_tool
  • Capability registry: registry.CapabilityRegistry with pip-extra detection
AreaIn the packageNot included
MCPMcpToolBridge format conversionMCP server transport wired into AiClient
Computer UseComputerAction, SafetyPolicy validationScreenshot / input execution environment
Embeddings / STT / TTS / RerankStandalone HTTP clientsFull pipeline operators for every modality
Hot reloadBuilder flag + in-memory cacheAutomatic file watching (needs watchdog; not wired end-to-end)
ProviderDriverPublic drivers moduleDefault AiClient chat path
  • AiClient — async entry point (await AiClient.create("provider/model"))
  • ChatRequestBuilder.messages(), .system(), .user(), .stream(), .execute(), .execute_with_stats()
  • AiClientBuilder.production_ready(), .hot_reload(), resilience knobs
  • ProtocolLoader, ProtocolManifest, validators
  • V2 types under protocol.v2

Decoder → Selector → Accumulator → FanOut → EventMapper (configured from manifests).

HttpTransport, credential resolution (keyring or <PROVIDER>_API_KEY).

Opt-in modules — use AiClientBuilder.production_ready() or wire ResilientConfig explicitly; not auto-enabled by AiClient.create().

ExtraEnables
vision / audioMultimodal helpers (HAS_VISION, HAS_AUDIO)
embeddingsEmbeddingClient
stt / tts / rerankingStandalone service clients
batchBatch collector / executor
telemetryOpenTelemetry integration
tokenizertiktoken-based counting
fullAll optional capabilities + watchdog, keyring
Terminal window
pip install ai-lib-python[full]