eden-sdk 0.1.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.
Files changed (37) hide show
  1. eden_sdk-0.1.0/LICENSE +21 -0
  2. eden_sdk-0.1.0/PKG-INFO +394 -0
  3. eden_sdk-0.1.0/README.md +341 -0
  4. eden_sdk-0.1.0/eden/__init__.py +77 -0
  5. eden_sdk-0.1.0/eden/py.typed +0 -0
  6. eden_sdk-0.1.0/eden_sdk/__init__.py +144 -0
  7. eden_sdk-0.1.0/eden_sdk/client.py +478 -0
  8. eden_sdk-0.1.0/eden_sdk/config.py +316 -0
  9. eden_sdk-0.1.0/eden_sdk/filters.py +130 -0
  10. eden_sdk-0.1.0/eden_sdk/gateway_session.py +128 -0
  11. eden_sdk-0.1.0/eden_sdk/instrumentations/__init__.py +54 -0
  12. eden_sdk-0.1.0/eden_sdk/instrumentations/anthropic.py +436 -0
  13. eden_sdk-0.1.0/eden_sdk/instrumentations/autogen.py +95 -0
  14. eden_sdk-0.1.0/eden_sdk/instrumentations/crewai.py +159 -0
  15. eden_sdk-0.1.0/eden_sdk/instrumentations/langchain.py +360 -0
  16. eden_sdk-0.1.0/eden_sdk/instrumentations/llama_index.py +147 -0
  17. eden_sdk-0.1.0/eden_sdk/instrumentations/mastra.py +36 -0
  18. eden_sdk-0.1.0/eden_sdk/instrumentations/openai.py +484 -0
  19. eden_sdk-0.1.0/eden_sdk/model_advisor.py +455 -0
  20. eden_sdk-0.1.0/eden_sdk/py.typed +0 -0
  21. eden_sdk-0.1.0/eden_sdk/trace.py +254 -0
  22. eden_sdk-0.1.0/eden_sdk.egg-info/PKG-INFO +394 -0
  23. eden_sdk-0.1.0/eden_sdk.egg-info/SOURCES.txt +53 -0
  24. eden_sdk-0.1.0/eden_sdk.egg-info/dependency_links.txt +1 -0
  25. eden_sdk-0.1.0/eden_sdk.egg-info/requires.txt +38 -0
  26. eden_sdk-0.1.0/eden_sdk.egg-info/top_level.txt +2 -0
  27. eden_sdk-0.1.0/pyproject.toml +100 -0
  28. eden_sdk-0.1.0/setup.cfg +4 -0
  29. eden_sdk-0.1.0/tests/test_client.py +300 -0
  30. eden_sdk-0.1.0/tests/test_config.py +246 -0
  31. eden_sdk-0.1.0/tests/test_filters.py +163 -0
  32. eden_sdk-0.1.0/tests/test_gateway_session.py +164 -0
  33. eden_sdk-0.1.0/tests/test_init.py +261 -0
  34. eden_sdk-0.1.0/tests/test_instrumentations.py +492 -0
  35. eden_sdk-0.1.0/tests/test_model_advisor.py +317 -0
  36. eden_sdk-0.1.0/tests/test_perf.py +264 -0
  37. eden_sdk-0.1.0/tests/test_trace.py +59 -0
