Skip to main content

mdmin

Markdown compression + context extraction for LLM consumption. Reduces token usage by 20–95%.

Website: mdmin.dev • npm: npmjs.com/package/mdmin

Install

pip install mdmin

Zero dependencies. Python 3.9+.

Compress

Strip verbose phrases, redundant formatting, and structural waste. 13–35% token savings.

from mdmin import compress, estimate_tokens

result = compress(text, level="medium")
print(result.output)       # compressed text
print(result.stats.pct)    # e.g. 22.3 (%)
print(result.stats.saved)  # tokens saved
mdmin compress README.md                    # stdout
mdmin compress README.md -o README.min.md   # save to file
mdmin compress README.md --level aggressive
mdmin stats README.md                       # compare all levels
cat file.md | mdmin compress -              # stdin

Extract

Given a large document and a query, returns only the relevant chunks within a token budget. TF-IDF based — no external API, no vector database, runs in milliseconds. 70–95% reduction on targeted queries.

from mdmin import extract

result = extract(large_doc, "how does auth work", max_tokens=2000)
print(result.text)               # relevant chunks only
print(result.stats.reduction)    # e.g. 91.2 (%)
print(result.stats.chunks_extracted)  # e.g. 2 of 24 chunks
mdmin extract bigdoc.md -q "how does auth work"
mdmin extract bigdoc.md -q "database schema" --max 1500

For advanced use:

from mdmin import ContextExtractor

extractor = ContextExtractor()
extractor.index(large_doc)
result = extractor.extract("auth flow", max_tokens=2000)

# Multi-doc: score chunks globally across files
scored = extractor.score_chunks("auth flow")

Compression Levels

Level Savings What it does
light ~10% Whitespace, comments, basic verbose patterns
medium ~20-25% + more verbose patterns, table compression, formatting cleanup
aggressive ~25-35% + article stripping, list compression, bold removal, dictionary dedup

API Reference

compress

compress(text: str, level: str = "medium") -> CompressResult

Returns CompressResult with .output (str) and .stats (CompressionStats):

stats.input_tokens     # int
stats.output_tokens    # int
stats.saved            # int
stats.pct              # float (% saved)
stats.input_chars      # int
stats.output_chars     # int
stats.level            # str

extract

extract(text: str, query: str, *, max_tokens: int = 2000) -> ExtractResult

Returns ExtractResult with .text (str) and .stats (ExtractStats):

stats.total_doc_tokens    # int
stats.extracted_tokens    # int
stats.chunks_total        # int
stats.chunks_extracted    # int
stats.reduction           # float (% reduction)
stats.top_scores          # list[TopScore]

estimate_tokens

estimate_tokens(text: str) -> int

Fast BPE token count estimate (no external dependencies).

License

AGPL-3.0-only

Metadata

Release files for mdmin 1.1.1

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

Source distribution (sdist)

Source distribution for mdmin 1.1.1
File Size Uploaded Provenance Actions
mdmin-1.1.1.tar.gz 31.2 kB Without provenance Details for mdmin-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mdmin 1.1.1
File Interpreter ABI Platform Actions
mdmin-1.1.1-py3-none-any.whl Python 3 none any Details for mdmin-1.1.1-py3-none-any.whl

Total release size: 57.5 kB

Release files / mdmin-1.1.1.tar.gz

Download URL mdmin-1.1.1.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
66400f5eaff3909cc6b55daff7fa3a10e4c160c3c4ec649ba26414c94a422cc0
BLAKE2b-256 checksum
How to use checksums
1bc571a1dac18317416c2d128c1ab6a1308435348eb95967ef489b2f63db3d9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.8

Release files / mdmin-1.1.1-py3-none-any.whl

Download URL mdmin-1.1.1-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18d18713eec13025efbf9a7928ec1e6613954afa324f9ad26d0aa6b264b666ba
BLAKE2b-256 checksum
How to use checksums
b386c65c722e423e9dea154bb25c5f3be4708e1324a47bcb5a15ac98be2466b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.8

Security for mdmin 1.1.1

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