Registry / llm-agents / lmnr
library0.7.61pypypi✓ verified 24d ago

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.

pip install 'lmnr[all]'
INSTALL
IMPORT
SIG · LMNR
L
lmnr
llm-agentspythonv0.7.61
Install
13.5s avg
Import
1767ms
Disk
70MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.61 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
installs and imports cleanly · install 0.0s · import 2.015s · 73.8MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 13.5s · import 1.518s · 70MB
70MB installed
● package 70MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Laminar
from lmnr import Laminar
observe
from lmnr import observe
wrap_llm_call
from lmnr import wrap_llm_call
lmnr_context
from lmnr import lmnr_context

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.

import os import openai from lmnr import Laminar, observe # It's recommended to install with pip install -U 'lmnr[all]' openai python-dotenv # Initialize Laminar. project_api_key will be read from LMNR_PROJECT_API_KEY environment # variable if not explicitly passed. Laminar.initialize( project_api_key=os.environ.get('LMNR_PROJECT_API_KEY', ''), # Instrument the OpenAI module for automatic tracing of API calls. instrumentModules={ "OpenAI": openai } ) # Initialize OpenAI client *after* Laminar has instrumented the module. # The OpenAI API key will be read from OPENAI_API_KEY environment variable. client = openai.OpenAI(api_key=os.environ.get('OPENAI_API_KEY', '')) @observe(name="poem_generator") def generate_poem(topic: str) -> str: """Generates a short poem using OpenAI and traces the call with Laminar.""" print(f"Calling OpenAI to generate a poem about: {topic}") response = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "user", "content": f"Write a short poem about {topic}"}, ], ) return response.choices[0].message.content if __name__ == "__main__": # Ensure LMNR_PROJECT_API_KEY and OPENAI_API_KEY are set in your environment # or a .env file loaded with python-dotenv. if not os.environ.get('LMNR_PROJECT_API_KEY') or not os.environ.get('OPENAI_API_KEY'): print("Please set LMNR_PROJECT_API_KEY and OPENAI_API_KEY environment variables.") print("You can get LMNR_PROJECT_API_KEY from your Laminar dashboard.") exit(1) print("Generating a poem with Laminar tracing enabled...") try: poem = generate_poem("a starry night") print("\nGenerated Poem:") print(poem) print("\nCheck your Laminar dashboard for the trace of this operation!") except Exception as e: print(f"An error occurred: {e}") print("Ensure your API keys are correct and you have network connectivity.")
lmnr --version
Debug
Known issues
gotchaMixing 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.
fix
Standardize on either automatic instrumentation for supported libraries or manual instrumentation for custom logic. Avoid interleaving them within the same code path.
affects: >=0.1.0
gotchaLaminar'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.
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.
affects: >=0.1.0
gotchaAutomatic 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.
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).
affects: >=0.1.0
Errors
Common errors & fixes
Error initializing MistralAI instrumentor
This error occurs when the MistralAI instrumentor encounters a problem during initialization, often due to an outdated or incompatible version of the `lmnr` library or its specific instrumentor package, or when multiple instrumentation packages conflict.
fix
Update the `lmnr` library to the latest version (`pip install --upgrade lmnr`) and ensure that only the necessary instrumentor packages are installed. If `lmnr[all]` was installed, consider removing it and installing only the specific instrumentors you need (e.g., `pip install lmnr[openai]`).
SSL Certificate Verification Error
This error, often accompanied by `StatusCode.UNAVAILABLE` for GRPC connections, indicates a problem with SSL certificate verification. This can be due to an incomplete or incorrect certificate chain, or the client not being configured to accept the server's certificate.
fix
Ensure that the SSL certificate chain is correctly configured and that the client is set up to trust the server's certificate. For self-hosted environments, verify that `base_url`, `http_port`, and `grpc_port` are correctly specified during `Laminar.initialize()`.
AttributeError: 'Thread' object has no attribute '_otel_context'
This `AttributeError` suggests a conflict or issue with how OpenTelemetry's context management interacts with Python's threading, particularly within the `lmnr` library's instrumentation.
fix
This issue was addressed in a fix related to threading instrumentor in the `lmnr-python` repository. Updating `lmnr` to the latest version should resolve this problem.
ModuleNotFoundError: No module named 'lmnr'
This common error indicates that the `lmnr` package is not installed in the Python environment being used, or the Python interpreter cannot find the installed package due to a misconfigured `PYTHONPATH` or virtual environment.
fix
Install the `lmnr` library using pip: `pip install lmnr`. If you need specific instrumentations, install them with `pip install lmnr[openai]`, `pip install lmnr[langchain]`, etc. Ensure you are running your code in the same Python environment where `lmnr` was installed.
Laminar.initialize() must be called once in your application
The `Laminar.initialize()` method is designed to be called only once early in the application's lifecycle to set up observability. Calling it multiple times can lead to unexpected behavior or resource conflicts.
fix
Ensure that `Laminar.initialize()` is called a single time at the very beginning of your application's startup code, before any LLM or instrumented calls are made. It should ideally be placed in the main entry point of your application or a dedicated configuration file.
Upgrade
Version history
0.7.61latest on PyPI · released Aug 27, 2026
Audit
Dependencies
openaioptionalOptional, for OpenAI API instrumentation.
anthropicoptionalOptional, for Anthropic API instrumentation.
python-dotenvoptionalOptional, for loading API keys from .env files.
Agent activity
32 hits · last 30 days
node
26
OpenAI (training)
2
Resources
lmnr — pip install lmnr · libregistry