liveBook · Manning

LM Studio Python SDK

As explained in Domain-Specific Small Language Models

A Python client library for interacting programmatically with models served by LM Studio, including chat, completion, embeddings, and tool-calling workflows.

LM Studio Python SDK is an open-source Python client for models served by an LM Studio API server. It supports chat, text completion, embeddings, streaming, and tool-calling workflows from applications, notebooks, or the Python REPL. section 12.4

Choose between two API styles:

  • Use the synchronous convenience API for CLI programs and notebook cells. section 12.4
  • Use the scoped resource API with a context manager for larger applications and deterministic connection cleanup. section 12.4
  • Call respond or respond_stream for chat, complete for text completion, and embed for vector generation. section 12.4

Tool-calling workflow

Define a typed Python function, load an instruct model, and pass the function to model.act so the model can invoke it during a conversation.

How Domain-Specific Small Language Models covers it

How deep it goes
Explains API styles and demonstrates chat, streaming, completion, embeddings, and agentic flows without detailing server internals.
Examples
Uses Llama 3.2 3B Instruct, streamed multi-turn chat, completion, embedding generation, and a multiplication tool.
What it assumes
Assumes a running LM Studio API server with a loaded model, while demonstrating chat context and tool definitions directly.
What you can do after
Build Python clients that chat with, stream from, complete with, embed through, and extend locally served models.
How it connects
Connects local inference with chat context, text completion, embeddings, streaming responses, context managers, and tool calling.

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.