Skip to main content

pydantic-ai-lmstudio-provider

A Pydantic AI provider for LM Studio local inference.

Installation

uv add pydantic-ai-lmstudio-provider

Requirements

  • Python 3.12+
  • LM Studio installed and running locally

Quick Start

  1. Start LM Studio and load a model (e.g., via http://localhost:1234)

  2. Use with Pydantic AI:

from pydantic_ai import Agent
from pydantic_ai_lmstudio_provider import LMStudioProvider

provider = LMStudioProvider()

agent = Agent(
    provider=provider,
    model='lmstudio-ai/qwen2.5-7b-instruct',  # or any model loaded in LM Studio
)

result = agent.run_sync('What is the capital of France?')
print(result.data)

Configuration

The LMStudioProvider supports several initialization patterns:

Default (uses cached HTTP client)

provider = LMStudioProvider()

Custom API key

provider = LMStudioProvider(api_key='your-api-key')

Custom HTTP client

import httpx
from pydantic_ai_lmstudio_provider import LMStudioProvider

http_client = httpx.AsyncClient(timeout=60.0)
provider = LMStudioProvider(http_client=http_client)

Pass your own OpenAI client

from openai import AsyncOpenAI
from pydantic_ai_lmstudio_provider import LMStudioProvider

openai_client = AsyncOpenAI(
    base_url='http://localhost:1234/v1',
    api_key='lmstudio',
)
provider = LMStudioProvider(openai_client=openai_client)

LM Studio Setup

  1. Download and install LM Studio
  2. Open LM Studio and download a model (recommended: Qwen2.5, Llama 3.2, or Mistral)
  3. Click "Start Server" and ensure the local server is running at http://localhost:1234
  4. Select your model and click "Apply"

Usage with Tools

You can use Pydantic AI agents with tools:

from pydantic import BaseModel
from pydantic_ai import Agent
from pydantic_ai_lmstudio_provider import LMStudioProvider

class WeatherResult(BaseModel):
    temperature: int
    conditions: str

weather_agent = Agent(
    provider=LMStudioProvider(),
    model='lmstudio-ai/qwen2.5-7b-instruct',
    result_type=WeatherResult,
)

result = weather_agent.run_sync('What is the weather in Paris?')
print(result.data.temperature)  # e.g., 22

License

MIT

Metadata

Release files for pydantic-ai-lmstudio-provider 0.1.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 pydantic-ai-lmstudio-provider 0.1.0
File Size Uploaded Provenance Actions
pydantic_ai_lmstudio_provider-0.1.0.tar.gz 2.0 kB Without provenance Details for pydantic_ai_lmstudio_provider-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-lmstudio-provider 0.1.0
File Interpreter ABI Platform Actions
pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl Python 3 none any Details for pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl

Total release size: 5.5 kB

Release files / pydantic_ai_lmstudio_provider-0.1.0.tar.gz

Download URL pydantic_ai_lmstudio_provider-0.1.0.tar.gz
Size 2.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a9bd5662715655d01308091dc66c364ec8bc14998382e3b12dc454983b1a2e01
BLAKE2b-256 checksum
How to use checksums
be4c91579b8bac7175cc39e8e8df75b2e69928cbae4d8e713cb1f8c9635fde1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl

Download URL pydantic_ai_lmstudio_provider-0.1.0-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf605fe5310eb067e5c237c7f9ea6dd963fb2b166985e32972f29262d4ff0272
BLAKE2b-256 checksum
How to use checksums
9e3f881af6aed35e5b2f906af7e7aaaed9da9db34f7e45403d9a024169ea1d63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.1 {"installer":{"name":"uv","version":"0.11.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for pydantic-ai-lmstudio-provider 0.1.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

0.1.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