Skip to main content

Python Bindings for llm_api_access

This package provides a unified interface to query popular LLM providers (OpenAI, Anthropic, Gemini, and LlamaServer) 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. However, when invoking from Python, it is recommended to load your .env file explicitly using python-dotenv at the very entry point of your Python script to ensure keys like OPEN_AI_KEY, ANTHROPIC_API_KEY, or GEMINI_API_KEY are available in the process environment before calling Rust code.

pip install python-dotenv

Example .env configuration:

OPEN_AI_KEY=your_openai_key_health
ANTHROPIC_API_KEY=your_anthropic_key_here
GEMINI_API_KEY=your_gemini_key_here
LLAMA_SERVER_URL=http://192.168.0.91:8080

3. Usage Guide

Here is how to use all available providers 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. OpenAI
# -------------------------------------------------------------------------
try:
    openai_client = llm_api_access.LLMClient(llm_api_access.LLMProvider.OpenAI)
    response = openai_client.send_message(
        prompt="Explain quantum computing in one sentence.",
        model="gpt-4o",
        config=config
    )
    print("OpenAI Response:", response)
except Exception as e:
    print("OpenAI Error:", e)

# -------------------------------------------------------------------------
# 2. Anthropic
# -------------------------------------------------------------------------
try:
    anthropic_client = llm_api_access.LLMClient(llm_api_access.LLMProvider.Anthropic)
    response = anthropic_client.send_message(
        prompt="Why is the sky blue?",
        model=None, # Uses default model
        config=config
    )
    print("Anthropic Response:", response)
except Exception as e:
    print("Anthropic Error:", e)

# -------------------------------------------------------------------------
# 3. Gemini
# -------------------------------------------------------------------------
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)

# -------------------------------------------------------------------------
# 4. LlamaServer (Local / Custom URL)
# -------------------------------------------------------------------------
llama_config = (
    llm_api_access.LlmConfig()
    .with_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="Hello local model!",
        model=None,
        config=llama_config
    )
    print("LlamaServer Response:", response)
except Exception as e:
    print("LlamaServer Error:", e)

4. Troubleshooting

  • ModuleNotFoundError: No module named 'llm_api_access': Run maturin develop --features python inside your virtual environment to ensure the dynamic library is linked correctly.
  • API Key Errors: Ensure python-dotenv is installed and load_dotenv() is called at the top of your python script so environment variables are populated before Rust execution begins.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_api_access-0.1.50.tar.gz (43.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_api_access-0.1.50-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file llm_api_access-0.1.50.tar.gz.

File metadata

  • Download URL: llm_api_access-0.1.50.tar.gz
  • Upload date:
  • Size: 43.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for llm_api_access-0.1.50.tar.gz
Algorithm Hash digest
SHA256 9084b8871d503978fd79bee51ade88b33f5a256a068cd5d46ef3e1593702fb0d
MD5 4d5146bec24a7b0bf31368c0f94df28f
BLAKE2b-256 9107742202300fc6935b800591b519b11a0b99e3e1c3829cb72a03c5f98de32b

See more details on using hashes here.

File details

Details for the file llm_api_access-0.1.50-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for llm_api_access-0.1.50-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33d5ac7e0a73b94c84eda2a29d660cda39db21e0c97ddce34786c1c7e9d5c7d6
MD5 e2b761e22351ac8df9518caade1cf9f0
BLAKE2b-256 f9b29f248e43ab221fa43d16c3ffd10f6456ef1170d0fe5144bd1d5c51daf3c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page