Unified LLM connectors for OpenAI, Google Gemini, Ollama, and LM Studio.
Project description
rwu-llmconnector
Unified Python connectors for calling large language models through a common interface.
Supported backends:
- OpenAI (official API and OpenAI-compatible endpoints)
- Google Gemini (
google-genai) - Ollama (local server)
- LM Studio (local or remote server, stateful conversations, MCP tool integrations)
Installation
pip install rwu-llmconnector
With a virtual environment (recommended):
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install rwu-llmconnector
Quick start
OpenAI
from openai import OpenAI
from rwu_llmconnector import OpenAIClient
client = OpenAI(api_key="your-openai-api-key")
llm = OpenAIClient(client, model="gpt-4o-mini")
response, prompt_tokens, completion_tokens, reasoning_tokens, runtime = llm.send_request(
"What is PyPI?",
system_message="you are a helpful assistant",
)
print(response)
Google Gemini
from google import genai
from rwu_llmconnector import GeminiClient
client = genai.Client(api_key="your-gemini-api-key")
llm = GeminiClient(client, model="gemini-2.5-flash-lite")
response, *_ = llm.send_request(
"What is PyPI?",
system_message="you are a helpful assistant",
)
print(response)
Ollama
from rwu_llmconnector import OllamaClient
llm = OllamaClient(model="llama3.2", host="http://localhost:11434")
response, *_ = llm.send_request(
"What is PyPI?",
system_message="you are a helpful assistant",
)
print(response)
LM Studio
Default server: http://localhost:1234 (override with LMSTUDIO_BASE_URL or env var).
from rwu_llmconnector import LMStudioClient, StatefulLMStudioClient
# local_history: send conversation from self.history (default)
llm = LMStudioClient(
model="qwen/qwen3-4b-2507",
base_url="http://localhost:1234",
api_key=None,
)
response, prompt_tokens, completion_tokens, reasoning_tokens, runtime = llm.send_request(
"What is PyPI?",
system_message="you are a helpful assistant",
)
print(response)
For server-side context (store=True, previous_response_id chain), use StatefulLMStudioClient.
MCP / tool integrations
Pass integration specs in the constructor, or add them later with add_integration(). Each entry is either a dict (LM Studio integration JSON) or an object with to_lmstudio_integration().
Hugging Face MCP (same pattern as the live test in tests/test_lmstudio_client.py):
from rwu_llmconnector import LMStudioClient
mcp_hf = {
"type": "ephemeral_mcp",
"server_label": "huggingface",
"server_url": "https://huggingface.co/mcp",
}
llm = LMStudioClient(
base_url="http://localhost:1234",
model="openai/gpt-oss-20b",
temperature=0.0,
integrations=[mcp_hf],
)
response_msg, prompt_tokens, completion_tokens, reasoning_tokens, runtime = llm.send_request(
"list 3 new papers",
ignore_history=True,
timeout=120,
)
print(response_msg)
print(
f"prompt tokens: {prompt_tokens}, completion_tokens: {completion_tokens}, "
f"reasoning_tokens: {reasoning_tokens}, runtime: {runtime:.2f} seconds"
)
If Hugging Face is already configured in ~/.lmstudio/mcp.json, use a plugin id instead:
mcp_hf = {"type": "plugin", "id": "mcp/huggingface"}
Custom integration wrapper (same hook as the unit test test_integration_to_lmstudio_integration_hook):
class MyMCP:
def to_lmstudio_integration(self):
return {"type": "mcp", "server": "demo"}
llm = LMStudioClient(model="your-model")
llm.add_integration(MyMCP())
response, *_ = llm.send_request("hi", ignore_history=True)
Model loader helpers
from rwu_llmconnector.model_loader import load_openai_model, load_ollama_model
llm = load_openai_model("gpt-4o-mini", env="openai")
ollama = load_ollama_model("llama3.2")
Set OPENAI_API_KEY in the environment when using env="openai".
Development
Clone the repository, then:
uv sync --group dev
cp .env.example .env # add your API keys locally; never commit .env
Run tests (unit tests always; live tests skip if the backend is unreachable):
uv run pytest -v
LM Studio only (including MCP):
uv run pytest tests/test_lmstudio_client.py -v
uv run pytest tests/test_lmstudio_client.py::test_lmstudio_mcp_hf_lists_new_papers -v
Tests load variables from .env via python-dotenv. See .env.example for supported names.
| Variable | Used for |
|---|---|
OPENAI_API_KEY |
OpenAI |
GEMINI_API_KEY or GOOGLE_API_KEY |
Gemini |
LMSTUDIO_BASE_URL, LMSTUDIO_MODEL |
LM Studio live tests (defaults: http://localhost:1234, qwen/qwen3-4b-2507) |
LMSTUDIO_API_KEY or MAC_STUDIO_API_KEY |
LM Studio auth (optional locally) |
OLLAMA_MODEL, OLLAMA_HOST |
Ollama (optional) |
LMSTUDIO_MCP_MODEL |
MCP live test model (default openai/gpt-oss-20b) |
LMSTUDIO_MCP_INTEGRATION_JSON |
Override MCP spec (e.g. plugin id from mcp.json) |
Project layout
src/rwu_llmconnector/ # library code
tests/ # integration tests
pyproject.toml
uv.lock # pinned dev dependencies
.env.example # template for local secrets (commit this)
Do not commit: .env, .venv/, dist/, __pycache__/, .pytest_cache/, .idea/
Publishing to PyPI
Build and upload (requires PyPI account and API token):
uv build
uv publish
Upload only the files in dist/; do not add dist/ to git.
After creating the GitHub repository, uncomment and set Repository under [project.urls] in pyproject.toml.
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rwu_llmconnector-0.1.1.tar.gz.
File metadata
- Download URL: rwu_llmconnector-0.1.1.tar.gz
- Upload date:
- Size: 76.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db9740a006f66105d594883e6c39f3254ed17c15285f25e9c08a31bcda431ac2
|
|
| MD5 |
51112b0ac04f93359098a0c4f342037a
|
|
| BLAKE2b-256 |
3b53df92b7486112b7eb19020523f192b252034b3694d0b2c09d7a5b8bd7b4c7
|
File details
Details for the file rwu_llmconnector-0.1.1-py3-none-any.whl.
File metadata
- Download URL: rwu_llmconnector-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
325a1e3648ba7e448d61dbd5c440b8bd097041c8b7be0313f9ed6c5a4f71905f
|
|
| MD5 |
61b6abe4157c9f04349e26733fe7640d
|
|
| BLAKE2b-256 |
3c4aae4e308d041da1e44a84dbc8d45d42fe6c50ce107734ae558c346f4c58b0
|