This project has been archived by its maintainers, and is no longer receiving any updates.
llm-factory
A flexible Python factory for working with multiple Large Language Model (LLM) providers (OpenAI, Anthropic, Gemini, Llama) using a unified interface, with robust configuration and extensibility.
Features
- ✅ Unified interface for multiple LLM providers (OpenAI, Anthropic, Gemini, Llama)
- ✅ Easy provider switching via configuration
- ✅ Pydantic-based response validation
- ✅ Environment variable-based secure configuration
- ✅ Extensible for new providers
- ✅ Supports model, temperature, max tokens, and retries per provider
Installation
pip install python-llm-factory
Configuration
The package uses environment variables for authentication and configuration. You can set these in a .env file or your environment:
# Required environment variables for each provider
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
GEMINI_API_KEY=your_gemini_api_key
Examples
Basic Usage: Creating a Completion
from pydantic import BaseModel, Field
from python_llm_factory import LLMFactory
from python_llm_factory import Settings
class CompletionModel(BaseModel):
response: str = Field(description="Your response to the user.")
reasoning: str = Field(description="Explain your reasoning for the response.")
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "If it takes 2 hours to dry 1 shirt out in the sun, how long will it take to dry 5 shirts?"},
]
llm = LLMFactory(
settings=Settings().gemini.gemini_2_5_flash,
)
completion = llm.completions_create(
response_model=CompletionModel,
messages=messages,
)
print(f"Response: {completion.response}\n")
print(f"Reasoning: {completion.reasoning}")
🤝 Contributing
If you have a helpful tool, pattern, or improvement to suggest:
- Fork the repo
- Create a new branch
- Submit a pull request
I welcome additions that promote clean, productive, and maintainable development.
🙏 Thanks
Thanks for exploring this repository!
Happy coding!
Metadata
Release files for python-llm-factory 0.0.5
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 |
|---|---|---|---|---|
| python_llm_factory-0.0.5.tar.gz | 8.0 kB | Without provenance | Details for python_llm_factory-0.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_llm_factory-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for python_llm_factory-0.0.5-py3-none-any.whl |
Total release size: 18.3 kB
Release files / python_llm_factory-0.0.5.tar.gz
| Download URL | python_llm_factory-0.0.5.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
491f569aac818a1e81c0ded7111c193196ddf1ba5ad7f1aedde34359f170d8ef
|
|
BLAKE2b-256 checksum How to use checksums |
aeffaa1d4f147e64ef4e702e622481a28defc52efe12c86a62d0d485d35c1c49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / python_llm_factory-0.0.5-py3-none-any.whl
| Download URL | python_llm_factory-0.0.5-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f950e2096fe037dc7d364b7303152dfcf182542232a57b958a9e41da081f77f8
|
|
BLAKE2b-256 checksum How to use checksums |
a9fd7b0b8b116e096ed0aaa73c753ebad4428d1caad917fa92d5a08e0a17627c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for python-llm-factory 0.0.5
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.