Skip to main content

Language Model Development Kit

What it offers:

  • Simplest interface to call different Language Model APIs
  • Minimal dependencies: HTTP requests only, no third party packages
  • Streaming
  • Thinking / reasoning efforts
  • Comfy structured outputs via Pydantic models
  • Parallel completions
  • Unified HTTP error handling
  • Easy location config: shapes (chat:, responses:, messages:, systemone:) are addressed via @<host>[:<port>], vendors (openai:, anthropic:, ...) default to their hosted endpoint and let @<address> override it, and providers with multiple datacenters (AWS Bedrock, GCP Vertex) use @<region>
  • Model fallbacks
  • Bring Your Own Key (for each provider)
  • Optional Telemetry following OpenTelemetry GenAI Semantic Conventions
  • In-process observation hook (observe()) to capture request/response pairs from wrapped code
  • Decision models (non-generative encoders) like Jev, GLiDE or self-hosted Laya servers via decide(): label probabilities for typed questions

What it does NOT offer:

  • Tools / function calling / MCP
  • Agents (but you can build your own on top of this! See markov-agent)
  • Multimodality (only text-in, text-out)
  • Shady under-the-hood prompt modification (e.g. to force structured output)
  • API gateways

If you are looking for a more constrained but out-of-the-box agent interface, I'd recommend pydantic-ai or haystack-ai. If you are looking to keep granular control but extend on tools or multimodality, I'd recommend litellm or leveraging the OpenAI-compatible endpoints that providers normally set up. The closest to the "less intrusive path to unified LM calling" idea in lmdk is chatlas, but their main public interface is stateful (versus the full stateless design of lmdk). If you want a unified a token for all providers and are willing to give away telemetry data, check Gateways like Opper or openrouter.

Installation

uv add lmdk

Optional OpenTelemetry support:

uv add 'lmdk[telemetry]'

Usage

Completions

Check the expanders below for different use cases of generative language models.

from lmdk import complete

model = "mistral:mistral-small-2603"
# supports locations as in "vertex:gemini-2.5-flash@europe-west4"
# or "bedrock:eu.anthropic.claude-opus-5@eu-central-1" (region inferred from the
# geo prefix when omitted)
Single prompt
response = complete(model=model, prompt="Tell me a joke")
Multi-turn conversation
messages = [
    UserMessage("My name is Alice."),
    AssistantMessage("Nice to meet you, Alice!"),
    UserMessage("What is my name?"),
]
response = complete(model=model, prompt=messages)
System prompt and generation kwargs
response = complete(
    model=model,
    prompt="Hi!",
    system_instruction="Talk like a pirate",
    generation_kwargs={"temperature": 0.9, "max_tokens": 10}
)
Streaming
token_iter = complete(model=model, prompt="Count from 1 to 5.", stream=True)
Model fallbacks
response = complete(model=["mistral:nonexistent-model", model], prompt="Hi")
# first request will raise NotFoundError bc model does not exist, second will work
Shapes, vendors and locations

A provider name is either a shape or a vendor:

  • Shapes are wire formats only (chat: (OpenAIs legacy), responses: (OpenAI's new), messages: (Anthropic standard), systemone: (TypeSafe's Jev)). They have no hosted default, so the @<address> suffix is required and the request goes to <address> + the shape's path:

    # Format: chat:<model-id>@<host>[:<port>]
    # Most local model servers (llama.cpp, vLLM, Ollama, LM Studio, etc.) expose
    # an OpenAI-compatible /v1/chat/completions API:
    response = complete(
        model="chat:Qwen3.6-27B-BF16@192.168.10.51:4000",
        prompt="Hello!"
    )
    # same idea for the other shapes:
    #   "responses:<model>@<host>[:<port>]"  -> POST <host>/v1/responses
    #   "messages:<model>@<host>[:<port>]"   -> POST <host>/v1/messages
    #   "systemone:<model>@<host>[:<port>]"  -> POST <host>/v1/systemone
    
  • Vendors (openai:, anthropic:, mistral:, openrouter:, lyceum:, typesafe:, fastino:, ...) subclass a shape with a hosted default location and their own API key. The @ suffix is optional and overrides the default location, so a self-hosted server that copies a vendor's API is reachable too:

    # hosted default (sends FASTINO_API_KEY):
    decide(model="fastino:glide", ...)
    # self-hosted GLiDE server (sends LOCAL_API_KEY instead):
    decide(model="fastino:glide@192.168.10.51:8100", ...)
    

