Skip to main content

Compressor inteligente de tokens para LLMs

Project description

ReduxToken

Compressor inteligente de tokens para LLMs. Reduz o custo e o consumo de tokens ao comprimir texto, JSON, código e logs antes de enviá-los para modelos como Claude e GPT-4.

Core de alta performance em Rust, interface acessível em Python.

Benchmark

Conteúdo Tokens antes Tokens depois Economia
Log com DEBUG/TRACE 1 166 47 96%
JSON com metadados 522 155 70%
Código com comentários 844 60 93%
Texto repetitivo 367 12 97%
Média ~90%

Instalação

pip install redux-token

Wheels disponíveis para Linux, macOS e Windows — Python 3.10, 3.11, 3.12 e 3.13.

Uso rápido

from redux_token import ReduxToken

rt = ReduxToken()
compressed, stats = rt.compress("seu texto aqui")

print(f"Tokens economizados: {stats.tokens_saved} ({stats.savings_pct:.1f}%)")

Como funciona

ReduxToken aplica filtros sequenciais ao conteúdo antes de enviá-lo ao LLM:

Entrada (texto / JSON / código / log)
  -> JsonFilter   — remove campos irrelevantes (id, uuid, timestamps, metadata)
  -> CodeFilter   — remove comentários // e /* */
  -> TextFilter   — remove linhas [DEBUG] e [TRACE]
  -> SmartFilter  — elimina separadores e linhas duplicadas
Saída (60–97% menos tokens)

CLI

# Comprimir texto ou arquivo
redux-token compress "seu texto"
redux-token compress --file input.log
cat big_output.log | redux-token compress

# Monitorar arquivo e comprimir ao salvar
redux-token watch arquivo.log

# Estimar custo
redux-token cost 10000 800 --price 0.003

# Salvar relatório de economia do proxy
redux-token report

Filtros customizados

import re
from redux_token import ReduxToken

def remove_urls(text: str) -> str:
    return re.sub(r'https?://\S+', '[url]', text)

def remove_emails(text: str) -> str:
    return re.sub(r'[\w.+-]+@[\w-]+\.\w+', '[email]', text)

rt = ReduxToken(extra_filters=[remove_urls, remove_emails])
compressed, stats = rt.compress(text)

Proxy HTTP (transparente)

Intercepta requests para OpenAI/Claude e comprime automaticamente sem alterar o código da aplicação:

# Iniciar o proxy
cargo run --release --package redux-token-proxy

# Configurar a aplicação para usar o proxy
# Antes: https://api.openai.com/v1/chat/completions
# Depois: http://localhost:8080/openai/v1/chat/completions

# Ver estatísticas acumuladas
curl http://localhost:8080/_redux/stats

Configuração em proxy.toml (criado automaticamente com valores padrão).

Hook para Claude Code

Com o projeto clonado, o hook já está ativo via .claude/settings.json. Ele comprime automaticamente outputs grandes de Bash e Read antes que entrem no contexto do modelo.

Para projetos externos, adicione ao .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "python -m redux_token.hook" }]
      }
    ]
  }
}

MCP Server (Claude Desktop, Cursor, Zed, etc.)

Qualquer cliente que suporte o protocolo MCP pode usar o ReduxToken como ferramenta.

pip install redux-token

Claude Desktop

Edite o arquivo de configuração:

  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "redux-token": {
      "command": "python",
      "args": ["-m", "redux_token.mcp"]
    }
  }
}

Cursor / Zed / outros clientes MCP

{
  "mcpServers": {
    "redux-token": {
      "command": "redux-token-mcp"
    }
  }
}

Ferramentas disponíveis

Ferramenta O que faz
compress Comprime texto — remove DEBUG, comentários, metadados JSON, duplicatas
compress_file Lê um arquivo do disco e comprime
estimate_cost Calcula economia financeira dado o volume de tokens

Instalação para desenvolvimento

Requer Rust + Python 3.10+.

git clone https://github.com/ElizioMartins/ReduxToken.git
cd ReduxToken
pip install maturin
maturin develop
python examples/basic.py

Veja ARCHITECTURE.md para decisões técnicas e ROADMAP.md para o plano de desenvolvimento.

Apoio

Se o ReduxToken te economizou tokens (e dinheiro), considere contribuir para manter o projeto:

Licença

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

redux_token-0.2.0-cp313-cp313-win_amd64.whl (790.8 kB view details)

Uploaded CPython 3.13Windows x86-64

redux_token-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

