kalibr 0.1.28__tar.gz → 1.1.2a0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. kalibr-1.1.2a0/LICENSE +21 -0
  2. kalibr-1.1.2a0/PKG-INFO +236 -0
  3. kalibr-1.1.2a0/README.md +168 -0
  4. kalibr-1.1.2a0/kalibr/__init__.py +172 -0
  5. kalibr-1.1.2a0/kalibr/__main__.py +6 -0
  6. kalibr-1.1.2a0/kalibr/capsule_middleware.py +108 -0
  7. kalibr-1.1.2a0/kalibr/cli/__init__.py +5 -0
  8. kalibr-1.1.2a0/kalibr/cli/capsule_cmd.py +174 -0
  9. kalibr-1.1.2a0/kalibr/cli/deploy_cmd.py +114 -0
  10. kalibr-1.1.2a0/kalibr/cli/main.py +67 -0
  11. kalibr-1.1.2a0/kalibr/cli/run.py +203 -0
  12. kalibr-1.1.2a0/kalibr/cli/serve.py +59 -0
  13. kalibr-1.1.2a0/kalibr/client.py +293 -0
  14. kalibr-1.1.2a0/kalibr/collector.py +173 -0
  15. kalibr-1.1.2a0/kalibr/context.py +132 -0
  16. kalibr-1.1.2a0/kalibr/cost_adapter.py +222 -0
  17. kalibr-1.1.2a0/kalibr/decorators.py +140 -0
  18. kalibr-1.1.2a0/kalibr/instrumentation/__init__.py +13 -0
  19. kalibr-1.1.2a0/kalibr/instrumentation/anthropic_instr.py +282 -0
  20. kalibr-1.1.2a0/kalibr/instrumentation/base.py +108 -0
  21. kalibr-1.1.2a0/kalibr/instrumentation/google_instr.py +281 -0
  22. kalibr-1.1.2a0/kalibr/instrumentation/openai_instr.py +265 -0
  23. kalibr-1.1.2a0/kalibr/instrumentation/registry.py +153 -0
  24. kalibr-1.1.2a0/kalibr/kalibr.py +173 -0
  25. kalibr-1.1.2a0/kalibr/kalibr_app.py +82 -0
  26. kalibr-1.1.2a0/kalibr/middleware/__init__.py +5 -0
  27. kalibr-1.1.2a0/kalibr/middleware/auto_tracer.py +356 -0
  28. kalibr-1.1.2a0/kalibr/models.py +41 -0
  29. kalibr-1.1.2a0/kalibr/redaction.py +44 -0
  30. kalibr-1.1.2a0/kalibr/schemas.py +116 -0
  31. kalibr-1.1.2a0/kalibr/simple_tracer.py +258 -0
  32. kalibr-1.1.2a0/kalibr/tokens.py +52 -0
  33. kalibr-1.1.2a0/kalibr/trace_capsule.py +296 -0
  34. kalibr-1.1.2a0/kalibr/trace_models.py +201 -0
  35. kalibr-1.1.2a0/kalibr/tracer.py +354 -0
  36. kalibr-1.1.2a0/kalibr/types.py +38 -0
  37. kalibr-1.1.2a0/kalibr/utils.py +198 -0
  38. kalibr-1.1.2a0/kalibr.egg-info/PKG-INFO +236 -0
  39. kalibr-1.1.2a0/kalibr.egg-info/SOURCES.txt +53 -0
  40. kalibr-1.1.2a0/kalibr.egg-info/entry_points.txt +2 -0
  41. kalibr-1.1.2a0/kalibr.egg-info/requires.txt +50 -0
  42. kalibr-1.1.2a0/kalibr.egg-info/top_level.txt +4 -0
  43. kalibr-1.1.2a0/kalibr_crewai/__init__.py +65 -0
  44. kalibr-1.1.2a0/kalibr_crewai/callbacks.py +539 -0
  45. kalibr-1.1.2a0/kalibr_crewai/instrumentor.py +513 -0
  46. kalibr-1.1.2a0/kalibr_langchain/__init__.py +47 -0
  47. kalibr-1.1.2a0/kalibr_langchain/async_callback.py +850 -0
  48. kalibr-1.1.2a0/kalibr_langchain/callback.py +1064 -0
  49. kalibr-1.1.2a0/kalibr_openai_agents/__init__.py +43 -0
  50. kalibr-1.1.2a0/kalibr_openai_agents/processor.py +554 -0
  51. kalibr-1.1.2a0/pyproject.toml +113 -0
  52. kalibr-1.1.2a0/tests/test_capsule_builder.py +326 -0
  53. kalibr-1.1.2a0/tests/test_instrumentation.py +235 -0
  54. kalibr-0.1.28/PKG-INFO +0 -53
  55. kalibr-0.1.28/README.md +0 -27
  56. kalibr-0.1.28/kalibr/__init__.py +0 -6
  57. kalibr-0.1.28/kalibr/__main__.py +0 -88
  58. kalibr-0.1.28/kalibr/kalibr.py +0 -111
  59. kalibr-0.1.28/kalibr/kalibr_sdk.py +0 -20
  60. kalibr-0.1.28/kalibr.egg-info/PKG-INFO +0 -53
  61. kalibr-0.1.28/kalibr.egg-info/SOURCES.txt +0 -13
  62. kalibr-0.1.28/kalibr.egg-info/entry_points.txt +0 -2
  63. kalibr-0.1.28/kalibr.egg-info/requires.txt +0 -4
  64. kalibr-0.1.28/kalibr.egg-info/top_level.txt +0 -1
  65. kalibr-0.1.28/pyproject.toml +0 -3
  66. kalibr-0.1.28/setup.py +0 -38
  67. {kalibr-0.1.28 → kalibr-1.1.2a0}/kalibr.egg-info/dependency_links.txt +0 -0
  68. {kalibr-0.1.28 → kalibr-1.1.2a0}/setup.cfg +0 -0