Location rules:

  • If the location has no scheme, http:// is assumed.
  • bedrock: and vertex: keep their @<region> suffix (e.g. vertex:gemini-2.5-flash@europe-west4), which is a region, not an address.
  • If a server requires authentication, set the LOCAL_API_KEY environment variable. It is sent in the provider's auth header format (Bearer, x-api-key or X-API-Key).
Structured output
class Ingredient(BaseModel):
    name: str
    quantity: int
    unit: str = ""

class Recipe(BaseModel):
    ingredients: list[Ingredient]

response = complete(model=model, prompt="How do I make cheescake?", output_schema=Recipe)
# response.parsed will have a Recipe instance
Reasoning / thinking

lmdk offers 4 thinking configurations for the time-test compute of recent LLMs. We map them to the configs available on the provider side. See the documentation on each provider for more info.

# "none" (default) | "low" | "medium" | "high"
response = complete(model=model, prompt="Solve this carefully...", thinking_effort="high")

# Works alongside structured output where the provider supports both:
response = complete(
    model=model,
    prompt="Plan a 3-day trip to Lisbon.",
    output_schema=Trip,
    thinking_effort="medium",
)

The usage of the thinking can be seen in the respective CompletionResponse.thinking and CompletionResponse.thinking_tokens fields.

Parallel calls
from lmdk import complete_batch

batch = complete_batch(model=model, prompt_list=["Greet in english", "Saluda en espanyol."])
# `batch` is a CompletionBatch. Iterate it to handle each outcome:
for result in batch:
    if isinstance(result, Exception):
        ...  # this prompt failed
    else:
        ...  # CompletionResponse

# Aggregates over successful responses:
batch.input_tokens, batch.output_tokens, batch.latency
batch.responses  # successes only
batch.errors     # exceptions only
Template Rendering
from lmdk import render_template

# Render a template string with variables
result = render_template(
    template="Hello, {{ name }}!",
    name="World"
)
# Output: "Hello, World!"

# Render a template from a jinja file
result = render_template(
    path="path/to/template.jinja2",
    name="World"
)
Observing wrapped code
from lmdk import observe

with observe() as obs:
    answer = my_function_that_calls_complete()

for record in obs.records:
    record.request    # CompletionRequest sent to the LM
    record.response   # CompletionResponse returned

Useful for tests, evals, and debug tooling where the wrapped function only returns its own result but you also want to inspect the underlying LM calls. Streaming completions are not recorded.

Decisions

Decision models are encoders (non-generative): instead of generating text, they return a probability for each label of each question, in a single forward pass. Every question is evaluated independently against the same state, in one request.

from lmdk import Question, decide

response = decide(
    model="typesafe:jev-latest",  # or "fastino:glide", or "systemone:english@localhost:8000" for a self-hosted laya-serve, or "fastino:glide@192.168.10.51:8100" for a self-hosted GLiDE server
    state={"message": "I was billed twice for March, refund it or I cancel."},
    questions={
        "department": Question(
            text="Which team should handle `message`?",
            labels={"billing": "invoices, payments, refunds", "technical": "bugs, outages"},
        ),
        "urgency": Question(
            text="How urgent is `message`?",
            labels={"low": "can wait", "medium": "this week", "high": "today"},
            is_ordered=True,
        ),
        "churn": Question(
            text="Does the customer threaten to leave?",
            labels={"yes": "mentions cancelling or leaving", "no": "no such threat"},
        ),
    },
)
response.probabilities  # {"department": {"billing": 0.97, "technical": 0.03}, "urgency": {...}, ...}
  • A Question is its text plus labels, each with a description. Set is_ordered=True when the labels form a scale (in insertion order). Labels that are a yes/no (or true/false) pair use the provider's dedicated yes/no head.
  • state is a string or a dict; a dict keeps its structure, so questions can reference fields by path (`message`).
  • Model fallbacks work as in complete. Batching, telemetry and observe() cover completions only for now.

Telemetry

Telemetry is off by default and adds no required dependencies to the default install. To enable OpenTelemetry-based spans and metrics, install the optional extra and set LMDK_TELEMETRY:

uv add 'lmdk[telemetry]'
export LMDK_TELEMETRY=metadata  # spans/metrics without prompt text
# export LMDK_TELEMETRY=content  # also records prompt, system-instruction, and response text

We follows the experimental Gen AI semconv v1.41.0. We only instrument non-streaming responses for now.

lmdk only emits telemetry through the OpenTelemetry SDK. Your application owns exporter, processor, reader, collector endpoint, i.e.: you decide how and where to send the emitted traces.

