kalmia 0.2.0__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.
kalmia-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kalmia
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.
kalmia-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: kalmia
3
+ Version: 0.2.0
4
+ Summary: Kalmia Tracing SDK — automatic LLM call tracing for OpenAI and Anthropic
5
+ Author: Kalmia
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/xuandy05/trace-analyzer/tree/main/sdk/python#readme
8
+ Project-URL: Repository, https://github.com/xuandy05/trace-analyzer
9
+ Project-URL: Issues, https://github.com/xuandy05/trace-analyzer/issues
10
+ Keywords: llm,tracing,observability,openai,anthropic,claude,agents
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Requires-Python: >=3.7
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Provides-Extra: openai
20
+ Requires-Dist: openai>=1.0.0; extra == "openai"
21
+ Provides-Extra: anthropic
22
+ Requires-Dist: anthropic>=0.10.0; extra == "anthropic"
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # Kalmia SDK (Python)
29
+
30
+ Automatic LLM call tracing for OpenAI and Anthropic. Wrap your client once and
31
+ every call — prompts, responses, tool calls, errors — is captured and sent to
32
+ your Kalmia dashboard. Zero external dependencies.
33
+
34
+ ## Installation
35
+
36
+ ```sh
37
+ pip install kalmia
38
+ ```
39
+
40
+ ## Usage
41
+
42
+ Get your API key from the Kalmia dashboard, then initialize the logger once at
43
+ startup and wrap your LLM client:
44
+
45
+ ```python
46
+ from kalmia import init_logger, wrap_anthropic
47
+ import anthropic
48
+
49
+ init_logger(
50
+ project_name="my-agent",
51
+ api_key="kal_live_your_api_key", # required — or set KALMIA_API_KEY
52
+ )
53
+
54
+ client = wrap_anthropic(anthropic.Anthropic())
55
+ # use `client` exactly like the Anthropic SDK — traces are captured automatically
56
+ ```
57
+
58
+ OpenAI works the same way:
59
+
60
+ ```python
61
+ from kalmia import init_logger, wrap_openai
62
+ import openai
63
+
64
+ init_logger(project_name="my-agent", api_key="kal_live_your_api_key")
65
+ client = wrap_openai(openai.OpenAI())
66
+ ```
67
+
68
+ ## Configuration
69
+
70
+ | Argument / env var | Purpose |
71
+ | --- | --- |
72
+ | `project_name` (required) | Groups traces under a project. |
73
+ | `api_key` / `KALMIA_API_KEY` | Workspace API key. Without it, traces are rejected and dropped. |
74
+ | `base_url` / `KALMIA_BASE_URL` | Where traces are sent. Defaults to the hosted Kalmia backend (`https://www.kalmia.dev`). Set this for local development or self-hosting. |
75
+
76
+ ## Decorators and spans
77
+
78
+ Use `@traced` to capture custom steps, and `current_span()` to log inside them:
79
+
80
+ ```python
81
+ from kalmia import traced, current_span
82
+
83
+ @traced(name="run")
84
+ def run(message):
85
+ current_span().log(input={"message": message})
86
+ ...
87
+ ```
88
+
89
+ ## Delivery reliability
90
+
91
+ Trace delivery is **at-least-once with no silent loss**:
92
+
93
+ - **Retry with backoff.** Transient failures (transport errors, timeouts, `429`,
94
+ `5xx`) are retried with bounded backoff. Permanent `4xx` responses (`400`,
95
+ `401`, `413`) are not retried.
96
+ - **Buffering.** A trace that still fails after its retries is held in a bounded
97
+ in-memory buffer and re-attempted on the next send, then once more at
98
+ interpreter exit (`atexit`).
99
+ - **No silent loss.** Every drop path — a non-retryable response, a full buffer
100
+ evicting its oldest entry, a server-side rejection, or a trace still
101
+ undelivered at exit — emits a warning naming the trace `id`, so a lost run is
102
+ always visible in your logs.
103
+ - **Safe retries.** The backend de-duplicates by trace `id`, so a retried
104
+ delivery never creates a duplicate.
105
+
106
+ The buffer lives in memory, so a hard kill (`SIGKILL`, OOM) can still lose
107
+ buffered traces — those are warned when the trace is first buffered. Durable
108
+ on-disk buffering is planned. Delivery never raises into your application.
kalmia-0.2.0/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # Kalmia SDK (Python)
2
+
3
+ Automatic LLM call tracing for OpenAI and Anthropic. Wrap your client once and
4
+ every call — prompts, responses, tool calls, errors — is captured and sent to
5
+ your Kalmia dashboard. Zero external dependencies.
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pip install kalmia
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Get your API key from the Kalmia dashboard, then initialize the logger once at
16
+ startup and wrap your LLM client:
17
+
18
+ ```python
19
+ from kalmia import init_logger, wrap_anthropic
20
+ import anthropic
21
+
22
+ init_logger(
23
+ project_name="my-agent",
24
+ api_key="kal_live_your_api_key", # required — or set KALMIA_API_KEY
25
+ )
26
+
27
+ client = wrap_anthropic(anthropic.Anthropic())
28
+ # use `client` exactly like the Anthropic SDK — traces are captured automatically
29
+ ```
30
+
31
+ OpenAI works the same way:
32
+
33
+ ```python
34
+ from kalmia import init_logger, wrap_openai
35
+ import openai
36
+
37
+ init_logger(project_name="my-agent", api_key="kal_live_your_api_key")
38
+ client = wrap_openai(openai.OpenAI())
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ | Argument / env var | Purpose |
44
+ | --- | --- |
45
+ | `project_name` (required) | Groups traces under a project. |
46
+ | `api_key` / `KALMIA_API_KEY` | Workspace API key. Without it, traces are rejected and dropped. |
47
+ | `base_url` / `KALMIA_BASE_URL` | Where traces are sent. Defaults to the hosted Kalmia backend (`https://www.kalmia.dev`). Set this for local development or self-hosting. |
48
+
49
+ ## Decorators and spans
50
+
51
+ Use `@traced` to capture custom steps, and `current_span()` to log inside them:
52
+
53
+ ```python
54
+ from kalmia import traced, current_span
55
+
56
+ @traced(name="run")
57
+ def run(message):
58
+ current_span().log(input={"message": message})
59
+ ...
60
+ ```
61
+
62
+ ## Delivery reliability
63
+
64
+ Trace delivery is **at-least-once with no silent loss**:
65
+
66
+ - **Retry with backoff.** Transient failures (transport errors, timeouts, `429`,
67
+ `5xx`) are retried with bounded backoff. Permanent `4xx` responses (`400`,
68
+ `401`, `413`) are not retried.
69
+ - **Buffering.** A trace that still fails after its retries is held in a bounded
70
+ in-memory buffer and re-attempted on the next send, then once more at
71
+ interpreter exit (`atexit`).
72
+ - **No silent loss.** Every drop path — a non-retryable response, a full buffer
73
+ evicting its oldest entry, a server-side rejection, or a trace still
74
+ undelivered at exit — emits a warning naming the trace `id`, so a lost run is
75
+ always visible in your logs.
76
+ - **Safe retries.** The backend de-duplicates by trace `id`, so a retried
77
+ delivery never creates a duplicate.
78
+
79
+ The buffer lives in memory, so a hard kill (`SIGKILL`, OOM) can still lose
80
+ buffered traces — those are warned when the trace is first buffered. Durable
81
+ on-disk buffering is planned. Delivery never raises into your application.
@@ -0,0 +1,21 @@
1
+ """Kalmia Tracing SDK — automatic LLM call tracing for OpenAI and Anthropic."""
2
+
3
+ from .tracer import (
4
+ init_logger,
5
+ traced,
6
+ current_span,
7
+ wrap_openai,
8
+ wrap_anthropic,
9
+ Span,
10
+ )
11
+
12
+ __all__ = [
13
+ "init_logger",
14
+ "traced",
15
+ "current_span",
16
+ "wrap_openai",
17
+ "wrap_anthropic",
18
+ "Span",
19
+ ]
20
+
21
+ __version__ = "0.2.0"