LlmUnify
LlmUnify is a Python library designed to simplify and standardize interactions with multiple Large Language Model (LLM) providers. By offering a unified interface, it enables seamless integration and allows you to switch between providers or models without modifying your code. The library abstracts the complexity of invoking LLMs, supports streaming responses, and can be easily configured via environment variables or method arguments.
Supported Providers
- AWS Bedrock (via
boto3) - Azure AI Foundry (via
azure-ai-inference) - Google Vertex Ai (via
vertexai) - Ollama (via direct API calls)
- IBM WatsonX (via
ibm-watsonx-ai) - OpenAI (via
openai)
Future versions will include support for additional providers.
Installation
Install the core library from PyPI
To install the library directly from PyPI, run:
pip install llmUnify
Install with dependencies for a specific provider
To install the library with AWS-specific dependencies, use:
pip install 'llmUnify[aws]'
Install with all provider-specific dependencies
To install the library with all available provider-specific dependencies, use:
pip install 'llmUnify[all]'
Quickstart
Configuration and Authentication
LlmUnify retrieves provider-specific credentials and configuration from environment variables, with the option to override them using method arguments.
Example .env configuration:
OLLAMA_API_KEY=your_ollama_api_key
AWS_ACCESS_KEY_ID=your_aws_access_key_id
AWS_SECRET_ACCESS_KEY=your_aws_secret_access_key
Minimal Example
from llmUnify import LlmOptions, LlmUnify
from dotenv import load_dotenv
# Load configurations from .env file
load_dotenv()
# Define options for text generation
options = LlmOptions(
temperature=0.7,
prompt="Write a motivational poem:",
)
# Generate a response specifying provider and model
result = LlmUnify.generate(
model="<provider>:<model-name>", # Provider and model name separated by ":"
options=options,
)
print(result.generated_text)
Reusing Connectors
For repeated calls to the same provider, you can use a reusable connector:
from llmUnify import LlmOptions, LlmUnify
from dotenv import load_dotenv
# Load configurations from .env file
load_dotenv()
# Create a connector for a specific provider
connector = LlmUnify.get_connector(
provider="<provider>",
)
# Define options for text generation
options = LlmOptions(prompt="List three ways to stay productive:")
# Generate a response in streaming mode
result = connector.generate_stream(model_name="model_name", options=options)
print(result.generated_text)
Usage Metrics Logging
LlmUnify can log usage statistics such as token counts, elapsed time, and optional call identifiers.
Enable logging via environment variables:
LLM_UNIFY_ENABLE_USAGE_METRICS=true
LLM_UNIFY_USAGE_METRICS_OUTPUT_PATH=llm_unify_usage_metrics.csv # optional, default is ./llm_unify_usage_metrics.csv
Enable logging via code:
from llmUnify import configure_usage_metrics
UsageMetricsLogger.enable_usage_metrics(enabled=True, output_path="my_metrics.csv")
Pass a custom call name to identify calls in the logs:
result = LlmUnify.generate(
provider="<provider>:<model-name>",
options=options,
call_name="<call_name>"
)
After each call with logging enabled, a new row will be appended to the CSV file at the specified path.
Metadata
Release files for llmUnify 1.0.2
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 | |
|---|---|---|---|---|
| llmunify-1.0.2.tar.gz | 18.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llmunify-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.1 kB
Release files / llmunify-1.0.2.tar.gz
| Download URL | llmunify-1.0.2.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f1a206fb56cea5b7e865e54c906eca126dfc47208472f734ee1343bc9e241da9
|
|
BLAKE2b-256 checksum How to use checksums |
fffde00b7b5e527ca337addec4df42bb54d78e695aea0f68b292ce71175152f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.19 Linux/6.11.0-1018-azure
|
Release files / llmunify-1.0.2-py3-none-any.whl
| Download URL | llmunify-1.0.2-py3-none-any.whl |
|---|---|
| Size | 32.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
802dbe431f5fa8631e0928cd072d34cfa3f34148bc28c7fdccff6f149ca168b3
|
|
BLAKE2b-256 checksum How to use checksums |
792734a2570f0d91e3d0b9c859f775c66b42f89f7e43523622a056292ef62949
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.10.19 Linux/6.11.0-1018-azure
|
Security for llmUnify 1.0.2
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.