Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

leanprompt-cli

The usage logger for Python apps, part of leanprompt by the LM Warden Team. leanprompt gets more from every LLM call your app makes: its skills teach AI coding assistants to make prompts cacheable, cut dead weight, stop wasted output and speed up first tokens, without changing the answers; it is not a prompt-compression library. The main tool is the npm package (npx leanprompt install); this package is the Python side of its measure loop.

The logger writes one JSON line per LLM call to a usage log. npx leanprompt score reads that log and gives a measured score for how well the app's prompts reuse the provider's cache.

Install

pip install leanprompt-cli

It depends on kvsig 0.1.0, which computes the keyed prompt ids.

Use

import os
from openai import OpenAI
from leanprompt_cli import Logger

key_bytes = bytes.fromhex(os.environ["LEANPROMPT_KEY"])  # 32 random bytes, generated once, kept out of the repo
logger = Logger(".leanprompt/usage.jsonl", key_bytes, "openai", "gpt-x")

client = OpenAI()
body = {"model": "gpt-x", "messages": [{"role": "system", "content": "You are a support assistant."},
                                       {"role": "user", "content": "Where is my order?"}]}
response = client.chat.completions.create(**body)

# after each call:
logger.log("openai.chat", body, response.usage, finish=response.choices[0].finish_reason)

log() accepts the SDK's usage object as it comes (OpenAI and Anthropic pydantic models, google-genai usage_metadata) or a plain dict. It returns the record's index in the file, the value to pass as retry_of= when you retry that call; set parse_failed=True when your parser rejects an answer. It never raises into your request path: if anything goes wrong, nothing is written and it returns None.

The provider argument decides which cache facts score the call: name where the request is served (openai, anthropic, gemini, openrouter, deepinfra, or vllm, sglang, lm-warden for a self-hosted server), not the SDK that sends it.

What is written, and what is not

Each line holds: a timestamp, the provider and model names, the request dialect, kvsig ids (keyed hashes of the conversation, the system prompt and tools, and each prefix), cumulative character counts, the cache breakpoint positions, a keyed hash of the sampling parameters, the token counts (prompt, cached, cache write, output), the finish reason and the retry and parse flags.

It never writes prompt text, completion text, tool arguments or the key. The ids are keyed, so without the key they cannot be matched against a guessed prompt. It makes no network calls.

More

Apache-2.0.

Metadata

Release files for leanprompt-cli 0.1.0.dev9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for leanprompt-cli 0.1.0.dev9
File Size Uploaded Provenance Actions
leanprompt_cli-0.1.0.dev9.tar.gz 12.2 kB Without provenance Details for leanprompt_cli-0.1.0.dev9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for leanprompt-cli 0.1.0.dev9
File Interpreter ABI Platform Actions
leanprompt_cli-0.1.0.dev9-py3-none-any.whl Python 3 none any Details for leanprompt_cli-0.1.0.dev9-py3-none-any.whl

Total release size: 22.6 kB

Release files / leanprompt_cli-0.1.0.dev9.tar.gz

Download URL leanprompt_cli-0.1.0.dev9.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d99290f8ebc595870ba24e17e4bd26278b6a5f9bb4cd51587989f8ee1878f54e
BLAKE2b-256 checksum
How to use checksums
1f9a2a0bc25d340ce5b6f930420d23b8b07780858601ff3570bf5dbd9fa2c243
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Release files / leanprompt_cli-0.1.0.dev9-py3-none-any.whl

Download URL leanprompt_cli-0.1.0.dev9-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29455376e601f88f5c5e37d36177976a1c6bb8f9b21a81d54aff8a0ea509cd95
BLAKE2b-256 checksum
How to use checksums
007c74ddf88a01c6456159cb999537e29341a3925f9dc56cb9df555b45f0b3fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.12

Security for leanprompt-cli 0.1.0.dev9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page