A functionnal oriented Python CLI for LLM calling with multi provider and multi model
Project description
Func-LLM
A functional-oriented Python library for LLM calling with multi-provider and multi-model support.
Provides a unified, provider-agnostic interface over Anthropic, Gemini, Mistral (Vertex AI), and OpenAI (Azure) through a single data-driven configuration layer.
Quick Start
import asyncio
import fllme
async def main():
# 1. Create the service (default SQLite backend)
service = await fllme.DeploymentService.from_sqlite("deployments.db")
fllme.configure(service)
# 2. Register a model and its deployment
await service.add_model(fllme.LLMModel(
id="claude-sonnet-4",
name="Claude Sonnet 4",
provider=fllme.Provider.ANTHROPIC,
))
await service.add_deployment(fllme.Deployment(
id="claude-vertex-euw1",
url="https://europe-west1-aiplatform.googleapis.com/v1/projects/my-project/...",
model_id="claude-sonnet-4",
adapter=fllme.AdapterType.ANTHROPIC_VERTEX_V1,
auth_id="google_adc",
))
# 3. Generate
gen_input = fllme.GenerationInput(
model="claude-sonnet-4",
conversation=[fllme.Message(source="user", contents=[...])],
)
output = await fllme.generate(gen_input)
asyncio.run(main())
Architecture
The design is data-driven: models, deployments, and auth are stored as data (not coded as classes). Users register entries in a database; the library resolves them at generation time.
LLMModel ──┐
├── DeploymentService ── generate()
Deployment ─┤ │
│ ├── resolves model → deployment → adapter
AuthPrinciple ┘ └── resolves auth → headers
The flow: GenerationInput → DeploymentService resolves the deployment → Adapter serializes → HTTP call → Adapter deserializes → GenerationOutput.
Project Structure
fllme/
models/
model.py # LLMModel (id, name)
deployment.py # AdapterType enum, Deployment (url, model_id, adapter, auth_id)
auth.py # AuthPrinciple, built-in principles (google_adc, api_key)
message.py # Message, Content blocks (text, media, tool calls, thinking, errors)
input/
main.py # ThinkingLevel, LLMConfig, BasicOutputType, GenerationInput
tools.py # ToolsCallingMode, Tool, ToolsConfig
image.py # Ratio, Resolution, PersonGeneration, MimeType, ImageConfig
output/
main.py # FinishReason, GenerationOutput
usage.py # CacheUsage, Usage
citation.py # CitationType, TextSpan, Citation
safety.py # SafetyCategory, SafetySeverity, SafetyRating, SafetyResult
stream.py # StreamEventType, TextDelta, ThinkingDelta, StreamDelta
auth/
protocol.py # AuthResolver protocol
google_adc.py # Google ADC resolver (asyncio.to_thread wrapping google.auth)
api_key.py # API key resolver (reads env var, returns header)
store/
deployments/
protocol.py # ModelRepository, DeploymentRepository, AuthRepository protocols
sqlite.py # SQLiteStore — default async SQLite implementation
providers/
base.py # Adapter protocol (serialize, parse_stream)
anthropic/vertex_v1.py
gemini/vertex_v1.py
mistral/vertex_v1.py
openai/azure_v1.py
service.py # DeploymentService — composes repos + auth resolution
generate.py # configure(), generate() — main entry point
media.py # MediaResolver protocol, resolve_references(), store_media()
http.py # Shared httpx async client
errors.py # FuncLLMError hierarchy
Domain Models
LLMModel
Simple identity — an ID, a display name, and the provider:
LLMModel(id="claude-sonnet-4", name="Claude Sonnet 4", provider=Provider.ANTHROPIC)
Deployment
Links a model to a concrete cloud endpoint, an adapter for serialization, and an auth method:
Deployment(
id="claude-vertex-euw1",
url="https://europe-west1-aiplatform.googleapis.com/v1/...",
model_id="claude-sonnet-4",
adapter=AdapterType.ANTHROPIC_VERTEX_V1,
auth_id="google_adc",
)
AuthPrinciple
Data-driven auth configuration. Declares which resolver to use, which env vars are required, and resolver-specific config:
AuthPrinciple(
id="azure_openai_key",
name="Azure OpenAI API Key",
resolver_id="api_key",
required_env_vars=["AZURE_OPENAI_KEY"],
config={"header_name": "api-key"},
)
Built-in principles (google_adc, api_key) are pre-seeded in the default SQLite store.
IO Models
Input
GenerationInput is the unified request object. It carries:
- model — model ID string (resolved to a
DeploymentbyDeploymentService) - conversation — list of
Messagewith typed content blocks (text, media, tool calls, tool responses, thinking, errors). Each message has asourcefield (user | model | system | tool) - llm_config — generation parameters (temperature, top_p, top_k, max_tokens, stop sequences, thinking level)
- tool_config — function calling tools, mode (auto/any/none), parallel calling
- image_config — image generation settings (ratio, resolution, person generation, mime type)
- output_type — text, image, hybrid, or a Pydantic
BaseModelfor structured output - system_prompt — extracted from provider-specific locations into a dedicated field
- stream — whether to stream the response
Output
GenerationOutput is the unified response object. It carries:
- message — the model's response as a
Message(directly appendable to conversation history) - finish_reason — why generation stopped (stop, max_tokens, tool_use, content_filter, error)
- usage — token breakdown (input, output, thinking, cache read/creation)
- citations — grounding annotations (URL, document, search) with text spans and confidence
- safety — content filtering results with per-category ratings and refusal details
Streaming
During streaming, the library yields unified StreamDelta events (TextDelta or ThinkingDelta) on the fly, then returns the aggregated GenerationOutput at the end.
Media Resolution
MediaContent blocks can carry three source types: Base64Source, UrlSource, or ReferenceSource. References are opaque user-domain IDs (e.g. a document-management key) that providers cannot consume directly.
The MediaResolver protocol bridges this gap:
class MediaResolver(Protocol):
async def resolve(self, references: list[ReferenceSource]) -> list[Base64Source | UrlSource]: ...
async def store(self, media: list[Base64Source | UrlSource]) -> list[ReferenceSource]: ...
resolve— outbound: converts user-domain IDs into provider-sendable sources before serializationstore— inbound: uploads AI-generated media and returns user-domain IDs after deserialization
Pass an implementation to generate() via the media_resolver keyword argument. Resolution and storage are batched and applied transparently. Resolver failures are wrapped in MediaResolutionError.
Deployment & Storage
Repository Protocols
Three separate async protocols define data access — users can swap the storage backend by implementing them:
ModelRepository— CRUD forLLMModelDeploymentRepository— CRUD forDeployment, plusget_for_model()AuthRepository— CRUD forAuthPrinciple
SQLiteStore (default)
SQLiteStore is the built-in implementation using aiosqlite. It manages three tables with foreign keys (deployments cascade-delete when a model is removed) and pre-seeds built-in auth principles.
store = await SQLiteStore.create("deployments.db") # or ":memory:"
DeploymentService
Composes the three repositories and auth resolution into a high-level API:
service = await DeploymentService.from_sqlite("deployments.db")
await service.add_model(model)
await service.add_deployment(deployment) # validates model_id + auth_id exist
deployment = await service.resolve_deployment("claude-sonnet-4")
headers = await service.get_auth_headers(deployment)
issues = await service.check_deployment_ready(deployment) # missing env vars, etc.
Auth System
Auth is data-driven and extensible. Each AuthPrinciple references a resolver_id that maps to a registered AuthResolver:
class AuthResolver(Protocol):
async def get_headers(self, principle: AuthPrinciple) -> dict[str, str]: ...
def check_env(self, principle: AuthPrinciple) -> list[str]: ...
Built-in resolvers:
| Resolver ID | Resolver | Description |
|---|---|---|
google_adc |
GoogleADCResolver |
Google Application Default Credentials via google.auth |
api_key |
ApiKeyResolver |
Reads an env var, returns it as a header |
Register custom resolvers:
fllme.register_resolver("my_oauth", MyOAuthResolver())
Adapters
Each provider/cloud/version combination has its own adapter implementing the Adapter protocol (serialize, parse_stream).
| AdapterType | Provider | Cloud |
|---|---|---|
anthropic_vertex_v1 |
Anthropic | Vertex AI |
gemini_vertex_v1 |
Gemini | Vertex AI |
mistral_vertex_v1 |
Mistral | Vertex AI |
openai_azure_v1 |
OpenAI | Azure |
New API versions get new enum values (e.g., anthropic_vertex_v2). Adapters are looked up via get_adapter(adapter_type).
Requirements
- Python >= 3.13
- pydantic >= 2.13
- httpx >= 0.28
- aiosqlite >= 0.20
- google-auth >= 2.55
- requests >= 2.32
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fllme-0.2.0.tar.gz.
File metadata
- Download URL: fllme-0.2.0.tar.gz
- Upload date:
- Size: 116.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fcc19c6cd75561d5b18a7d6f6d322ae2cb2446b58d0933f2fbe21821ba0aabf
|
|
| MD5 |
0cd52000b03c651b8f8729524c1e0be2
|
|
| BLAKE2b-256 |
4c0ca13e96b3f9490456119e8fe16997918e21e30cd4fc76482f069b23ef9618
|
File details
Details for the file fllme-0.2.0-py3-none-any.whl.
File metadata
- Download URL: fllme-0.2.0-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4b34942f96229d599137fa1ad28d73d7f6f2e4caa6501a6bb383587d0601d96
|
|
| MD5 |
19682fcebf6cd7f0e6a5732b1b4eb6e2
|
|
| BLAKE2b-256 |
c5ed9ba2fa50311c6609967086c285063ff28d3ebcad08cc4dca7c7bfac9b5aa
|