CMDOP umbrella package — reusable utilities (llm, codegen, logging, telegram, agent) extracted from the relay.
Project description
cmdop-utils
The umbrella package for reusable CMDOP utilities — heavy, self-contained pieces lifted out of the relay repo so the repo stays light. This is not the whole relay (run that from the repo); it's an installable home for features other projects (e.g. the LLM router) can reuse.
pip install cmdop-utils
📚 docs.cmdop.com · Server · Connect · Bots · SDK
Features
cmdop_utils.codegen — multi-language client generator
A monorepo-agnostic code-generation engine: declarative targets (proto / OpenAPI /
WebSocket) → typed clients in Go, TypeScript, Python, Swift. You supply a
Config describing your sources + outputs; the engine drives the toolchains
(grpc_tools, ogen, @hey-api, openapi-python-client, swift-openapi, a
built-in WS emitter).
from cmdop_utils.codegen.schema import Config, ProtoSpec, ProtoTarget, Lang, Tool
from cmdop_utils.codegen.core.runner import run
cfg = Config(proto=ProtoSpec(targets=[ProtoTarget(
name="proto-python", lang=Lang.PY, tool=Tool.GRPC_PYTHON,
path=my_out_dir, proto_dirs=[my_proto_dir],
)]))
run(cfg, kinds=("proto",))
Or the CLI, pointing at a module that exposes config: Config:
python -m cmdop_utils.codegen --config myproject.codegen_config gen all
External toolchains (ogen, buf, swift-openapi, @hey-api) are subprocess prerequisites — install the ones your targets use.
cmdop_utils.llm — universal LLM transport
One module for every model call — chat, structured extraction (Pydantic
response_format with parse-and-repair), vision, image generation/edit,
embeddings, translation. It owns HTTP, auth, cost-per-response, retries, a
live OpenRouter model registry (pricing + capabilities), and a cascade
LLMRouter with role presets. Provider-agnostic (OpenAI / OpenRouter).
from cmdop_utils.llm import LLMClient
client = LLMClient(api_key="sk-...") # or omit → reads OPENROUTER_API_KEY / OPENAI_API_KEY
resp = client.chat("Summarize this.", model="alias:balanced")
print(resp.content, resp.cost_usd)
Config is hybrid (the openai/stripe-SDK pattern): pass keys explicitly, or let
them fall back to env (OPENROUTER_API_KEY, OPENAI_API_KEY, or the
CMDOP_DEV_LLM_KEYS__* form). No global Django config — explicit always wins.
cmdop_utils.telegram — Telegram notification service
A small, framework-neutral Telegram sender (queue + formatters + parse-mode
handling) used for alerts/notifications. Reads CMDOP_TELEGRAM_BOT_TOKEN /
CMDOP_TELEGRAM_CHAT_ID from env, or take them per-call.
cmdop_utils.agent — reusable tool-use loop
The framework-neutral agent harness built on pydantic-ai (Agent + toolsets +
iter()). Slim — no provider SDKs bundled; the consumer injects the Model.
cmdop_utils.logging — universal structured logger
structlog + rich: async-safe queue sink, token-efficient logfmt for AI
consumption, dual console/machine renderers, context scoping, noise control.
All features are framework-neutral — no Django.
cmdop_utils.llmandcmdop_utils.telegramwere ported fromdjango_cfg; the single host seam iscmdop_utils._compat(env-driven config + a tiny TTL cache).
Apache-2.0.
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 cmdop_utils-0.1.1.tar.gz.
File metadata
- Download URL: cmdop_utils-0.1.1.tar.gz
- Upload date:
- Size: 487.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6efe03509c765e86ba957073e808aa096746d89a3261ef9823bd67bfcb5abeb5
|
|
| MD5 |
5d67db5762b16c021f394eb409426e0a
|
|
| BLAKE2b-256 |
9ca52b5c4aac48fe4546a4e36230037a4699ea77368c7ea053032361d16b1f7d
|
File details
Details for the file cmdop_utils-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cmdop_utils-0.1.1-py3-none-any.whl
- Upload date:
- Size: 517.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da99e92162f4177e07b006b5aed55f2691da63aba167d9e629a627286517f1c0
|
|
| MD5 |
3d92f3eda8b2465c31b35167e05d638e
|
|
| BLAKE2b-256 |
5580d18ccc4990f5f38a7a78569543bcdc7bb89608b47762f621a9b8a040634f
|