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

Nota: O pacote contém código Rust compilado. Wheels pré-compiladas estão disponíveis para Linux, macOS e Windows (x86_64, arm64).

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" }]
      }
    ]
  }
}

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.

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 Distribution

redux_token-0.1.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distributions

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

redux_token-0.1.0-cp313-cp313-win_amd64.whl (786.8 kB view details)

Uploaded CPython 3.13Windows x86-64

redux_token-0.1.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.1.0-cp313-cp313-macosx_11_0_arm64.whl (882.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

redux_token-0.1.0-cp312-cp312-win_amd64.whl (790.4 kB view details)

Uploaded CPython 3.12Windows x86-64

redux_token-0.1.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.1.0-cp312-cp312-macosx_11_0_arm64.whl (882.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

redux_token-0.1.0-cp311-cp311-win_amd64.whl (792.7 kB view details)

Uploaded CPython 3.11Windows x86-64

redux_token-0.1.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.1.0-cp311-cp311-macosx_11_0_arm64.whl (883.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

redux_token-0.1.0-cp310-cp310-win_amd64.whl (792.6 kB view details)

Uploaded CPython 3.10Windows x86-64

redux_token-0.1.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.1.0-cp310-cp310-macosx_11_0_arm64.whl (883.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file redux_token-0.1.0.tar.gz.

File metadata

  • Download URL: redux_token-0.1.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for redux_token-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d0f8037f74e9666a9240d20395676c89c25ff9e51de702d96f615fec81251137
MD5 f73a8c8187be646311d825e745fb9cf3
BLAKE2b-256 f42f615b2725c9f203eb23c65ba0c12367559fd98031ef1884b98b7a0888397e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redux_token-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 14fcba5202a11f39338d305277951059623f477a48019f5c7623a1cc18881c7a
MD5 bad87a2451d8630c1c4a21fba1a5909e
BLAKE2b-256 cbda3c10b847c97d1bf3ff09fa89a9b77bdeeec6027c1b206c4ebe8814445fd3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redux_token-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f920750de36be75c39799d595a2ffb171c8a4a007edbd93d598625f28a08f1f5
MD5 8cb9a9eabed3d277e469c6826aa8146f
BLAKE2b-256 4c29493cb1ad912fbaf60a0019440e38c0f2732d6b022cdfe2d0d5b86d8a0939

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 213d85a89434226653bb40706946ae9fe19799b7a83df2c7b7fef58d168b8297
MD5 90ce10fc3229c8e4d3a7a27fb57ee79e
BLAKE2b-256 81c63670067717688a3c042bd040019d77027f6be5e82cb5a1e8d8be94c04fd8

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: redux_token-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 790.4 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.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7fdbddc5e83465374d857efde3ba4067adae6e538071767cf4a40e377e51be34
MD5 d179e99da9293ef3ac0cc22abfd9d9db
BLAKE2b-256 8e99ea6aee9c7951c9e3f1901d957ef31420c3e3e21664653164282cc80d2db2

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redux_token-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47761e441424a36f186f61293bbc337bbff73121a7eabd9f83b1c09107d38e27
MD5 d46a7953cb00b2dd472812ef38bc8aca
BLAKE2b-256 948ab2b2041a29ed7c19481a7d6cc3c835cdb7f588bf3e7ee563a8ae9f88c642

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1e08669946b707f4b790b3505fb55a901bdb4aa8222585bd57e6e4702e9a956e
MD5 dd602fc367476333d197eb43a92fd81f
BLAKE2b-256 2590d7ad89e2caeeee55328a532c9b420b6a0533bec75f9894b085b38164576b

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: redux_token-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 792.7 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.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7e9ad67d92af62e115701e7f747a9ddf807c94d8b9080db7e581474741dfe4c9
MD5 e0779185fe4928f56b4b0f48a4f9168a
BLAKE2b-256 3401b1a718a86abb979793fe00216b90a9eb9f9e2609a2e17bd9162d4f499779

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redux_token-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b137f64cc8e355c0361262bc31162f36f4dedcee23265525f09338057fbb85bb
MD5 d0c9d09e8549e40b3a025d2c1e984bf5
BLAKE2b-256 b80aa3684785fb21bfedc01e90bf61cdbd09560bbd5726bbe33cf6a63d17582a

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8d3b4cc09a1c4bf78abf90ef7666da4aaf1cba7f0aa05ca59c9def1025a65a99
MD5 f0dc3c4807b46f4de17ff3b11ccf493f
BLAKE2b-256 9a9b61919d71c5f9c90188939601bc0d54a3178318a3469a4e6bc69fa44d6ca5

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: redux_token-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 792.6 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.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8dffe7b34b95fe837f41d306dfe274d5e3155b2b5345eafe2f268d0a57b28060
MD5 afa640026cebb1ce9901ee77f0524557
BLAKE2b-256 f4e09a63553770766f9fad9a1b2b10234529f3600d4252126229507b2273e66d

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redux_token-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9e1808d08b4699cc4a97b6b6df736049e25e3e57af7ec58202df5f2e69fa34b9
MD5 fb9c5b97d41e7fda99cf2cd304077d67
BLAKE2b-256 aca11ccaceedf246ec64e6b7e328e1247a865819acdf2d53a28c16f554896d74

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for redux_token-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 185dbe4b4b8b2da4e9764cf7ac34bad9e458520965da15eca52251fcd1763d0c
MD5 9c31bbdc666c34a556a758711fe3260a
BLAKE2b-256 6e7b63be50622f136fd67bc10cb083bbacb65b21159af1ad359f8b90882a29fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for redux_token-0.1.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