Multi-tool setup
If you are building a suite of tools — for example, a code assistant with search, analysis, and refactor tools — you can register each as a separate tool in CLIMeter while sharing a single SDK configuration.
Overview
Each CLIMeter tool has its own slug, pricing, and analytics. You can use multiple Meter instances (one per tool) or configure the global meter once and use meter.record(event_name) with explicit event names:
- Each CLIMeter tool has its own slug, pricing, and analytics
- Use multiple
Meterinstances (one per tool) or configure the global meter with a defaulttool_slug - All tools share the same event buffer and flush thread
Shared configuration
config.py
Python
import os
from climeter import meter
# Configure once — no default tool_slug
meter.configure(
api_key=os.environ["CLIMETER_API_KEY"],
)Per-tool overrides
tools/__init__.py
Python
import os
from climeter import Meter, meter
# Option A: configure per tool before decorating
meter_search = Meter()
meter_search.configure(api_key=os.environ["CLIMETER_API_KEY"], tool_slug="code-search")
@meter_search.track(command="search-code")
def search_code(query: str, repo: str = ".") -> list[dict]:
"""Semantic code search — price set in CLIMeter dashboard."""
return run_search(query, repo)
# Option B: use meter.record() directly with the event name
@meter.track(command="analyze-code")
def analyze_code(file_path: str) -> dict:
"""Static code analysis — configure CLIMETER_TOOL_SLUG=code-analyzer."""
return run_analysis(file_path)CLI dispatch pattern
Use a single CLI entrypoint that dispatches to the appropriate tool:
cli.py
Python
"""
Usage:
python cli.py search "async def" ./src
python cli.py analyze ./src/main.py
python cli.py refactor ./src/auth.py "add type hints"
"""
import sys
import atexit
from climeter import meter
from tools import search_code, analyze_code, refactor_code
# Flush events on exit (important for short-lived CLI processes)
atexit.register(meter.flush, timeout=3)
COMMANDS = {
"search": search_code,
"analyze": analyze_code,
"refactor": refactor_code,
}
def main():
if len(sys.argv) < 2 or sys.argv[1] not in COMMANDS:
print(f"Usage: cli.py [{' | '.join(COMMANDS)}] [args...]")
sys.exit(1)
cmd = sys.argv[1]
args = sys.argv[2:]
result = COMMANDS[cmd](*args)
print(result)
if __name__ == "__main__":
main()Testing
In your test suite, disable metering to avoid recording test events:
conftest.py
Python
import pytest
from climeter import meter
@pytest.fixture(autouse=True)
def disable_metering(monkeypatch):
"""Disable CLIMeter in all tests."""
monkeypatch.setenv("CLIMETER_API_KEY", "")
yield