eden_sdk-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eden contributors
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,394 @@
1
+ Metadata-Version: 2.4
2
+ Name: eden-sdk
3
+ Version: 0.1.0
4
+ Summary: Eden runtime SDK — auto-instrumentation, tracing, and fire-and-forget telemetry for LLM applications.
5
+ Author-email: Eden <hello@eden.dev>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://eden.dev
8
+ Project-URL: Documentation, https://docs.eden.dev/sdk/python
9
+ Project-URL: Repository, https://github.com/eden-ai/eden
10
+ Project-URL: Issues, https://github.com/eden-ai/eden/issues
11
+ Keywords: llm,observability,tracing,openai,anthropic,langchain,agent,eden
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: httpx>=0.27
24
+ Provides-Extra: openai
25
+ Requires-Dist: openai>=1.30; extra == "openai"
26
+ Provides-Extra: anthropic
27
+ Requires-Dist: anthropic>=0.30; extra == "anthropic"
28
+ Provides-Extra: langchain
29
+ Requires-Dist: langchain-core>=0.2; extra == "langchain"
30
+ Provides-Extra: llama-index
31
+ Requires-Dist: llama-index-core>=0.10; extra == "llama-index"
32
+ Provides-Extra: crewai
33
+ Requires-Dist: crewai>=0.50; extra == "crewai"
34
+ Provides-Extra: autogen
35
+ Requires-Dist: pyautogen>=0.2; extra == "autogen"
36
+ Provides-Extra: mastra
37
+ Provides-Extra: all
38
+ Requires-Dist: openai>=1.30; extra == "all"
39
+ Requires-Dist: anthropic>=0.30; extra == "all"
40
+ Requires-Dist: langchain-core>=0.2; extra == "all"
41
+ Requires-Dist: llama-index-core>=0.10; extra == "all"
42
+ Requires-Dist: crewai>=0.50; extra == "all"
43
+ Requires-Dist: pyautogen>=0.2; extra == "all"
44
+ Provides-Extra: dev
45
+ Requires-Dist: pytest>=8.0; extra == "dev"
46
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
47
+ Requires-Dist: pytest-mock>=3.12; extra == "dev"
48
+ Requires-Dist: ruff>=0.4; extra == "dev"
49
+ Requires-Dist: mypy>=1.8; extra == "dev"
50
+ Requires-Dist: respx>=0.21; extra == "dev"
51
+ Requires-Dist: anyio>=4.0; extra == "dev"
52
+ Dynamic: license-file
53
+
54
+ # Eden Python SDK
55
+
56
+ Lightweight, fire-and-forget observability for LLM applications.
57
+
58
+ - `@trace_agent` decorator and `with eden.trace(...)` context manager
59
+ - One-call auto-instrumentation for **OpenAI, Anthropic, LangChain, LlamaIndex, CrewAI, AutoGen, Mastra** (no-op for TS-only frameworks)
60
+ - Async, batched HTTP sender with a **5 ms p99 overhead budget** on the producer hot path
61
+ - Zero required dependencies beyond `httpx` (zero required deps beyond)
62
+
63
+ ## Install
64
+
65
+ ```bash
66
+ cd sdk/python
67
+ pip install -e .[dev] # core + tests
68
+ pip install -e .[openai,anthropic,langchain] # add instrumentations
69
+ pip install -e .[all] # every supported framework
70
+ ```
71
+
72
+ ## Quick start
73
+
74
+ ```python
75
+ import eden
76
+
77
+ eden.configure(
78
+ org_id="org_123",
79
+ api_key="sk-eden-...",
80
+ base_url="https://api.eden.dev", # default: http://localhost:8000
81
+ )
82
+
83
+ eden.instrument() # patches every installed framework
84
+
85
+ @eden.trace_agent(name="my-agent", tags=["prod"])
86
+ async def answer(question: str) -> str:
87
+ from openai import AsyncOpenAI
88
+ client = AsyncOpenAI()
89
+ resp = await client.chat.completions.create(
90
+ model="gpt-4o-mini",
91
+ messages=[{"role": "user", "content": question}],
92
+ )
93
+ return resp.choices[0].message.content
94
+ ```
95
+
96
+ Events are batched in memory and posted to the Eden ingestion endpoint
97
+ (`/orgs/{org_id}/ingest/{format}`) on a background thread. The shape
98
+ matches what `src/eden/observability/ingestion/providers.py` already
99
+ decodes — the SDK does no extra normalization.
100
+
101
+ ## Configuration
102
+
103
+ All settings are read from environment variables first, then overridden
104
+ by `eden.configure(...)`:
105
+
106
+ | Env var | Default | Purpose |
107
+ |------------------------|---------------------------|------------------------------------------|
108
+ | `EDEN_ORG_ID` | (required) | Org the events are attributed to. `EDEN_DEFAULT_ORG` accepted as an alias for parity with the TypeScript SDK. |
109
+ | `EDEN_API_KEY` | (required) | Programmatic key (`X-Org-Api-Key`). `EDEN_ORG_API_KEY` accepted as an alias for parity with the TypeScript SDK. |
110
+ | `EDEN_BASE_URL` | `http://localhost:8000` | Gateway / ingestion base URL |
111
+ | `EDEN_PROJECT_ID` | `default` | Multi-tenant project label |
112
+ | `EDEN_BATCH_SIZE` | `32` | Max events per HTTP POST |
113
+ | `EDEN_FLUSH_INTERVAL_MS` | `250` | Max time to buffer a batch |
114
+ | `EDEN_MAX_QUEUE` | `4096` | Backpressure cap (oldest dropped first) |
115
+ | `EDEN_DISABLED` | `0` | Turn the SDK into a complete no-op |
116
+ | `EDEN_DEBUG` | `0` | Mirror events to stderr instead of POST |
117
+
118
+ ## Auto-instrumentation
119
+
120
+ ```python
121
+ eden.instrument() # everything installed
122
+ eden.instrument("openai", "langchain") # specific frameworks
123
+ eden.uninstrument("openai") # tear down a patch
124
+ ```
125
+
126
+ | Framework | Mechanism |
127
+ |---------------|---------------------------------------------|
128
+ | openai | Monkey-patch `chat.completions.create` |
129
+ | anthropic | Monkey-patch `messages.create` |
130
+ | langchain | `BaseCallbackHandler` registered globally |
131
+ | llama_index | `BaseSpanHandler` registered via `Settings.callback_manager` |
132
+ | crewai | Default `step_callback` + `task_callback` |
133
+ | autogen | Global `register_reply_hook` on `ConversableAgent` |
134
+ | mastra | No-op (use the TypeScript SDK) |
135
+
136
+ ## Examples
137
+
138
+ ```bash
139
+ export EDEN_ORG_ID=org_...
140
+ export EDEN_API_KEY=sk-...
141
+ export OPENAI_API_KEY=sk-...
142
+ python examples/01_basic_chat.py # OpenAI non-streaming
143
+ python examples/02_langchain.py # LangChain
144
+ python examples/03_anthropic.py # Anthropic
145
+ python examples/04_streaming.py # OpenAI streaming (TTFT/ITL/TPOT)
146
+ ```
147
+
148
+ Each example traces a real LLM call and prints the result. Verify that
149
+ a row lands in `telemetry_events` with `source_format` matching the
150
+ framework (`openai`, `anthropic`, or `framework` for chains).
151
+
152
+ ## Streaming
153
+
154
+ `eden.instrument("openai")` / `eden.instrument("anthropic")` transparently
155
+ wrap streaming responses too — no code changes are needed. For each
156
+ `stream=True` call the SDK emits:
157
+
158
+ - one `llm_completion_stream` event with `ttft_ms`, `itl_ms_avg`,
159
+ `tpot_ms`, `output_tokens`, `chunk_count`, `finish_reason`;
160
+ - one row per chunk to `/ingest/chunks` with the `delta_text` and the
161
+ per-chunk `ttft_ms` / `itl_ms` / `tpot_ms`.
162
+
163
+ ```python
164
+ import eden
165
+ from openai import OpenAI
166
+
167
+ eden.configure(org_id="...", api_key="...", base_url="...")
168
+ eden.instrument("openai")
169
+
170
+ client = OpenAI()
171
+ stream = client.chat.completions.create(
172
+ model="gpt-4o-mini",
173
+ messages=[{"role": "user", "content": "Stream a haiku."}],
174
+ stream=True,
175
+ )
176
+ for chunk in stream:
177
+ print(chunk.choices[0].delta.content or "", end="", flush=True)
178
+ print()
179
+
180
+ eden.get_default_client().flush()
181
+ # → /ingest/openai (one llm_completion_stream event)
182
+ # → /ingest/chunks (one row per chunk)
183
+ ```
184
+
185
+ The same applies to Anthropic — `eden.instrument("anthropic")` understands
186
+ `message_start`, `content_block_delta`, `message_delta`, and `message_stop`
187
+ events and emits matching metrics.
188
+
189
+ ## Testing
190
+
191
+ ```bash
192
+ cd sdk/python
193
+ pip install -e .[dev]
194
+ pytest -v # unit + integration
195
+ pytest -v -m perf # perf microbench (p99 < 5 ms)
196
+ ```
197
+
198
+ The perf test asserts that the SDK's enqueue + `@trace_agent` wrapper
199
+ adds no more than 5 ms p99 over an uninstrumented baseline.
200
+
201
+ ## Architecture
202
+
203
+ ```
204
+ +-------------------+ +------------------+ +------------------+
205
+ | User code | ---> | EdenClient | ---> | /ingest/{fmt} |
206
+ | (sync/async) | | (queue + flush) | | (FastAPI route) |
207
+ +-------------------+ +------------------+ +------------------+
208
+ ^ |
209
+ | v
210
+ eden.trace / src/eden/observability/
211
+ @trace_agent ingestion/providers.py
212
+ (existing decoders)
213
+ ```
214
+
215
+ - The `EdenClient` is a singleton: `get_default_client()`.
216
+ - Producer calls are non-blocking (`queue.put_nowait`).
217
+ - A single background thread runs the async httpx loop.
218
+ - The ingestion route's auth (`get_ingestion_auth`) accepts the
219
+ `X-Org-Id` + `X-Org-Api-Key` headers this SDK sends.
220
+
221
+ ## Eden AI gateway (OpenAI-compatible)
222
+
223
+ Eden ships an OpenAI-compatible proxy at `https://gateway.eden.ai/v1`
224
+ that exposes `/chat/completions`, `/completions`, `/embeddings`, and
225
+ `/models`. Point any OpenAI-compatible client at it and Eden applies
226
+ PII redaction, semantic caching, per-tenant budgets, circuit
227
+ breakers, and cost-aware routing in the path.
228
+
229
+ ```python
230
+ from openai import OpenAI
231
+
232
+ client = OpenAI(
233
+ base_url="https://gateway.eden.ai/v1",
234
+ api_key="<EDEN_API_KEY>", # your org's Eden API key
235
+ default_headers={
236
+ # Per-request upstream: route to your own OpenAI-compatible
237
+ # server (e.g. an internal vLLM proxy) instead of the
238
+ # Eden-default upstream. Both are optional; when omitted,
239
+ # Eden uses the server-configured OpenRouter / MiniMax.
240
+ "X-Upstream-Base-Url": "https://my-internal-llm.example.com/v1",
241
+ "X-Upstream-Api-Key": "<your-internal-key>",
242
+ # Optional: hint for telemetry labelling + provider-specific
243
+ # header defaults (anthropic-version, etc.).
244
+ "X-Upstream-Provider": "openai",
245
+ # OpenRouter attribution (optional).
246
+ "HTTP-Referer": "https://my-app.example.com",
247
+ "X-Title": "my-app",
248
+ },
249
+ )
250
+
251
+ resp = client.chat.completions.create(
252
+ model="gpt-4o-mini", # any model your upstream supports
253
+ messages=[{"role": "user", "content": "hello"}],
254
+ )
255
+ ```
256
+
257
+ The gateway strips `X-Upstream-Api-Key`, `X-Org-Api-Key`, and
258
+ `X-Org-Id` before forwarding to the upstream so Eden credentials
259
+ never leak to a third-party LLM provider. Other `X-*` headers
260
+ (OpenRouter `HTTP-Referer` / `X-Title`, Anthropic `anthropic-version`
261
+ / `anthropic-beta`, OpenRouter `X-OpenRouter-Beta`) flow through
262
+ unchanged.
263
+
264
+ ### PII redaction
265
+
266
+ Every gateway call passes through Eden's PII redactor before the
267
+ upstream sees it. By default, the redactor masks emails, phones,
268
+ SSNs, credit cards, JWTs, API keys, AWS secrets, private keys,
269
+ IBANs, passports, and IP addresses. Three knobs control the
270
+ behaviour — pick the one that matches your scenario:
271
+
272
+ **1. Per-tenant policy (recommended for org-wide defaults).** The
273
+ org's `org_pii_policies` row drives the active category set, the
274
+ masker mode, and the fail-closed behaviour. Admins set it via
275
+ `PUT /orgs/{org_id}/pii-policy` or the portal. Three modes:
276
+
277
+ - `off` — never mask. Use when the system is designed to use the
278
+ raw PII values (e.g. an internal credential-management flow
279
+ that needs the API key to authenticate downstream).
280
+ - `redact` (default) — mask per the active category set.
281
+ - `fail_closed` — mask + reject with 422 when a credential
282
+ category (JWT, API key, AWS secret, private key, etc.) is
283
+ detected. Use for tenants handling user-supplied prompts that
284
+ must never reach the upstream unmasked.
285
+
286
+ **2. Per-request opt-out (recommended for one-off calls).** Send
287
+ `X-PII-Bypass: true` on a specific request to skip redaction for
288
+ that call, regardless of the tenant policy:
289
+
290
+ ```python
291
+ headers = cfg.gateway_headers(
292
+ pii_bypass=True, # skip PII redaction for this request
293
+ )
294
+ ```
295
+
296
+ The same effect comes from a request-body field — useful for
297
+ OpenAI-compatible clients that can't easily add headers:
298
+
299
+ ```python
300
+ client.chat.completions.create(
301
+ model="gpt-4o-mini",
302
+ messages=[...],
303
+ extra_body={"pii_filter_enabled": False},
304
+ )
305
+ ```
306
+
307
+ **3. Disable a specific category.** Set
308
+ `disabled_categories=["api_key", "url_with_creds"]` in the policy
309
+ when your flow intentionally carries API keys (e.g. the auth
310
+ header of an outbound call the LLM has to make on the user's
311
+ behalf). The masker will redact emails, phones, SSNs, etc. but
312
+ leave credentials untouched.
313
+
314
+ Per-request bypass wins over per-tenant policy. If a tenant has
315
+ `mode="fail_closed"` and a single request legitimately needs to
316
+ send a credential, that request can opt out via `X-PII-Bypass:
317
+ true` and the upstream sees the credential — the rest of the
318
+ tenant's traffic remains fail-closed.
319
+
320
+
321
+ ### Programmatic filter configuration from the SDK
322
+
323
+ For call sites that want to configure PII (and any future gateway
324
+ filters) from Python instead of hand-rolling headers, the SDK ships
325
+ a typed filter config surface:
326
+
327
+ ```python
328
+ import eden
329
+ from eden_sdk.filters import FilterConfig, PIIConfig
330
+
331
+ # Process-wide defaults — applied to every gateway call.
332
+ eden.configure(
333
+ org_id="org_123",
334
+ api_key="sk-eden-...",
335
+ filters=FilterConfig(
336
+ pii=PIIConfig(
337
+ mode="fail_closed",
338
+ disabled_categories=["api_key"], # opt out of specific categories
339
+ ),
340
+ ),
341
+ )
342
+ ```
343
+
344
+ Or, per-call, build a configured OpenAI client in one call:
345
+
346
+ ```python
347
+ from eden_sdk import EdenConfig, FilterConfig, PIIConfig, openai_client
348
+
349
+ cfg = EdenConfig(org_id="org_123", api_key="sk-eden-...")
350
+ client = openai_client(
351
+ cfg,
352
+ filters=FilterConfig(pii=PIIConfig(mode="redact")),
353
+ # Optional: route this specific call through your own
354
+ # OpenAI-compatible upstream.
355
+ upstream_base_url="https://my-internal-llm.example.com/v1",
356
+ upstream_api_key="<your-internal-key>",
357
+ )
358
+
359
+ resp = client.chat.completions.create(
360
+ model="gpt-5",
361
+ messages=[{"role": "user", "content": "hello"}],
362
+ )
363
+ ```
364
+
365
+ Or a one-shot helper for the common case:
366
+
367
+ ```python
368
+ from eden_sdk import (
369
+ EdenConfig, FilterConfig, PIIConfig, chat_completion,
370
+ )
371
+
372
+ cfg = EdenConfig(org_id="org_123", api_key="sk-eden-...")
373
+ resp = chat_completion(
374
+ cfg,
375
+ model="gpt-5",
376
+ messages=[{"role": "user", "content": "hello"}],
377
+ filters=FilterConfig(pii=PIIConfig(mode="fail_closed")),
378
+ )
379
+ ```
380
+
381
+ The SDK renders the filter config as the same wire headers the
382
+ gateway already accepts (`X-PII-Mode`, `X-PII-Disabled-Categories`,
383
+ `X-PII-Bypass`). Per-call filters layered via the `filters=` kwarg
384
+ override the process-wide `EdenConfig.filters` for that one call.
385
+ Adding a new server-side filter is a one-line change in
386
+ `sdk/python/eden_sdk/filters.py` + one new field on `FilterConfig`.
387
+
388
+ The TypeScript SDK (`@eden-ai/sdk`) mirrors this surface:
389
+ `new FilterConfig({ pii: new PIIConfig({ mode: "fail_closed" }) })`
390
+ plus `sdk.gatewayHeaders({ filters })` and `sdk.resolvedGatewayUrl()`.
391
+
392
+ ## License
393
+
394
+ Apache 2.0