🔌 pyllmlib
pyllmlib is a lightweight, provider-agnostic Python package that gives you one simple interface to work with multiple Large Language Model (LLM) APIs.
Stop juggling different SDKs and client libraries — whether it’s OpenAI GPT, Google Gemini, Mistral AI, or Groq, you write your code once and switch providers in seconds.
🎯 Ideal for developers who want to:
- Experiment with different LLMs quickly
- Build multi-provider AI applications
- Avoid vendor lock-in with a consistent API
✨ Features
- 🔌 Unified API — A single
generate()function for all providers - 🌐 Multi-Provider Support — OpenAI, Gemini, Mistral, Groq (with more coming soon)
- 🧠 Consistent Message Format — Same request style across providers
- 🔐 Flexible Config — Use env vars, inline setup, or config files
- 📦 Minimal Dependencies — Only needs
requests - 🔄 Quick Provider Switching — Change models with one line
- 🛡️ Automatic Token Handling — Prevents overflows & context errors
- 📜 Role-Based Conversations — System, user, assistant messages
- 🔧 Extensible — Add your own providers with minimal code
- 🚀 No Vendor Lock-In — Swap providers without rewriting logic
📦 Installation
From PyPI (recommended):
pip install pyllmlib
From GitHub:
# Latest release
pip install git+https://github.com/yazirofi/pyllmlib.git
# Development version
git clone https://github.com/yazirofi/pyllmlib.git
cd pyllmlib
pip install -e .
Requirements:
- Python 3.7+
requests(installed automatically)
🚀 Quick Start
from pyllmlib import config, generate
# Configure your preferred LLM
config(
provider="openai",
api_key="your-openai-api-key",
model="gpt-4"
)
# Generate text
response = generate("Explain quantum computing in simple terms")
print(response)
✅ Same code works with any provider — just change the config.
⚙️ Configuration
1. Direct in Code
from pyllmlib import config
# OpenAI
config(provider="openai", api_key="sk-...", model="gpt-4")
# Google Gemini
config(provider="gemini", api_key="AIza...", model="gemini-2.5-flash")
# Mistral
config(provider="mistral", api_key="...", model="mistral-large-latest")
# Groq
config(provider="groq", api_key="gsk_...", model="mixtral-8x7b-32768")
2. Environment Variables
LLM_PROVIDER=openai
LLM_API_KEY=sk-your-openai-key
LLM_MODEL=gpt-4
LLM_BASE_URL=https://api.openai.com/v1 # Optional
from pyllmlib import config, generate
config() # Loads from env
print(generate("What is LLM?"))
💬 Usage Examples
Text Generation
from pyllmlib import config, generate
config(provider="gemini", api_key="AIza...", model="gemini-2.5-flash")
print(generate("What is the capital of France?"))
prompt = """
Write a Python function to calculate factorial with error handling and docstring.
"""
print(generate(prompt))
Interactive Chat
from pyllmlib import config, chat, reset_chat
config(provider="gemini", api_key="AIza...", model="gemini-2.5-flash")
while q := input("Ask: "):
print(chat(q))
reset_chat()
Style Generated Output Response
from pyllmlib import config, chat, reset_chat, style, generate
config(provider="gemini", api_key="AIza...", model="gemini-2.5-flash")
style(generate("Write the wish in one line")) # use the **style** function instead of **print** function
while q := input("Ask: "):
style(chat(q)) # use the **style** function instead of **print** function
reset_chat()
🌐 Supported Providers
✅ Currently Supported
- OpenAI —
gpt-4,gpt-4-turbo,gpt-3.5-turbo - Google Gemini —
gemini-2.5-flash,gemini-1.5-flash - Mistral AI —
mistral-large-latest,mistral-small-latest - Groq —
mixtral-8x7b-32768,llama2-70b-4096,gemma-7b-it
🔜 Coming Soon
- Anthropic Claude
- Cohere
- Ollama & LM Studio (local hosting)
- Hugging Face models
🐛 Troubleshooting
- Auth Errors → Check API key format
- Model Not Found → Verify model name is correct
📊 Best Practices
# ✅ Reuse config for multiple prompts
config(provider="openai", api_key="sk-...", model="gpt-4")
for p in prompts:
print(generate(p))
# ❌ Don’t reconfigure on every request
💡 Cost Optimization: Use gpt-3.5-turbo for simple tasks, gpt-4 for complex ones.
📚 API Reference
config(**kwargs)→ Set provider, API key, modelgenerate(prompt, **kwargs)→ Single text outputgenerate_stream(prompt, **kwargs)→ Streaming outputchat(message)→ Conversational interfacereset_chat()→ Clear conversation history
📄 License
Licensed under the MIT License – see LICENSE.
👨💻 Author
Shay Yazirofi
- GitHub: @yazirofi
- Email: yazirofi@gmail.com
⭐ If you find pyllmlib useful, please star the repo on GitHub! 📖 More docs & tutorials: Wiki
Metadata
Release files for pyllmlib 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyllmlib-0.1.1.tar.gz | 10.9 kB | Without provenance | Details for pyllmlib-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyllmlib-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pyllmlib-0.1.1-py3-none-any.whl |
Total release size: 21.5 kB
Release files / pyllmlib-0.1.1.tar.gz
| Download URL | pyllmlib-0.1.1.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ffa0821d5184a9ac842c7118af88127892369bf112ada2420ea66060193f6cfc
|
|
BLAKE2b-256 checksum How to use checksums |
c7ee32cd9f5888f7629ef8da63a9d17b96f9f4fa40bee0c5f9484b52877432fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / pyllmlib-0.1.1-py3-none-any.whl
| Download URL | pyllmlib-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
490f47063e9da6711438c5cadd464b36d40ad140c652401f33d957f30e72d745
|
|
BLAKE2b-256 checksum How to use checksums |
c4d2672e46de9d636af6cb555740b8a6440c25e1f3adca69a9594833ccd7564e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Security for pyllmlib 0.1.1
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.