kalibr-1.1.2a0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kalibr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,236 @@
1
+ Metadata-Version: 2.4
2
+ Name: kalibr
3
+ Version: 1.1.2a0
4
+ Summary: Unified LLM Observability & Multi-Model AI Integration Framework - Deploy to GPT, Claude, Gemini, Copilot with full telemetry
5
+ Author-email: Kalibr Team <team@kalibr.dev>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/kalibr-systems/kalibr-sdk-python
8
+ Project-URL: Documentation, https://docs.kalibr.systems
9
+ Project-URL: Repository, https://github.com/kalibr-systems/kalibr-sdk-python
10
+ Project-URL: Issues, https://github.com/kalibr-systems/kalibr-sdk-python/issues
11
+ Keywords: ai,mcp,gpt,claude,gemini,copilot,openai,anthropic,google,microsoft,observability,telemetry,tracing,llm,schema-generation,api,multi-model,langchain,crewai
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: httpx>=0.27.0
27
+ Requires-Dist: tiktoken>=0.8.0
28
+ Requires-Dist: fastapi>=0.110.1
29
+ Requires-Dist: uvicorn>=0.25.0
30
+ Requires-Dist: pydantic>=2.6.4
31
+ Requires-Dist: typer>=0.9.0
32
+ Requires-Dist: python-multipart>=0.0.9
33
+ Requires-Dist: rich>=10.0.0
34
+ Requires-Dist: requests>=2.31.0
35
+ Requires-Dist: opentelemetry-api>=1.20.0
36
+ Requires-Dist: opentelemetry-sdk>=1.20.0
37
+ Requires-Dist: opentelemetry-exporter-otlp>=1.20.0
38
+ Provides-Extra: langchain
39
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain"
40
+ Provides-Extra: langchain-openai
41
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain-openai"
42
+ Requires-Dist: langchain-openai>=0.1.0; extra == "langchain-openai"
43
+ Provides-Extra: langchain-anthropic
44
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain-anthropic"
45
+ Requires-Dist: langchain-anthropic>=0.1.0; extra == "langchain-anthropic"
46
+ Provides-Extra: langchain-google
47
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain-google"
48
+ Requires-Dist: langchain-google-genai>=0.0.10; extra == "langchain-google"
49
+ Provides-Extra: langchain-all
50
+ Requires-Dist: langchain-core>=0.1.0; extra == "langchain-all"
51
+ Requires-Dist: langchain-openai>=0.1.0; extra == "langchain-all"
52
+ Requires-Dist: langchain-anthropic>=0.1.0; extra == "langchain-all"
53
+ Requires-Dist: langchain-google-genai>=0.0.10; extra == "langchain-all"
54
+ Provides-Extra: crewai
55
+ Requires-Dist: crewai>=0.28.0; extra == "crewai"
56
+ Provides-Extra: openai-agents
57
+ Requires-Dist: openai-agents>=0.0.3; extra == "openai-agents"
58
+ Provides-Extra: integrations
59
+ Requires-Dist: langchain-core>=0.1.0; extra == "integrations"
60
+ Requires-Dist: crewai>=0.28.0; extra == "integrations"
61
+ Requires-Dist: openai-agents>=0.0.3; extra == "integrations"
62
+ Provides-Extra: dev
63
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
64
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
65
+ Requires-Dist: black>=23.0.0; extra == "dev"
66
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
67
+ Dynamic: license-file
68
+
69
+ # Kalibr Python SDK
70
+
71
+ Production-grade observability for LLM applications. Automatically instrument OpenAI, Anthropic, and Google AI SDKs with zero code changes.
72
+
73
+ ## Features
74
+
75
+ - **Zero-code instrumentation** - Automatic tracing for OpenAI, Anthropic, and Google AI
76
+ - **Cost tracking** - Real-time cost calculation for all LLM calls
77
+ - **Token monitoring** - Track input/output tokens across providers
78
+ - **Parent-child traces** - Automatic trace relationship management
79
+ - **Multi-provider support** - Works with GPT-4, Claude, Gemini, and more
80
+
81
+ ## Installation
82
+
83
+ ```bash
84
+ pip install kalibr
85
+ ```
86
+
87
+ ## Quick Start
88
+
89
+ ### Auto-instrumentation (Recommended)
90
+
91
+ Simply import `kalibr` at the start of your application - all LLM calls are automatically traced:
92
+
93
+ ```python
94
+ import kalibr # Enable auto-instrumentation
95
+ import openai
96
+
97
+ # Set your Kalibr API key
98
+ import os
99
+ os.environ["KALIBR_API_KEY"] = "your-kalibr-api-key"
100
+
101
+ # All OpenAI calls are now automatically traced
102
+ client = openai.OpenAI()
103
+ response = client.chat.completions.create(
104
+ model="gpt-4o",
105
+ messages=[{"role": "user", "content": "Hello!"}]
106
+ )
107
+ ```
108
+
109
+ ### Manual Tracing with Decorator
110
+
111
+ For more control, use the `@trace` decorator:
112
+
113
+ ```python
114
+ from kalibr import trace
115
+ import openai
116
+
117
+ @trace(operation="summarize", provider="openai", model="gpt-4o")
118
+ def summarize_text(text: str) -> str:
119
+ client = openai.OpenAI()
120
+ response = client.chat.completions.create(
121
+ model="gpt-4o",
122
+ messages=[
123
+ {"role": "system", "content": "Summarize the following text."},
124
+ {"role": "user", "content": text}
125
+ ]
126
+ )
127
+ return response.choices[0].message.content
128
+
129
+ result = summarize_text("Your long text here...")
130
+ ```
131
+
132
+ ### Multi-Provider Example
133
+
134
+ ```python
135
+ import kalibr
136
+ import openai
137
+ import anthropic
138
+
139
+ # OpenAI call - automatically traced
140
+ openai_client = openai.OpenAI()
141
+ gpt_response = openai_client.chat.completions.create(
142
+ model="gpt-4o",
143
+ messages=[{"role": "user", "content": "Explain quantum computing"}]
144
+ )
145
+
146
+ # Anthropic call - automatically traced
147
+ anthropic_client = anthropic.Anthropic()
148
+ claude_response = anthropic_client.messages.create(
149
+ model="claude-sonnet-4-20250514",
150
+ max_tokens=1024,
151
+ messages=[{"role": "user", "content": "Explain machine learning"}]
152
+ )
153
+ ```
154
+
155
+ ## Configuration
156
+
157
+ Configure the SDK using environment variables:
158
+
159
+ | Variable | Description | Default |
160
+ |----------|-------------|---------|
161
+ | `KALIBR_API_KEY` | API key for authentication | *Required* |
162
+ | `KALIBR_COLLECTOR_URL` | Collector endpoint URL | `http://localhost:8001/api/ingest` |
163
+ | `KALIBR_TENANT_ID` | Tenant identifier for multi-tenant setups | `default` |
164
+ | `KALIBR_WORKFLOW_ID` | Workflow identifier for grouping traces | `default` |
165
+ | `KALIBR_SERVICE_NAME` | Service name for OpenTelemetry spans | `kalibr-app` |
166
+ | `KALIBR_ENVIRONMENT` | Environment (prod, staging, dev) | `prod` |
167
+ | `KALIBR_AUTO_INSTRUMENT` | Enable/disable auto-instrumentation | `true` |
168
+ | `KALIBR_CONSOLE_EXPORT` | Enable console span export for debugging | `false` |
169
+
170
+ ## CLI Tools
171
+
172
+ The SDK includes command-line tools for running and deploying applications:
173
+
174
+ ```bash
175
+ # Run your app locally with tracing
176
+ kalibr serve myapp.py
177
+
178
+ # Run with managed runtime lifecycle
179
+ kalibr run myapp.py --port 8000
180
+
181
+ # Deploy to cloud platforms
182
+ kalibr deploy myapp.py --runtime fly.io
183
+
184
+ # Fetch trace data by ID
185
+ kalibr capsule <trace-id>
186
+ ```
187
+
188
+ ## Supported Providers
189
+
190
+ | Provider | Models | Auto-Instrumentation |
191
+ |----------|--------|---------------------|
192
+ | OpenAI | GPT-4, GPT-4o, GPT-3.5 | Yes |
193
+ | Anthropic | Claude 3 Opus, Sonnet, Haiku | Yes |
194
+ | Google | Gemini Pro, Gemini Flash | Yes |
195
+
196
+ ## Examples
197
+
198
+ See the [`examples/`](./examples) directory for complete examples:
199
+
200
+ - `basic_example.py` - Simple tracing example
201
+ - `basic_agent.py` - Agent with auto-instrumentation
202
+ - `advanced_example.py` - Advanced tracing patterns
203
+ - `cross_vendor.py` - Multi-provider workflows
204
+ - `test_mas.py` - Multi-agent system demonstration
205
+
206
+ ## Development
207
+
208
+ ```bash
209
+ # Clone the repository
210
+ git clone https://github.com/kalibr-systems/kalibr-sdk-python.git
211
+ cd kalibr-sdk-python
212
+
213
+ # Install in development mode
214
+ pip install -e ".[dev]"
215
+
216
+ # Run tests
217
+ pytest
218
+
219
+ # Format code
220
+ black kalibr/
221
+ ruff check kalibr/
222
+ ```
223
+
224
+ ## Contributing
225
+
226
+ We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
227
+
228
+ ## License
229
+
230
+ MIT License - see [LICENSE](./LICENSE) for details.
231
+
232
+ ## Links
233
+
234
+ - [Documentation](https://docs.kalibr.systems)
235
+ - [GitHub Issues](https://github.com/kalibr-systems/kalibr-sdk-python/issues)
236
+ - [PyPI Package](https://pypi.org/project/kalibr/)
@@ -0,0 +1,168 @@
1
+ # Kalibr Python SDK
2
+
3
+ Production-grade observability for LLM applications. Automatically instrument OpenAI, Anthropic, and Google AI SDKs with zero code changes.
4
+
5
+ ## Features
6
+
7
+ - **Zero-code instrumentation** - Automatic tracing for OpenAI, Anthropic, and Google AI
8
+ - **Cost tracking** - Real-time cost calculation for all LLM calls
9
+ - **Token monitoring** - Track input/output tokens across providers
10
+ - **Parent-child traces** - Automatic trace relationship management
11
+ - **Multi-provider support** - Works with GPT-4, Claude, Gemini, and more
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install kalibr
17
+ ```
18
+
19
+ ## Quick Start
20
+
21
+ ### Auto-instrumentation (Recommended)
22
+
23
+ Simply import `kalibr` at the start of your application - all LLM calls are automatically traced:
24
+
25
+ ```python
26
+ import kalibr # Enable auto-instrumentation
27
+ import openai
28
+
29
+ # Set your Kalibr API key
30
+ import os
31
+ os.environ["KALIBR_API_KEY"] = "your-kalibr-api-key"
32
+
33
+ # All OpenAI calls are now automatically traced
34
+ client = openai.OpenAI()
35
+ response = client.chat.completions.create(
36
+ model="gpt-4o",
37
+ messages=[{"role": "user", "content": "Hello!"}]
38
+ )
39
+ ```
40
+
41
+ ### Manual Tracing with Decorator
42
+
43
+ For more control, use the `@trace` decorator:
44
+
45
+ ```python
46
+ from kalibr import trace
47
+ import openai
48
+
49
+ @trace(operation="summarize", provider="openai", model="gpt-4o")
50
+ def summarize_text(text: str) -> str:
51
+ client = openai.OpenAI()
52
+ response = client.chat.completions.create(
53
+ model="gpt-4o",
54
+ messages=[
55
+ {"role": "system", "content": "Summarize the following text."},
56
+ {"role": "user", "content": text}
57
+ ]
58
+ )
59
+ return response.choices[0].message.content
60
+
61
+ result = summarize_text("Your long text here...")
62
+ ```
63
+
64
+ ### Multi-Provider Example
65
+
66
+ ```python
67
+ import kalibr
68
+ import openai
69
+ import anthropic
70
+
71
+ # OpenAI call - automatically traced
72
+ openai_client = openai.OpenAI()
73
+ gpt_response = openai_client.chat.completions.create(
74
+ model="gpt-4o",
75
+ messages=[{"role": "user", "content": "Explain quantum computing"}]
76
+ )
77
+
78
+ # Anthropic call - automatically traced
79
+ anthropic_client = anthropic.Anthropic()
80
+ claude_response = anthropic_client.messages.create(
81
+ model="claude-sonnet-4-20250514",
82
+ max_tokens=1024,
83
+ messages=[{"role": "user", "content": "Explain machine learning"}]
84
+ )
85
+ ```
86
+
87
+ ## Configuration
88
+
89
+ Configure the SDK using environment variables:
90
+
91
+ | Variable | Description | Default |
92
+ |----------|-------------|---------|
93
+ | `KALIBR_API_KEY` | API key for authentication | *Required* |
94
+ | `KALIBR_COLLECTOR_URL` | Collector endpoint URL | `http://localhost:8001/api/ingest` |
95
+ | `KALIBR_TENANT_ID` | Tenant identifier for multi-tenant setups | `default` |
96
+ | `KALIBR_WORKFLOW_ID` | Workflow identifier for grouping traces | `default` |
97
+ | `KALIBR_SERVICE_NAME` | Service name for OpenTelemetry spans | `kalibr-app` |
98
+ | `KALIBR_ENVIRONMENT` | Environment (prod, staging, dev) | `prod` |
99
+ | `KALIBR_AUTO_INSTRUMENT` | Enable/disable auto-instrumentation | `true` |
100
+ | `KALIBR_CONSOLE_EXPORT` | Enable console span export for debugging | `false` |
101
+
102
+ ## CLI Tools
103
+
104
+ The SDK includes command-line tools for running and deploying applications:
105
+
106
+ ```bash
107
+ # Run your app locally with tracing
108
+ kalibr serve myapp.py
109
+
110
+ # Run with managed runtime lifecycle
111
+ kalibr run myapp.py --port 8000
112
+
113
+ # Deploy to cloud platforms
114
+ kalibr deploy myapp.py --runtime fly.io
115
+
116
+ # Fetch trace data by ID
117
+ kalibr capsule <trace-id>
118
+ ```
119
+
120
+ ## Supported Providers
121
+
122
+ | Provider | Models | Auto-Instrumentation |
123
+ |----------|--------|---------------------|
124
+ | OpenAI | GPT-4, GPT-4o, GPT-3.5 | Yes |
125
+ | Anthropic | Claude 3 Opus, Sonnet, Haiku | Yes |
126
+ | Google | Gemini Pro, Gemini Flash | Yes |
127
+
128
+ ## Examples
129
+
130
+ See the [`examples/`](./examples) directory for complete examples:
131
+
132
+ - `basic_example.py` - Simple tracing example
133
+ - `basic_agent.py` - Agent with auto-instrumentation
134
+ - `advanced_example.py` - Advanced tracing patterns
135
+ - `cross_vendor.py` - Multi-provider workflows
136
+ - `test_mas.py` - Multi-agent system demonstration
137
+
138
+ ## Development
139
+
140
+ ```bash
141
+ # Clone the repository
142
+ git clone https://github.com/kalibr-systems/kalibr-sdk-python.git
143
+ cd kalibr-sdk-python
144
+
145
+ # Install in development mode
146
+ pip install -e ".[dev]"
147
+
148
+ # Run tests
149
+ pytest
150
+
151
+ # Format code
152
+ black kalibr/
153
+ ruff check kalibr/
154
+ ```
155
+
156
+ ## Contributing
157
+
158
+ We welcome contributions! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.
159
+
160
+ ## License
161
+
162
+ MIT License - see [LICENSE](./LICENSE) for details.
163
+
164
+ ## Links
165
+
166
+ - [Documentation](https://docs.kalibr.systems)
167
+ - [GitHub Issues](https://github.com/kalibr-systems/kalibr-sdk-python/issues)
168
+ - [PyPI Package](https://pypi.org/project/kalibr/)
@@ -0,0 +1,172 @@
1
+ """Kalibr SDK v1.1.0 - Unified LLM Observability & Multi-Model AI Integration Framework
2
+
3
+ This SDK combines:
4
+ 1. Full LLM Observability with tracing, cost tracking, and analytics
5
+ 2. Multi-Model AI Integration (GPT, Claude, Gemini, Copilot)
6
+ 3. One-line deployment with Docker and runtime router
7
+ 4. Schema generation for all major AI platforms
8
+ 5. **NEW in 1.1.0**: Auto-instrumentation of LLM SDKs (OpenAI, Anthropic, Google)
9
+
10
+ Features:
11
+ - **Auto-Instrumentation**: Zero-config tracing of OpenAI, Anthropic, Google SDK calls
12
+ - **OpenTelemetry**: OTel-compatible spans with OTLP export
13
+ - **Tracing**: Complete telemetry with @trace decorator
14
+ - **Cost Tracking**: Multi-vendor cost calculation (OpenAI, Anthropic, etc.)
15
+ - **Deployment**: One-command deployment to Fly.io, Render, or local
16
+ - **Schema Generation**: Auto-generate schemas for GPT Actions, Claude MCP, Gemini, Copilot
17
+ - **Error Handling**: Automatic error capture with stack traces
18
+ - **Analytics**: ClickHouse-backed analytics and alerting
19
+
20
+ Usage - Auto-Instrumentation (NEW):
21
+ from kalibr import Kalibr
22
+ import openai # Automatically instrumented!
23
+
24
+ app = Kalibr(title="My API")
25
+
26
+ @app.action("chat", "Chat with GPT")
27
+ def chat(message: str):
28
+ # This OpenAI call is automatically traced!
29
+ response = openai.chat.completions.create(
30
+ model="gpt-4",
31
+ messages=[{"role": "user", "content": message}]
32
+ )
33
+ return response.choices[0].message.content
34
+
35
+ Usage - Manual Tracing:
36
+ from kalibr import trace
37
+
38
+ @trace(operation="chat_completion", vendor="openai", model="gpt-4")
39
+ def call_openai(prompt):
40
+ response = openai.chat.completions.create(
41
+ model="gpt-4",
42
+ messages=[{"role": "user", "content": prompt}]
43
+ )
44
+ return response
45
+
46
+ CLI Usage:
47
+ kalibr serve my_app.py # Run locally
48
+ kalibr deploy my_app.py --runtime fly # Deploy to Fly.io
49
+ kalibr run my_app.py # Run with auto-tracing
50
+ kalibr version # Show version
51
+ """
52
+
53
+ __version__ = "1.1.0-alpha"
54
+
55
+ # Auto-instrument LLM SDKs on import (can be disabled via env var)
56
+ import os
57
+
58
+ # ============================================================================
59
+ # OBSERVABILITY & TRACING (from 1023)
60
+ # ============================================================================
61
+ from .client import KalibrClient
62
+
63
+ # ============================================================================
64
+ # PHASE 1: SDK INSTRUMENTATION & OPENTELEMETRY (v1.1.0)
65
+ # ============================================================================
66
+ from .collector import (
67
+ get_tracer_provider,
68
+ )
69
+ from .collector import is_configured as is_collector_configured
70
+ from .collector import (
71
+ setup_collector,
72
+ )
73
+ from .context import get_parent_span_id, get_trace_id, new_trace_id, trace_context
74
+ from .cost_adapter import (
75
+ AnthropicCostAdapter,
76
+ BaseCostAdapter,
77
+ CostAdapterFactory,
78
+ OpenAICostAdapter,
79
+ )
80
+ from .instrumentation import auto_instrument, get_instrumented_providers
81
+
82
+ # ============================================================================
83
+ # SDK & DEPLOYMENT (from 1.0.30)
84
+ # ============================================================================
85
+ from .kalibr import Kalibr
86
+ from .kalibr_app import KalibrApp
87
+ from .models import EventData, TraceConfig
88
+ from .schemas import (
89
+ generate_copilot_schema,
90
+ generate_gemini_schema,
91
+ generate_mcp_schema,
92
+ get_base_url,
93
+ get_supported_models,
94
+ )
95
+ from .simple_tracer import trace
96
+ from .trace_capsule import TraceCapsule, get_or_create_capsule
97
+ from .tracer import SpanContext, Tracer
98
+ from .types import FileUpload, Session
99
+ from .utils import load_config_from_env
100
+
101
+ if os.getenv("KALIBR_AUTO_INSTRUMENT", "true").lower() == "true":
102
+ # Setup OpenTelemetry collector
103
+ try:
104
+ setup_collector(
105
+ service_name=os.getenv("KALIBR_SERVICE_NAME", "kalibr"),
106
+ file_export=True,
107
+ console_export=os.getenv("KALIBR_CONSOLE_EXPORT", "false").lower() == "true",
108
+ )
109
+ except Exception as e:
110
+ print(f"⚠️ Failed to setup OpenTelemetry collector: {e}")
111
+
112
+ # Auto-instrument available SDKs
113
+ try:
114
+ auto_instrument(["openai", "anthropic", "google"])
115
+ except Exception as e:
116
+ print(f"⚠️ Failed to auto-instrument SDKs: {e}")
117
+
118
+ __all__ = [
119
+ # ========================================================================
120
+ # OBSERVABILITY & TRACING
121
+ # ========================================================================
122
+ # Simple tracing API (recommended)
123
+ "trace",
124
+ # Capsule propagation (Phase 6)
125
+ "TraceCapsule",
126
+ "get_or_create_capsule",
127
+ # Client
128
+ "KalibrClient",
129
+ # Context
130
+ "trace_context",
131
+ "get_trace_id",
132
+ "get_parent_span_id",
133
+ "new_trace_id",
134
+ # Tracer
135
+ "Tracer",
136
+ "SpanContext",
137
+ # Cost Adapters
138
+ "BaseCostAdapter",
139
+ "OpenAICostAdapter",
140
+ "AnthropicCostAdapter",
141
+ "CostAdapterFactory",
142
+ # Models
143
+ "TraceConfig",
144
+ "EventData",
145
+ # Utils
146
+ "load_config_from_env",
147
+ # ========================================================================
148
+ # SDK & DEPLOYMENT
149
+ # ========================================================================
150
+ # SDK Classes
151
+ "Kalibr",
152
+ "KalibrApp",
153
+ # Types
154
+ "FileUpload",
155
+ "Session",
156
+ # Schema Generation
157
+ "get_base_url",
158
+ "generate_mcp_schema",
159
+ "generate_gemini_schema",
160
+ "generate_copilot_schema",
161
+ "get_supported_models",
162
+ # ========================================================================
163
+ # PHASE 1: SDK INSTRUMENTATION & OPENTELEMETRY (v1.1.0)
164
+ # ========================================================================
165
+ # Auto-instrumentation
166
+ "auto_instrument",
167
+ "get_instrumented_providers",
168
+ # OpenTelemetry collector
169
+ "setup_collector",
170
+ "get_tracer_provider",
171
+ "is_collector_configured",
172
+ ]
@@ -0,0 +1,6 @@
1
+ """Entry point for python -m kalibr"""
2
+
3
+ from kalibr.cli.main import app
4
+
5
+ if __name__ == "__main__":
6
+ app()