Python Bindings for llm_api_access
This package provides a unified interface to query popular LLM providers (LlamaServer, Gemini, Anthropic, and OpenAI) directly from Python via PyO3 bindings.
1. Installation
From PyPI (Recommended for users)
pip install llm_api_access
For Local Development / Building from Source
If you are modifying the Rust core or building from source:
# Ensure maturin is installed in your virtual environment
pip install maturin
# Build and develop the package in-place with the python feature enabled
maturin develop --features python
2. Environment Variables & .env Support
Because the underlying Rust library uses dotenv, environment variables can be loaded from a .env file. When invoking from Python, it is recommended to load your .env file explicitly using python-dotenv at the very entry point of your script to ensure keys like GEMINI_API_KEY, ANTHROPIC_API_KEY, or LLAMA_SERVER_URL are available in the process environment before calling Rust code.
pip install python-dotenv
Example .env configuration:
GEMINI_API_KEY=your_gemini_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here
LLAMA_SERVER_URL=http://192.168.0.91:8080
BASE64_DATA=your_base64_encoded_image_string_here
3. Usage Guide
Here is how to use the primary providers (LlamaServer and Gemini), along with multi-turn conversations and multimodal message handling in Python:
import os
from dotenv import load_dotenv
import llm_api_access
# Load environment variables from .env file first
load_dotenv()
# Configure optional parameters (temperature, max_tokens, server URLs, etc.)
config = (
llm_api_access.LlmConfig()
.with_temperature(0.7)
.with_max_tokens(150)
)
# -------------------------------------------------------------------------
# 1. LlamaServer (Local / Custom URL - Primary Target)
# -------------------------------------------------------------------------
llama_config = (
llm_api_access.LlmConfig()
.with_server_url(os.getenv("LLAMA_SERVER_URL", "http://192.168.0.91:8080"))
.with_max_tokens(100)
)
try:
llama_client = llm_api_access.LLMClient(llm_api_access.LLMProvider.LlamaServer)
response = llama_client.send_message(
prompt="Explain quantum computing in one sentence.",
model="gemma-4-26b",
config=llama_config
)
print("LlamaServer Response:", response)
except Exception as e:
print("LlamaServer Error:", e)
# -------------------------------------------------------------------------
# 2. Gemini (Secondary Target)
# -------------------------------------------------------------------------
try:
gemini_client = llm_api_access.LLMClient(llm_api_access.LLMProvider.Gemini)
response = gemini_client.send_message(
prompt="Write a haiku about coding.",
model=None,
config=config
)
print("Gemini Response:", response)
except Exception as e:
print("Gemini Error:", e)
# -------------------------------------------------------------------------
# 3. Multi-turn Conversation & Multimodal (Images via Base64)
# -------------------------------------------------------------------------
base64_image = os.getenv("BASE64_DATA")
if base64_image and base64_image != "default_base64_value":
try:
# Construct a multimodal user message with an attached base64 image
image_message = llm_api_access.Message(
role="user",
text="What is in this image? Answer briefly.",
image_base64=base64_image,
image_media_type="image/png"
)
# Follow-up message in conversation history
follow_up = llm_api_access.Message(
role="user",
text="Summarize that in 3 words."
)
conversation = [
image_message,
llm_api_access.Message(role="assistant", text="I see a graphical pattern."),
follow_up
]
client = llm_api_access.LLMClient(llm_api_access.LLMProvider.Gemini)
chat_response = client.send_chat(conversation, model=None, config=config)
print("Multimodal Chat Response:", chat_response)
except Exception as e:
print("Multimodal Error:", e)
else:
print("Skipping multimodal example: BASE64_DATA not found in environment.")
4. Troubleshooting
ModuleNotFoundError: No module named 'llm_api_access': Runmaturin develop --features pythoninside your virtual environment to ensure the dynamic library is linked correctly.- API Key Errors: Ensure
python-dotenvis installed andload_dotenv()is called at the top of your python script so environment variables are populated before Rust execution begins.
Metadata
Release files for llm-api-access 0.1.56
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 | |
|---|---|---|---|---|
| llm_api_access-0.1.56.tar.gz | 48.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llm_api_access-0.1.56-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | CPython 3.9 | Linux glibc 2.17+ x86-64 | Details |
Total release size: 2.3 MB
Release files / llm_api_access-0.1.56.tar.gz
| Download URL | llm_api_access-0.1.56.tar.gz |
|---|---|
| Size | 48.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57ec2b7413fde27f20e6035ccaa6265549a673c46acd5b1fd58501cbf71cf686
|
|
BLAKE2b-256 checksum How to use checksums |
fb64d487f42e6f22b35025f3e37645ea3cd6ce4a24505c960487bc555913052f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Release files / llm_api_access-0.1.56-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | llm_api_access-0.1.56-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
0159ce45720dc42e058bbde4976e11b8e3992c74fd54844d80edee5be7a0cb56
|
|
BLAKE2b-256 checksum How to use checksums |
03b7ff6b05823325eb0b5a354780cd1fc01e9e82d7df6c4c9167f81e94b72caf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.15.0
|
Security for llm-api-access 0.1.56
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.