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.dev8

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.dev8
File Size Uploaded Provenance Actions
leanprompt_cli-0.1.0.dev8.tar.gz 12.2 kB Without provenance Details for leanprompt_cli-0.1.0.dev8.tar.gz

Built distribution (wheel)

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

Total release size: 22.6 kB

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

Download URL leanprompt_cli-0.1.0.dev8.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ee6026bc743b9e414f4bbaaef64b025d6693985bb0bbacb49daf77037ea68509
BLAKE2b-256 checksum
How to use checksums
6c6bcdd19e57cadbf21146c268523b192168d0cd1be43c70205e35b257b02bfd
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.dev8-py3-none-any.whl

Download URL leanprompt_cli-0.1.0.dev8-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e13e5cf82c30e6ec9b2b9ca3705357d924987698f8104a4460071fb8ee7a5828
BLAKE2b-256 checksum
How to use checksums
d537cbcb353a40506320fb0921df86ea47960d1566cf0742de18f78a23f7e7f3
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.dev8

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