Skip to main content

AXM Logo

axm-smelt — Deterministic token compaction for LLM inputs

CI axm-audit axm-init Coverage PyPI Python 3.12+ Docs


axm-smelt reduces token consumption for LLM inputs by applying deterministic compaction strategies — whitespace collapsing, structural transforms, and optional lossy simplifications. It works through the Python API and three registered AXMTools, which provide MCP, AXM CLI, and DAG-node access from one declaration.

📖 Full documentation

Features

  • Format detection — auto-detect JSON, YAML, XML, TOML, CSV, Markdown, and plain text
  • Token counting — always via tiktoken; Claude and unknown models route to the o200k_base proxy (approximate, no network)
  • 10 strategies — minify, drop_nulls, flatten, tabular, round_numbers, strip_quotes, dedup_values_with_refs, collapse_whitespace, compact_tables, strip_html_comments
  • Composable pipeline — chain strategies explicitly or use presets (safe, moderate, aggressive)
  • AXMTools — smelt, smelt_check, and smelt_count, available through MCP, axm, and DAG nodes
  • MCP tool — SmeltTool for use by AI agents via axm-mcp
  • Modern Python — 3.12+ with strict typing

Installation

uv add axm-smelt

Quick Start

AXM CLI

The CLI surface is derived from the registered AXMTools. Each command accepts redirected text or a UTF-8 file.

Compact data with smelt:

printf '{"name": "Alice", "notes": null}\n' | axm smelt
# smelt | json | 11->9 tok (-18.18%) | minify | tiktoken
# {"name":"Alice","notes":null}
axm smelt --input-path ./payload.json

Analyze possible savings with smelt_check:

printf '{"name": "Alice", "notes": null}\n' | axm smelt_check
# smelt_check | json | 11 tok
#   drop_nulls: -54.55%
#   minify: -18.18%
#   flatten: -18.18%
#   round_numbers: -18.18%
#   strip_quotes: -18.18%
axm smelt_check --input-path ./payload.json

Count tokens with smelt_count:

printf 'alpha beta gamma delta epsilon\n' | axm smelt_count
# smelt_count | 6 tokens | 31 chars | o200k_base | tiktoken
axm smelt_count --input-path ./payload.txt

Explicit data takes precedence over --input-path, which takes precedence over non-interactive stdin. If the designated path does not exist or its contents are not valid UTF-8, the command exits with a non-zero status and a diagnostic that names that path.

There is no standalone axm-smelt executable and python -m axm_smelt is intentionally unsupported.

Python API

from axm_smelt import smelt, check, count

# Compact using the safe preset (default)
report = smelt('{\n  "name": "Alice",\n  "age": 30\n}')
print(f"{report.savings_pct:.1f}% saved")
# Tokens: 14 -> 9

# Compact with explicit strategies
report = smelt(data, strategies=["minify", "drop_nulls"])

# Compact with a preset
report = smelt(data, preset="aggressive")

# Analyze without transforming
report = check('{"data": [1, 2, 3]}')
for strat, pct in report.strategy_estimates.items():
    print(f"  {strat}: {pct:.1f}%")

# Count tokens
tokens = count("hello world")

MCP (AI Agent)

axm-smelt is available through axm-mcp. AI agents can call smelt(data, preset="moderate"), smelt_check(...), or smelt_count(...) directly.

See the MCP how-to guide for details.

AXMTool Commands

Command Description
axm smelt Compact text or structured data
axm smelt_check Analyze token waste without transforming the input
axm smelt_count Count input tokens from explicit data, a UTF-8 file, or redirected stdin

These commands come from the axm.tools registry; the same definitions power MCP and DAG nodes. Use --help for their generated CLI signatures. The removed standalone façade has no compatibility alias.

Strategies

Name Category Description
minify whitespace Compact JSON/YAML/XML whitespace (parse + re-serialize; preserves data)
drop_nulls structural Recursively remove None, "", [], {} values
flatten structural Collapse single-child wrapper dicts ({"a":{"b":1}} → {"a.b":1})
tabular structural Convert list[dict] JSON to pipe-separated tables
round_numbers cosmetic Round floats to N decimal places (default: 2)
strip_quotes cosmetic Remove quotes on simple alphanumeric JSON keys
dedup_values_with_refs structural Replace repeated long strings (≥20 chars, ≥2 occurrences) with aliases. Output is wrapped in a {_refs, _data} envelope — not format-preserving.
collapse_whitespace whitespace Collapse consecutive blank lines and strip trailing whitespace on prose/Markdown (skips structured formats and fenced code blocks)
compact_tables whitespace Remove padding whitespace from Markdown table cells (skips fenced code blocks)
strip_html_comments cosmetic Remove <!-- … --> HTML comments from Markdown/plain text (skips fenced code blocks)

Presets

Preset Strategies Use when
safe minify, collapse_whitespace Data-preserving — keeps the parsed value identical for structured formats (JSON/YAML/…) and never touches fenced code. Not byte/whitespace-lossless on prose/Markdown: collapse_whitespace collapses blank-line runs and strips trailing whitespace.
moderate minify, drop_nulls, flatten, dedup_values_with_refs, tabular, strip_quotes, collapse_whitespace, compact_tables, strip_html_comments Structural transforms are acceptable
aggressive minify, drop_nulls, flatten, tabular, round_numbers, dedup_values_with_refs, strip_quotes, collapse_whitespace, compact_tables, strip_html_comments Maximum savings, may alter float precision

Development

This package is part of the axm-forge workspace.

git clone https://github.com/axm-protocols/axm-forge.git
cd axm-forge
uv sync --all-groups
uv run --package axm-smelt --directory packages/axm-smelt pytest -x -q

License

Apache-2.0 — © 2026 axm-protocols

Metadata

Release files for axm-smelt 0.3.0

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

Source distribution (sdist)

Source distribution for axm-smelt 0.3.0
File Size Uploaded
axm_smelt-0.3.0.tar.gz 72.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for axm-smelt 0.3.0
File Interpreter ABI Platform
axm_smelt-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 112.1 kB

Release files / axm_smelt-0.3.0.tar.gz

Download URL axm_smelt-0.3.0.tar.gz
Size 72.4 kB
Tags Source
SHA-256 checksum
How to use checksums
269e7c1110b44c2aba629e24f348b2945503c03dafb1375122658a9775b8166c
BLAKE2b-256 checksum
How to use checksums
7da27dde8eed22ee7f778f3fb9fa926267551e26bb784519878ec21d028f6925
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release files / axm_smelt-0.3.0-py3-none-any.whl

Download URL axm_smelt-0.3.0-py3-none-any.whl
Size 39.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f8c88069d8c4fe2b891a9dfba2f8feb36f9a208ba67cd1d615fbfaa187ced1d
BLAKE2b-256 checksum
How to use checksums
7ad1884af4ee385a9ffe410265f83b0ecc76a73fa625e2821e39921effa9691c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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