launchdarkly-ai-python
Convenience barrel package for the LaunchDarkly AI Python SDK. Re-exports the complete public API of launchdarkly-ai-server — install this instead of launchdarkly-ai-server for the simplest setup.
Installation
pip install launchdarkly-ai-python launchdarkly-ai-openai-messages
To enable trace export to the LaunchDarkly Observability dashboard, install the otel extras group:
pip install "launchdarkly-ai-python[otel]"
init_client() detects the OTel packages at runtime and configures tracing automatically. If the extras are not installed, a single warning is logged and all AI calls continue normally with no-op spans.
Usage
Import everything from launchdarkly_ai_python instead of launchdarkly_ai_server:
import asyncio
from launchdarkly_ai_python import config, graph, resolve_graph
from launchdarkly_ai_python import init_client, shutdown, global_registry
from launchdarkly_ai_openai_messages import create_openai_messages_handler
async def main():
result = await config(
key="my-ai-config-flag",
handler=create_openai_messages_handler(),
).invoke("What is feature flagging?", {"kind": "user", "key": "user-123"})
print(result.response)
await shutdown()
asyncio.run(main())
inspect_config(key, context)
Reads an AI Config flag variation without invoking any AI provider. Re-exported from launchdarkly-ai-server — see the full reference there.
from launchdarkly_ai_python import inspect_config
result = await inspect_config("my-ai-config-flag", {"kind": "user", "key": "user-123"})
if result["enabled"]:
print(result["config"]["model"]["name"])
Never raises. Returns {"enabled": bool, "config": dict | None, "meta": dict | None}.
Evaluations from code
init_evaluations, the criterion types, EvalTool, and the evaluations result types are all re-exported:
from launchdarkly_ai_python import Judge, Scorer, init_evaluations
evals = init_evaluations(project_key="my-project")
result = await evals.run(
key="unique-evaluation-key",
dataset="golden-dataset",
handler=my_handler,
generation={"provider": "OpenAI", "model": "gpt-4o"},
criteria=[
Judge(key="accuracy-judge"),
Scorer(name="mentions-policy", fn=lambda row, output: "policy" in (output or "")),
],
)
LD_API_TOKEN is required. Configure LD_SDK_KEY — or initialize your own client with init_client(client=...) — to emit one $ld:ai:offline-evals:generation event per generated row, plus one $ld:ai:offline-evals:criterion event per (row, criterion) when criteria are supplied, through the standard SDK event transport. The SDK reports scores; LaunchDarkly rules on them at ingest. A judge served by a different provider than generation needs a handler for it in judge_handlers. Each row's tool calls are recorded during generation and rendered into the judge's {{message_history}}, between the row input and the generated output, so a rubric can grade the tool trajectory as well as the final answer. Use LD_API_BASE_URI for staging or local management API traffic; it is separate from the SDK delivery setting LD_BASE_URI. Evaluation-run links use the explicit ui_base_uri option or LD_UI_BASE_URI, defaulting to https://app.launchdarkly.com; set it when the project is not in production, or a run created elsewhere still links to the production app. tools is a list of EvalTool. Construct one to define a tool in code, or await evals.tools.get() for a tool that already exists in LaunchDarkly. See the core evaluations guide.
Experimental features
Experimental features are not re-exported from this package. They live in
launchdarkly-ai-server, the package this one depends on, and need a launchdarkly-ai-server
release that includes them. Import them from launchdarkly_ai_server.experimental; if that
import fails, upgrade launchdarkly-ai-server itself, since upgrading this package alone can
leave an older launchdarkly-ai-server in place. For example, Agent Skills
lives in launchdarkly_ai_server.experimental.skills; see the
Agent Skills guide.
All exports, types, and behaviors are identical to launchdarkly-ai-server. See the core client README for the full API reference.
Metadata
Release files for launchdarkly-ai-python 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| launchdarkly_ai_python-0.2.0.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| launchdarkly_ai_python-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / launchdarkly_ai_python-0.2.0.tar.gz
| Download URL | launchdarkly_ai_python-0.2.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
be0ae3d28fcd8ba04c996065fef1e30a1ddf7269a256070b2c5e201ec09ce592
|
|
BLAKE2b-256 checksum How to use checksums |
42d9c9bf6f6c09f7fc20979a499327aa11185fece0b26d4068004d049b8490cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / launchdarkly_ai_python-0.2.0-py3-none-any.whl
| Download URL | launchdarkly_ai_python-0.2.0-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9acaffe173d136d3920ac9ab904c94cbdc76e59f1ece9d236570037272db5fe
|
|
BLAKE2b-256 checksum How to use checksums |
a652d6f13786260ca618e26e9af497528fe0f56599bcdbc5147839192d3699d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|