コンテンツにスキップ

Python SDK 概要

ai-lib-python(v0.6.0)は、AI-Protocol の公式 Python ランタイムです。Pydantic v2 による型安全性と本番グレードのテレメトリを持つ、開発者フレンドリーな完全 async インターフェースを提供します。

Python SDK は Rust ランタイムのレイヤーアーキテクチャを反映しています:

クライアントレイヤー(client/

Section titled “クライアントレイヤー(client/)”
  • AiClient — ファクトリメソッド付きのメインエントリポイント
  • AiClientBuilder — fluent 設定ビルダー
  • ChatRequestBuilder — リクエスト構築
  • ChatResponse / CallStats — レスポンス型
  • CancelToken / CancellableStream — ストリームキャンセル

プロトコルレイヤー(protocol/

Section titled “プロトコルレイヤー(protocol/)”
  • ProtocolLoader — キャッシュ付きでローカル/環境変数/GitHub からマニフェストを読み込み
  • ProtocolManifest — プロバイダー設定用の Pydantic モデル
  • Validator — JSON Schema 検証(fastjsonschema)

パイプラインレイヤー(pipeline/

Section titled “パイプラインレイヤー(pipeline/)”
  • Decoder — SSE、JSON Lines、Anthropic SSE デコーダー
  • Selector — JSONPath ベースのフレーム選択(jsonpath-ng)
  • Accumulator — ツール呼び出しの組み立て
  • FanOut — マルチ候補展開
  • EventMapper — プロトコル駆動、Default、Anthropic マッパー

トランスポートレイヤー(transport/

Section titled “トランスポートレイヤー(transport/)”
  • HttpTransport — ストリーミング対応 httpx ベースの非同期 HTTP
  • Auth — 環境変数と keyring からの API キー解決
  • ConnectionPool — パフォーマンスのためのコネクションプール
  • ResilientExecutor — すべてのパターンを統合
  • RetryPolicy — 指数バックオフ
  • RateLimiter — トークンバケット
  • CircuitBreaker — 障害分離
  • Backpressure — 同時実行制限
  • FallbackChain — マルチターゲットフェイルオーバー
  • PreflightChecker — 統合リクエストゲート

ルーティングレイヤー(routing/

Section titled “ルーティングレイヤー(routing/)”
  • ModelManager — モデル登録と選択
  • ModelArray — エンドポイント間のロードバランシング
  • 選択戦略 — ラウンドロビン、重み付き、コストベース、品質ベース

テレメトリレイヤー(telemetry/

Section titled “テレメトリレイヤー(telemetry/)”
  • MetricsCollector — Prometheus メトリクスエクスポート
  • Tracer — OpenTelemetry 分散トレーシング
  • Logger — 構造化ログ
  • HealthChecker — サービスヘルス監視
  • FeedbackCollector — ユーザーフィードバック
  • embeddings/ — ベクトル操作付き EmbeddingClient
  • cache/ — マルチバックエンドキャッシュ(メモリ、ディスク)
  • tokens/ — TokenCounter(tiktoken)とコスト見積もり
  • batch/ — 同時実行制御付き BatchCollector/Executor
  • plugins/ — プラグインベース、レジストリ、フック、ミドルウェア
  • structured/ — JSON モード、スキーマ生成、出力検証
  • guardrails/ — コンテンツフィルタリング、バリデーター
パッケージ目的
httpx非同期 HTTP クライアント
pydanticデータ検証と型
pydantic-settings設定管理
fastjsonschemaマニフェスト検証
jsonpath-ngJSONPath 式
pyyamlYAML パース
Extraパッケージ
[telemetry]OpenTelemetry、Prometheus
[tokenizer]tiktoken
[full]上記すべて + watchdog、keyring

v0.6.0 は AI-Protocol V2 仕様に対応しています:

  • 標準エラーコードerrors/standard_codes.py の 13 の frozen dataclass コード(E1001–E9999)
  • 機能 Extra — 8 つの pip extra(vision、audio、embeddings、structured、batch、agentic、telemetry、tokenizer)に加え「full」メタ extra
  • コンプライアンステスト — 20/20 のクロスランタイムテストケースが合格
  • プロトコルバージョンサポート — プロトコルバージョン 1.0、1.1、1.5、2.0 をサポート

Python 3.10+ が必要です。