Skip to main content

Personal core toolkit for AI projects — config loading, LLM client factory, and logging.

Project description

lmcore

Personal core toolkit for AI projects. Install once, call with inputs, never edit the package.

Covers three things every project needs:

  • Config — load and validate .env secrets
  • LLM — build AI clients from a models.yaml file
  • Logging — colored, consistent logging across all modules

Install

pip install lmcore

With specific provider dependencies:

pip install lmcore[openai]
pip install lmcore[anthropic]
pip install lmcore[ollama]
pip install lmcore[all]       # all three providers

Config

Call load_config once at startup. Pass the keys your project needs — the package handles loading from .env, validating, and returning a plain dict.

from lmcore import load_config

cfg = load_config(
    required=["OPENAI_API_KEY", "CHROMA_API_KEY"],
    optional={"ACTIVE_ARCH": "arch_1", "LOG_LEVEL": "INFO"}
)
  • required — must exist in .env, raises EnvironmentError if any are missing
  • optional — uses the default value if not set in .env

LLM

models.yaml

Lives in your project root. Define only what your project uses — chat and embed are both optional. Each section is a list so you can define multiple clients and reference them by index.

arch_1:
  chat:
    - provider: openai
      model: gpt-4o
      api_key_env: OPENAI_API_KEY
    - provider: anthropic
      model: claude-sonnet-4-6
      api_key_env: ANTHROPIC_API_KEY
  embed:
    - provider: ollama
      model: nomic-embed-text
      base_url_env: OLLAMA_URL

arch_2:
  chat:
    - provider: anthropic
      model: claude-opus-4-8
      api_key_env: ANTHROPIC_API_KEY

Supported fields per client:

Field Required Description
provider yes ollama, openai, or anthropic
model yes model name string
api_key_env when needed env var name that holds the API key
base_url no override default endpoint (e.g. local Ollama)
base_url_env no env var name that holds the base URL (alternative to base_url)

Getting clients

from lmcore import get_chat_client, get_embed_client

# index defaults to 0 — covers most single-client projects
chat  = get_chat_client("models.yaml", arch="arch_1")
embed = get_embed_client("models.yaml", arch="arch_1")

# specify index for multiple clients
openai_client    = get_chat_client("models.yaml", arch="arch_1", index=0)
anthropic_client = get_chat_client("models.yaml", arch="arch_1", index=1)

Adding a custom provider

If you need a provider not built into the package, register it in your project:

from lmcore import register_provider

def _build_groq(cfg):
    from groq import Groq
    return Groq(api_key=cfg["api_key"])

register_provider("groq", _build_groq)

Once registered, groq works as a provider: value in models.yaml like any built-in.


Logging

from lmcore import configure_logging, get_logger

configure_logging()          # call once at app startup
configure_logging("DEBUG")   # optional level override

logger = get_logger(__name__)

logger.info("Starting up")
logger.warning("Something looks off")
logger.error("Connection failed")

Color scheme:

Color Level
Cyan INFO
Yellow WARNING
Red ERROR / CRITICAL
Dim DEBUG

Full Example

Project layout:

my-project/
├── .env
├── models.yaml
└── app/
    └── core/
        ├── config.py
        └── llm.py

.env:

OPENAI_API_KEY=sk-...
ACTIVE_ARCH=arch_1

models.yaml:

arch_1:
  chat:
    - provider: openai
      model: gpt-4o
      api_key_env: OPENAI_API_KEY
    - provider: ollama
      model: llama3
      base_url_env: OLLAMA_URL

app/core/config.py:

from lmcore import load_config, configure_logging

configure_logging()

cfg = load_config(
    required=["OPENAI_API_KEY"],
    optional={"ACTIVE_ARCH": "arch_1"}
)

app/core/llm.py:

from lmcore import get_chat_client
from app.core.config import cfg

chat = get_chat_client("models.yaml", arch=cfg["ACTIVE_ARCH"])

Anywhere in the project:

from lmcore import get_logger
from app.core.llm import chat

logger = get_logger(__name__)

response = chat.chat(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Summarize this document."}]
)
logger.info(f"Done: {response.choices[0].message.content}")

Built-in Providers

Provider provider: value Install extra
Ollama ollama pip install lmcore[ollama]
OpenAI openai pip install lmcore[openai]
Anthropic anthropic pip install lmcore[anthropic]

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

lmcore-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

lmcore-0.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file lmcore-0.2.0.tar.gz.

File metadata

  • Download URL: lmcore-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for lmcore-0.2.0.tar.gz
Algorithm Hash digest
SHA256 323d889e7c4cd156109e81e19864a3f7a5af2de882b35e070ff1458f9b2060ae
MD5 e31d36ae3f3c179469588069a736489a
BLAKE2b-256 154da1b936fa7dadb4c4dffd1b675b806d6fc04563a4ab1962a219d40eec72c0

See more details on using hashes here.

File details

Details for the file lmcore-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: lmcore-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for lmcore-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4676f506898a6c58fe45448db8852344a5b9298b26afb01f2cb5847f799f1c09
MD5 b7e2d62f59145c7da52fbea0539be2ba
BLAKE2b-256 1dd489eb7255cdfac6e201e13fdd1edd0c1a45eeb6d3365094205cd446ed0e0a

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 Pingdom Monitoring Sentry Error logging StatusPage Status page