{"id":2105,"library":"lmnr","title":"Laminar Python SDK","description":"The Laminar Python SDK provides an open-source platform for engineering LLM products, offering capabilities to trace, evaluate, annotate, and analyze LLM data. It helps developers bring their AI applications to production with confidence by providing observability into their LLM interactions. The library is currently at version 0.7.47 and is actively maintained.","status":"active","version":"0.7.47","language":"en","source_language":"en","source_url":"https://github.com/lmnr-ai/lmnr-python","tags":["LLM","observability","AI","tracing","evaluation","SDK","monitoring"],"install":[{"cmd":"pip install 'lmnr[all]'","lang":"bash","label":"Install with all instrumentations"},{"cmd":"pip install 'lmnr[anthropic,openai]'","lang":"bash","label":"Install with specific instrumentations (e.g., Anthropic, OpenAI)"},{"cmd":"pip install -U 'lmnr[all]' openai python-dotenv","lang":"bash","label":"Install with OpenAI and dotenv for quickstart"}],"dependencies":[{"reason":"Optional, for OpenAI API instrumentation.","package":"openai","optional":true},{"reason":"Optional, for Anthropic API instrumentation.","package":"anthropic","optional":true},{"reason":"Optional, for loading API keys from .env files.","package":"python-dotenv","optional":true}],"imports":[{"symbol":"Laminar","correct":"from lmnr import Laminar"},{"symbol":"observe","correct":"from lmnr import observe"},{"symbol":"wrap_llm_call","correct":"from lmnr import wrap_llm_call"},{"symbol":"lmnr_context","correct":"from lmnr import lmnr_context"}],"quickstart":{"code":"import os\nimport openai\nfrom lmnr import Laminar, observe\n\n# It's recommended to install with pip install -U 'lmnr[all]' openai python-dotenv\n\n# Initialize Laminar. project_api_key will be read from LMNR_PROJECT_API_KEY environment\n# variable if not explicitly passed.\nLaminar.initialize(\n    project_api_key=os.environ.get('LMNR_PROJECT_API_KEY', ''),\n    # Instrument the OpenAI module for automatic tracing of API calls.\n    instrumentModules={\n        \"OpenAI\": openai\n    }\n)\n\n# Initialize OpenAI client *after* Laminar has instrumented the module.\n# The OpenAI API key will be read from OPENAI_API_KEY environment variable.\nclient = openai.OpenAI(api_key=os.environ.get('OPENAI_API_KEY', ''))\n\n@observe(name=\"poem_generator\")\ndef generate_poem(topic: str) -> str:\n    \"\"\"Generates a short poem using OpenAI and traces the call with Laminar.\"\"\"\n    print(f\"Calling OpenAI to generate a poem about: {topic}\")\n    response = client.chat.completions.create(\n        model=\"gpt-4o-mini\",\n        messages=[\n            {\"role\": \"user\", \"content\": f\"Write a short poem about {topic}\"},\n        ],\n    )\n    return response.choices[0].message.content\n\nif __name__ == \"__main__\":\n    # Ensure LMNR_PROJECT_API_KEY and OPENAI_API_KEY are set in your environment\n    # or a .env file loaded with python-dotenv.\n    if not os.environ.get('LMNR_PROJECT_API_KEY') or not os.environ.get('OPENAI_API_KEY'):\n        print(\"Please set LMNR_PROJECT_API_KEY and OPENAI_API_KEY environment variables.\")\n        print(\"You can get LMNR_PROJECT_API_KEY from your Laminar dashboard.\")\n        exit(1)\n\n    print(\"Generating a poem with Laminar tracing enabled...\")\n    try:\n        poem = generate_poem(\"a starry night\")\n        print(\"\\nGenerated Poem:\")\n        print(poem)\n        print(\"\\nCheck your Laminar dashboard for the trace of this operation!\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n        print(\"Ensure your API keys are correct and you have network connectivity.\")","lang":"python","description":"This quickstart demonstrates how to initialize Laminar, instrument the OpenAI SDK, and trace an LLM call using the `@observe` decorator. It expects `LMNR_PROJECT_API_KEY` and `OPENAI_API_KEY` to be set in environment variables."},"warnings":[{"fix":"Standardize on either automatic instrumentation for supported libraries or manual instrumentation for custom logic. Avoid interleaving them within the same code path.","message":"Mixing automatic instrumentation (e.g., via `instrumentModules` or default behavior) with manual span management (e.g., `lmnr_context` or `start_as_current_span`) can lead to unpredictable or duplicated tracing results. It is recommended to choose one instrumentation style per function or module for clarity and correct tracing.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"For multi-threaded scenarios, explicitly manage context propagation or consider using asynchronous programming patterns where `contextvars` typically behave as expected. Test thoroughly in your specific multi-threaded environment.","message":"Laminar's context management for tracing relies on `contextvars.ContextVar`, which may not propagate context correctly across native Python threads without explicit handling. This can result in incomplete or broken traces in multi-threaded applications.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"To disable all auto-instrumentation, use `Laminar.initialize(instruments=set())`. To instrument specific modules, use `Laminar.initialize(instrumentModules={'OpenAI': openai})` (as shown in quickstart).","message":"Automatic instrumentation for popular LLM, Vector DB, database, and requests libraries is enabled by default if the `instruments` argument is omitted during `Laminar.initialize()`. To explicitly control or fully disable auto-instrumentation, pass the `instruments` argument.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}