Metadata-Version: 2.4
Name: tokzip
Version: 1.0.0
Summary: Offline text, chat, source code, and directory compression for AI prompts
Author: Islom0111
License-Expression: MIT
Project-URL: Homepage, https://github.com/Islom0111/AI-Token-Compressor
Project-URL: Repository, https://github.com/Islom0111/AI-Token-Compressor
Project-URL: Changelog, https://github.com/Islom0111/AI-Token-Compressor/blob/main/CHANGELOG.md
Keywords: llm,tokens,compression,prompt,cli,offline
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Text Processing
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: tokens
Requires-Dist: tiktoken>=0.7; extra == "tokens"
Provides-Extra: dnd
Requires-Dist: tkinterdnd2; extra == "dnd"
Provides-Extra: full
Requires-Dist: tiktoken>=0.7; extra == "full"
Requires-Dist: tkinterdnd2; extra == "full"
Dynamic: license-file

# tokzip

![Python 3.9+](https://img.shields.io/badge/Python-3.9%2B-3776AB)
![MIT License](https://img.shields.io/badge/License-MIT-64748B)
![Zero required dependencies](https://img.shields.io/badge/Required%20dependencies-0-16836E)
![v1.0.0](https://img.shields.io/badge/Version-v1.0.0-5965B4)

Clean up chats, source code, JSON, logs, or entire folders before adding them to an AI prompt. The compressor runs fully offline with Python 3.9+.

This is a finished personal tool shared as-is. It may receive occasional updates.

[Русская версия](README.ru.md)

## Quick start

Download and unpack the repository, then run these commands in a terminal from that folder.

```sh
python -m tokzip notes.md --no-clip
python -m tokzip ./project --brutal -o bundle.txt --no-clip
python -m tokzip --gui
```

On Windows, `tokzip.cmd` accepts the same arguments. Running the module, launcher, or `compress.py` without arguments opens the GUI when launched from a terminal. The GUI uses Tk if it is available in your Python installation.

For the installed `tokzip` command, run `python -m pip install .` from the unpacked folder. This uses setuptools at build time. You can use the commands above directly from source with Python alone.

## Before → after

| Input | Output in `max` |
| --- | --- |
| `## Inventory` | `Inventory` |
| `**Ready**    to process.` | `Ready to process.` |

| Mode | What it changes |
| --- | --- |
| `high` | Tidies whitespace, keeps comments and formatting, and looks for clear dictionary savings. |
| `max` | Default. Removes Markdown emphasis, comments in recognized code, and Python docstrings. Packs repeated lines and finds more dictionary candidates. |
| `brutal` | Also removes emoji from prose and chat timestamps. Packs directory trees and repeated document blocks. |

Chat code fences keep their line breaks and indentation. JSON compaction keeps string contents and number spellings. Code cleanup outside Python uses language-specific patterns and preserves recognized multiline literals.

## CLI and local expansion

```sh
python -m tokzip --stdin --stdout < input.txt
python -m tokzip - --stdout --lang ru < input.txt
python -m tokzip notes.md --dry-run
python -m tokzip --expand bundle.txt --stdout
```

In PowerShell, use `Get-Content -Raw input.txt | python -m tokzip --stdin --stdout` to pipe a file.

`--stdout` sends just the result to stdout and reports statistics on stderr. `--dry-run` reports statistics without writing files or using the clipboard. File output copies the file to the clipboard when the OS supports it. Use `--no-clip` to skip copying or `--clip-text` to copy the text. Run `python -m tokzip --help` for all flags.

`--expand` (also `--decompress`) expands v1.0 output into the cleaned text. It restores dictionary phrases, line and block repeats, shared blocks, and compact trees. Cleanup itself can discard comments, formatting, chat timestamps, and other content. Use the original files when you need their exact contents.

Directory scans skip sensitive names such as `.env`, private keys, and credential JSON files. They also skip symbolic links and known binary files. To add project-specific filters, put a UTF-8 `.compressignore` in the scanned directory. Use one case-sensitive glob per line, such as `*.log`, `drafts/**/private-*.md`, or `generated/` for directories. Blank lines and lines beginning with `#` are ignored. `--include-secrets` overrides the built-in sensitive-name filter. Explicitly selected files are read directly. Review a bundle before sharing it.

Saved results go to `./compressed_files/` in your working directory unless you pass `-o`. The OS determines the user log directory.

| OS | Log folder |
| --- | --- |
| Windows | `%LOCALAPPDATA%\tokzip\logs` |
| macOS | `~/Library/Logs/tokzip/` |
| Linux | `~/.local/state/tokzip/logs/` or `$XDG_STATE_HOME/tokzip/logs/` |

## Optional features

Install `".[tokens]"` to use exact `o200k_base` token counts, `".[dnd]"` for drag-and-drop in Tk, or `".[full]"` for both, using `python -m pip install` followed by the extra. For exact counts, run this command once while connected to populate the local tokenizer cache.

```sh
python -c "import tiktoken; tiktoken.get_encoding('o200k_base')"
```

The compressor reads only the local vocabulary cache. When the tokenizer or its cache is unavailable, it reports estimated counts.

## Measured examples

Measured on Python 3.14.3 by running the CLI on synthetic UTF-8 files. The samples were a 40-line maintenance log, 28 Python functions with comments and docstrings, and four copies of the same Unicode directory tree. Byte counts below are from the exact-token runs.

| Sample | Mode | UTF-8 bytes | `o200k_base` tokens | Stdlib estimate |
| --- | --- | ---: | ---: | ---: |
| Repeated log | `high` | 4,079 → 945 | 599 → 301 | 999 → 273 |
| Commented Python | `max` | 4,720 → 1,017 | 896 → 297 | 1,538 → 468 |
| Repeated directory tree | `brutal` | 5,367 → 814 | 1,903 → 342 | 1,931 → 385 |

## Previews

![GUI showing a compressed maintenance log](docs/gui_preview.png)

![CLI dry run on the same sample](docs/cli_preview.png)

Run the local test suite with `python -m unittest discover`.

[Changelog](CHANGELOG.md) · [Pre-Git history](docs/pre-git-history.md) · [MIT license](LICENSE)
