A complete setup guide and example scripts for running LM Studio locally with Python SDK integration.
This project provides:
- Step-by-step LM Studio installation and configuration
- Python examples using both LM Studio SDK and OpenAI-compatible API
- Connection testing utilities
- Sample chat completion implementations
- Python 3.13 or higher
- Windows, macOS, or Linux
- At least 8GB RAM (16GB+ recommended for larger models)
-
Download LM Studio
- Visit LM Studio official website
- Download the installer for your operating system
- Install following the standard installation process
-
Download a Model
- Launch LM Studio
- Go to the "Discover" tab
- Search for and download a model
-
Start the Local Server
- Navigate to the "Developer" tab in LM Studio
- Toggle "Status: Stopped" to "Status: Running"
uv is a fast Python package installer and resolver that works great with this project.
-
Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh -
Clone this repository
git clone https://github.com/medvoice-research/lmstudio-local-setup.git cd lmstudio-local-setup -
Install dependencies with uv
uv sync
-
Create a virtual environment
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies with pip
pip install -r requirements.txt
-
Environment Variables (Optional for local testing) Create a
.envfile in the project root:cp .env.example .env
LMSTUDIO_SERVER_HOST=localhost:1234 LMSTUDIO_API_HOST=http://localhost:1234/v1 LMSTUDIO_API_KEY=lm-studio MODEL_CHOICE=your-preferred-model-name
Run the comprehensive connection test:
python test_lmstudio_connection.pyThis script will:
- Test LM Studio SDK connection
- Test OpenAI-compatible API connection
- Perform a sample chat completion
- Provide troubleshooting information if connections fail
Run the basic example:
python lmstudio_hello_world.pyfrom openai import OpenAI
client = OpenAI(
base_url="http://localhost:1234/v1",
api_key="lm-studio"
)
response = client.chat.completions.create(
model="your-model-name",
messages=[
{"role": "user", "content": "Hello, how are you?"}
]
)
print(response.choices[0].message.content)See docs/troubleshooting.md for information on increasing VRAM on Apple Silicon.
See LICENSE file for details.