Below are some minimal exporter setups. Call them once at process start before invoking complete / complete_batch.

Console (debugging)

Prints spans to stdout. Useful to verify instrumentation locally without any backend.

from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter


def configure_console_traces() -> None:
    provider = TracerProvider()
    provider.add_span_processor(BatchSpanProcessor(ConsoleSpanExporter()))
    trace.set_tracer_provider(provider)
Pydantic Logfire

Logfire installs itself as the global TracerProvider, so spans emitted by lmdk are forwarded automatically. Requires uv add logfire and a LOGFIRE_TOKEN.

import os
import logfire


def configure_logfire_traces() -> None:
    logfire.configure(
        token=os.environ["LOGFIRE_TOKEN"],
        service_name="my-app",
        # lmdk already controls prompt/response redaction via LMDK_TELEMETRY;
        # don't let Logfire second-guess scrubbing of content.
        scrubbing=False,
        send_to_logfire=True,
    )
Grafana (OTLP / Tempo)

Ship spans over OTLP to Grafana Cloud (or a self-hosted Tempo + OTel Collector). Requires uv add opentelemetry-exporter-otlp.

import os

from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor


def configure_grafana_traces() -> None:
    # For Grafana Cloud OTLP, set:
    #   OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp-gateway-<region>.grafana.net/otlp
    #   OTEL_EXPORTER_OTLP_HEADERS=Authorization=Basic%20<base64(instanceID:token)>
    exporter = OTLPSpanExporter(
        endpoint=os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] + "/v1/traces",
    )
    provider = TracerProvider(resource=Resource.create({"service.name": "my-app"}))
    provider.add_span_processor(BatchSpanProcessor(exporter))
    trace.set_tracer_provider(provider)

Development

Structure

src/lmdk/
├── completion.py       # Entry points: complete, complete_batch
├── decision.py         # Entry point: decide
├── datatypes.py        # Common message, question and response schemas
├── provider.py         # Base Provider class and registry (shapes first, then vendors)
├── providers/
│   ├── shapes/         # Wire formats only, always need @<address> (chat, responses, messages, systemone)
│   └── vendors/        # Hosted defaults on top of a shape (openai, anthropic, mistral, bedrock, vertex, ...)
├── errors.py           # Unified HTTP and API error handling
└── utils.py            # Shared helper functions

Tooling

We use just for development tasks. Use:

  • just install: Sync environment from the lockfile.
  • just format: Lints and formats with ruff.
  • just check-types: Static analysis with ty.
  • just check-complexity: Cyclomatic complexity checks with complexipy.
  • just test: Runs pytest with 90% coverage threshold.

See justfile for a complete list of dev commands.

Contribute

  1. Hooks: Install pre-commit hooks via just install-hooks. PRs will fail CI if linting/formatting is not applied.
  2. Issues: Open an issue first using the default template.
  3. PRs: Link your PR to the relevant issue using the PR template.

You can use just validate <model> (runs example.py) to verify which features run properly and which do not for a new provider / model. Not all of them have to pass to open a PR: some providers do not even support native structured output. Do at least the normal non-structured, non-streamed completion. The rest can raise NotImplementedError.

License

MIT

This inference package has been used to build:

Made with mold template

Metadata

Release files for lmdk 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lmdk 3.0.0
File Size Uploaded Provenance Actions
lmdk-3.0.0.tar.gz 42.7 kB Without provenance Details for lmdk-3.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lmdk 3.0.0
File Interpreter ABI Platform Actions
lmdk-3.0.0-py3-none-any.whl Python 3 none any Details for lmdk-3.0.0-py3-none-any.whl

Total release size: 98.9 kB

Release files / lmdk-3.0.0.tar.gz

Download URL lmdk-3.0.0.tar.gz
Size 42.7 kB
Tags Source
SHA-256 checksum
How to use checksums
47232bab8aa6b39889a404488ad4d8a2e781ebaeb07cde866fb5c8368348ddfb
BLAKE2b-256 checksum
How to use checksums
bfbf919ef402c97be52f99e85d84619d1e7911b0456a3957fd2264ebe3a2d48c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / lmdk-3.0.0-py3-none-any.whl

Download URL lmdk-3.0.0-py3-none-any.whl
Size 56.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96ff67ce4bde1c1936b0ce76c7b38e8d7656cf3e0df97f64a4e5835c8a835a8d
BLAKE2b-256 checksum
How to use checksums
4228e953f72262b16c634c4c82413aa2d447810d61c71b16eb7b45d67992d55f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for lmdk 3.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page