redux_token-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (882.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

redux_token-0.2.0-cp312-cp312-win_amd64.whl (790.9 kB view details)

Uploaded CPython 3.12Windows x86-64

redux_token-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

redux_token-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (882.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

redux_token-0.2.0-cp311-cp311-win_amd64.whl (793.2 kB view details)

Uploaded CPython 3.11Windows x86-64

redux_token-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

redux_token-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (883.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

redux_token-0.2.0-cp310-cp310-win_amd64.whl (793.1 kB view details)

Uploaded CPython 3.10Windows x86-64

redux_token-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

redux_token-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (883.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file redux_token-0.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: redux_token-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 790.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for redux_token-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9c4931450dd68ab060966feeb7d7817f9d321ac1a7aa296754ae5f0915e9e01e
MD5 9b5e4da921bed3ec5c077fdd98dfbaab
BLAKE2b-256 b805a6982c648978a46616d12d5729437ce54490a6eb40b19c6acce90bc89128

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d2a67a63325bd4fd2af3e95c28e6518c392e7f863fad2c21cdb0d0ccd8dbc435
MD5 40b9f55b26edcb8105e4ebf695732a00
BLAKE2b-256 fafcb67da6b30bb8e73f73a7d1bbfcd0b434562956cbd5c25c52d7ec80f99cba

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3bc2e586ca2abcabd73c97211a155dee34915f570960b89cffd1678b202061aa
MD5 22a0ea838f8dd79f8e8ab25fe059c06b
BLAKE2b-256 6a2349cebcc1d0b8f8910ad42e02191f15ef2b9cc738185737c3b9d8b8660c11

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: redux_token-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 790.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for redux_token-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 20903d0dc76a0425ca95d3fc79138e6de0a4dd777648296824380c0e4fab6913
MD5 58e6e7f0bc9a5ed079b2297afbac9a9f
BLAKE2b-256 330c8841de6ac10dce72bc808bc39d3ed8327907683c4f073ff72289c8e797ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 082725b9f7ea84b6ac8c12c9921f45f1416f4eab5622855d9258214b1faa1d30
MD5 43bbfba032fce8e035b6b49dfdd40f8b
BLAKE2b-256 4ed730c4948a9cfe9a571fdce6de76366a99b2803d80f97c499d062833da9805

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 740c3d926c22ee4cb1534cac4c36e8c4862bc5c41b2917eaae5545bad9f0db89
MD5 717ce5ebbc0e72d854d275040bb18a25
BLAKE2b-256 d2280731f599b8b464691f0c510688136eae8785da609e11364589044d31dae7

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: redux_token-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 793.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for redux_token-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4e2c268d9cc20f2a0338072c3caf9a65e333dfb2dc214a00bb850c8185acbe81
MD5 edd76c0ee7cebb593c538b06f4d72a99
BLAKE2b-256 dfeea31f33ee4aba2723aeac181dbc11767cde5a47f7eaf36009429a9485eba2

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a453d71bd9037fe6ccbad96a9b28611b06932ef2039f4fba98657c305a4bac8d
MD5 7f3207c97631f6b87caa610528bd23c3
BLAKE2b-256 8f5c5730f00dfb0710af0f0ca34b6e3253ba3fe55cc0dc563f4d26d09cc218c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 956f5f9e515c336582f5424c290a3ad3cc0172c0879f129102d48c8f73f685fc
MD5 ce4e5a866243dce035aa08b53df08234
BLAKE2b-256 248ee48a6bec716a28be5bbcea3cd2954cb8be7396e985659702dd0f64d2b553

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: redux_token-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 793.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for redux_token-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8ef7729e6f52d0f709e6377cb674ef260c559d23b8a64bfcfb748315264ef03f
MD5 2bad9ae3241f7cbfc5b3a0a00bf22877
BLAKE2b-256 101f1655093579dda403841eb8b4b3fa4960b6dd24aacd9f366412712f7b7bfb

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp310-cp310-win_amd64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b95bbe171d367ac056cd7e85dd8550f24792bb63ed158b531a4c594b78847bc2
MD5 8c6e3fc095f854dc8ad560ed27aec7f5
BLAKE2b-256 3519f36fc829deec089682a075019a78ec4dc46b184e474dd62869da33fc30b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file redux_token-0.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b7bcfe1a6307819a934157b0f3ecb98d7491ae4b52343c08d29696634189ee30
MD5 09e4b506beb25000752bc3e52b3f3ebe
BLAKE2b-256 195febbabac9d40c1591954002a8d75d9f7c750811dc824fa34acaa77f69b6d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.2.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on ElizioMartins/ReduxToken

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page