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
.envsecrets - LLM — build AI clients from a
models.yamlfile - 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, raisesEnvironmentErrorif any are missingoptional— 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
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 lmcore-0.1.1.tar.gz.
File metadata
- Download URL: lmcore-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efe4ed0321cecb7544be2ce592a01efa230016f8e82625cf754e3b651a5b343f
|
|
| MD5 |
3d0787a7db269b5de6ab0926968e74b7
|
|
| BLAKE2b-256 |
33afd1d8c9698e75e031b8a5465d081c6c819435221564aa3b37c8f5bbbd90ab
|
File details
Details for the file lmcore-0.1.1-py3-none-any.whl.
File metadata
- Download URL: lmcore-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c187b04d3c0e8dfd96aba50f1886fb1a504745736fa72d88c1a65d2a35a1195f
|
|
| MD5 |
6af7517a45d9e466efed61389262d040
|
|
| BLAKE2b-256 |
b28fa967a4283c09804a436285ccd84fe65db8cb9b1f2c93e9aac9f4fd69427b
|