Skip to main content

A minimal Python library for interacting with various LLM providers

Project description

SmolLLM

A minimal Python library for interacting with various LLM providers, featuring automatic API key load balancing and streaming responses.

Installation

pip install smolllm
uv add "smolllm @ ../smolllm"

Quick Start

from dotenv import load_dotenv
import asyncio
from smolllm import ask_llm

# Load environment variables at your application startup
load_dotenv()

async def main():
    response = await ask_llm(
        "Say hello world",
        model="gemini/gemini-2.0-flash"
    )
    print(response)

if __name__ == "__main__":
    asyncio.run(main())

Reasoning Effort

For reasoning-capable models, pass reasoning_effort through to the provider. Useful for Ollama reasoning models where omitting it can make replies much slower.

response = await ask_llm(
    "Reply with one word.",
    model="ollama/qwen3.5:0.8b",
    base_url="http://rocry-ubuntu.local:11434/v1",
    reasoning_effort="none",
)

Provider Configuration

Format: provider/model_name (e.g., openai/gpt-4, gemini/gemini-2.0-flash)

API Keys

The library looks for API keys in environment variables following the pattern: {PROVIDER}_API_KEY

Example:

# .env
OPENAI_API_KEY=sk-xxx
GEMINI_API_KEY=key1,key2  # Multiple keys supported

Custom Base URLs

Override default API endpoints using: {PROVIDER}_BASE_URL

Example:

OPENAI_BASE_URL=https://custom.openai.com/v1
OLLAMA_BASE_URL=http://localhost:11434/v1

Advanced Configuration

You can combine multiple keys and base URLs in several ways:

  1. One key with multiple base URLs:
OLLAMA_API_KEY=ollama
OLLAMA_BASE_URL=http://localhost:11434/v1,http://other-server:11434/v1
  1. Multiple keys with one base URL:
GEMINI_API_KEY=key1,key2
GEMINI_BASE_URL=https://api.gemini.com/v1
  1. Paired keys and base URLs:
# Must have equal number of keys and URLs
# The library will randomly select matching pairs
GEMINI_API_KEY=key1,key2
GEMINI_BASE_URL=https://api.gemini.com/v1,https://api.gemini.com/v2

Environment Setup Best Practices

When using SmolLLM in your project, you should handle environment variables at your application level:

  1. Create a .env file:
# .env
OPENAI_API_KEY=sk-xxx
GEMINI_API_KEY=xxx,xxx2
ANTHROPIC_API_KEY=sk-xxx
  1. Load environment variables before using SmolLLM:
from dotenv import load_dotenv
import os

# Load at your application startup
load_dotenv()

# Now you can use SmolLLM
from smolllm import ask_llm

Tips

  • Keep sensitive API keys in .env (add to .gitignore)
  • Create .env.example for documentation
  • For production, consider using your platform's secret management system
  • When using multiple keys, separate with commas (no spaces)

Project details


Download files

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

Source Distribution

smolllm-0.8.0.tar.gz (58.7 kB view details)

Uploaded Source

Built Distribution

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

smolllm-0.8.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file smolllm-0.8.0.tar.gz.

File metadata

  • Download URL: smolllm-0.8.0.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smolllm-0.8.0.tar.gz
Algorithm Hash digest
SHA256 3c1633e1a497767bf10f0f5bc1fd3e9c36c185bb343d1cdae132fad53aae8105
MD5 f5e2b6d91279b824217f025993f0d6e4
BLAKE2b-256 7ffa17f319ea9d4f8f58f2c6da8d20bdb98fefaedf9c30a0bda7b86f7d5f8682

See more details on using hashes here.

Provenance

The following attestation bundles were made for smolllm-0.8.0.tar.gz:

Publisher: release.yml on RoCry/smolllm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file smolllm-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: smolllm-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smolllm-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6dd719ab7652b13c336f9e1fe30efb4bcefa1602e990a94723fb9c845d30598a
MD5 bd54ea8568a8a446ce9e586092def988
BLAKE2b-256 bdcedd288314e50901193869a8114124c34eff156f53f9e431de3e43b536995e

See more details on using hashes here.

Provenance

The following attestation bundles were made for smolllm-0.8.0-py3-none-any.whl:

Publisher: release.yml on RoCry/smolllm

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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