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 with deterministic transformations. It detects input formats, tries ordered strategies, and keeps candidates that reduce tokens or shorten text at equal token count.

Features

  • Detect JSON, YAML, XML, TOML, CSV, Markdown and plain text.
  • Compact inputs with ordered strategies and configurable presets.
  • Analyze independent strategy savings without replacing the input text.
  • Count tokens and report the counter backend through Python and AXM tools.

Installation

Requires Python 3.12+. In a uv project:

uv add axm-smelt

Quick Start

After installation, run this example with uv run python:

import json
from axm_smelt import check, count, smelt

data = '{\n  "name": "Alice",\n  "age": 30\n}'
report = smelt(data)
assert json.loads(report.compacted) == json.loads(data)
print(report.compacted, report.savings_pct)

analysis = check(data)
print(analysis.strategy_estimates)  # Independent estimates; do not add them
assert analysis.savings_pct == report.savings_pct
print(count("hello world"))

This prints compacted JSON, savings, independent strategy estimates and a count for hello world. The assertions verify this example's JSON values and the agreement between the default pipeline and its analysis.

The Python surface also exports SmeltReport, Format, CounterBackend and __version__. Compaction returns new text; it does not overwrite a file.

Usage

AXM tools and CLI

Three axm.tools registrations supply CLI, MCP and DAG access:

Command Result
axm smelt Compacted text and pipeline metrics
axm smelt_check Input format/count and isolated strategy estimates
axm smelt_count Token count with a requested model/encoding
printf '{"name": "Alice", "notes": null}\n' | uv run axm smelt --json-output
uv run axm smelt --data '{"a": 1, "b": null}' --strategies '["minify", "drop_nulls"]'
uv run axm smelt_count --data 'hello world' --model o200k_base

Use --input-path ./payload.json to read a UTF-8 file. Nonempty data takes precedence over the file, then non-interactive stdin. JSON-looking --data is decoded by the CLI; use a file/stdin to preserve its original whitespace baseline. Plain stdout includes a header; --json-output prints the data mapping. See CLI reference for errors and encoding.

For MCP, install the package into the server environment and call axm_call(name="smelt", arguments={...}) in façade mode. Integration guide.

Strategies and fidelity

Preset Intent
safe (default) minify and collapse_whitespace
moderate Also drop empties, flatten, alias repeated strings, tabularize, remove quotes/comments
aggressive Also round floats; order differs from moderate

The name safe is not a general losslessness guarantee. XML significant whitespace, YAML inline comments and Markdown layout can change. Structural transforms can lose values/types and produce output that is not valid JSON. Inspect strategy behavior and limits before choosing a preset. More strategies do not guarantee greater savings.

Detected formats: JSON, YAML, XML, TOML, CSV, Markdown and text. TOML/CSV have no dedicated compactor. Counts use tiktoken; Claude and unknown model names use an o200k_base proxy, not the target model's exact tokenizer or billing. The smelt/check pipelines always use o200k_base.

Documentation

The MkDocs home page is docs/index.md; it is separate from this README.

Development

This package belongs to the axm-forge workspace.

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

License

Licensed under Apache-2.0. See LICENSE.

Metadata

Release files for axm-smelt 0.3.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 axm-smelt 0.3.1
File Size Uploaded
axm_smelt-0.3.1.tar.gz 74.4 kB Details

Built distribution (wheel)

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

Total release size: 113.3 kB

Release files / axm_smelt-0.3.1.tar.gz

Download URL axm_smelt-0.3.1.tar.gz
Size 74.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d17f006888f3cb0fd2f8008cd5d7db544a72b1766620bab901be112913c18055
BLAKE2b-256 checksum
How to use checksums
5a7e8cd67cec178e26e8661bfa58015a4273bf68d39abe661f458d3aca0f4a07
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 Oct 15, 2026.

Transparency log

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

Download URL axm_smelt-0.3.1-py3-none-any.whl
Size 38.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05e39754dc7443840041e4023a01e172ff0ef9c62b2ac77bd94346c61f1f9e00
BLAKE2b-256 checksum
How to use checksums
08e23c51ef006654c6d20aaabc5b154b83a61368f0a5828f3b1cd7fc78c073b0
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 Oct 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

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