Catalog PyPI
PACKAGE EXPLORERView in registry

ahs-compressor

PyPI

A tool to compress Python code into an Abstract Hierarchical Structure (AHS) to optimize interaction with LLMs.

Versions collected1
Direct dependencies3From release 2.0.3
Last observed21 Oct, 09:43 UTC

README

Version 2.0.3 documentation

AHS-Compressor v2.0

A tool to compress Python code into an Abstract Hierarchical Structure (AHS), designed to optimize code analysis and interaction for Large Language Models (LLMs).

Python Version License: MIT


What problem does it solve?

LLMs have a limited context window. Analyzing or modifying large code repositories is inefficient and often impossible, as the full source code doesn't fit into the model's prompt.

AHS-Compressor addresses this problem through "context compression." It doesn't reduce the file size but transforms the code into a high-level structure (the AHS) and a corresponding code map. This allows an LLM to:

  1. See the project's "architecture" (the AHS structure) without needing to see every line of code.
  2. Navigate the code intelligently, requesting only the specific snippets it needs from the code map.
  3. Modify code safely, as reconstructing the code from the AHS and map preserves 100% of the original formatting, including comments (thanks to libCST).

Key Features

  • Format Preservation: Thanks to libCST, all comments, whitespace, and code structure are kept intact.
  • JSON Structure: The AHS format is now a structured JSON, making it easy to parse and extend.
  • Project-Level Support: The CLI can process entire directories, generating a single AHS for the whole project.
  • API and CLI: Offers both a command-line interface (ahs-cli) for local use and a web API (FastAPI) for integrations.
  • Packaged: Ready to be installed as a Python package via pip.

❤️ Support This Project

AHS-Compressor is a free and open-source project that requires significant time and effort to maintain and improve. If you find this tool useful, please consider supporting its development. Your sponsorship helps me dedicate more time to building new features, writing documentation, and providing support to the community.

You can become a sponsor through GitHub Sponsors. Every contribution is greatly appreciated!

Sponsor me on GitHub

Installation

To install the tool and its dependencies, you can use pip directly from the repository (once uploaded) or from your local copy.

# Install in editable mode from the local directory
cd /path/to/py-ahs-lmstudio
pip install -e .

This will install all dependencies and make the ahs-cli command available in your system.

How to Use

Command-Line Interface (CLI)

The CLI is the primary way to interact with the tool to compress and decompress projects.

1. Encode an entire project:

# Encodes the 'my_project' directory and saves the output to 'compressed_project.json'
ahs-cli encode ./my_project -o compressed_project.json

2. Decode a project:

# Reads 'compressed_project.json' and restores the code in the 'my_project_restored' directory
ahs-cli decode compressed_project.json -o ./my_project_restored

Web API

The application also includes a FastAPI for integrations.

To start the server:

# Make sure you have uvicorn installed (it's in the dependencies)
uvicorn app.main:app --reload

The server will be available at http://localhost:8000.

Main Endpoints:

  • POST /compress-text: Compresses a code snippet sent in the request body.
  • POST /decompress-text: Decompresses an AHS and map sent in the request body.
  • GET /health: A status endpoint to check if the API is running.

Development

To contribute to the project, clone the repository, install the dependencies in editable mode as shown above, and start making changes.

Next Steps

  • Implement project-level compression in the API using background tasks.
  • Publish the package to PyPI.
  • Add support for more languages (e.g., JavaScript, Java) using dedicated parsers.
  • Create a Python client to interact with the API more easily.

Downloads & popularity

1downloads
1-day window · source-reported counts20 Oct 2026
94.50
2026-07-23: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-07-23–2026-07-232026-07-26: 3 · observed 2026-10-21T12:37:17.8059096Z · period 2026-07-26–2026-07-262026-07-27: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-07-27–2026-07-272026-07-31: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-07-31–2026-07-312026-08-02: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-02–2026-08-022026-08-04: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-04–2026-08-042026-08-08: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-08–2026-08-082026-08-09: 4 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-09–2026-08-092026-08-14: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-14–2026-08-142026-08-15: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-15–2026-08-152026-08-17: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-17–2026-08-172026-08-21: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-21–2026-08-212026-08-23: 3 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-23–2026-08-232026-08-24: 8 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-24–2026-08-242026-08-25: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-25–2026-08-252026-08-28: 4 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-28–2026-08-282026-08-31: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-08-31–2026-08-312026-09-01: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-01–2026-09-012026-09-02: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-02–2026-09-022026-09-06: 6 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-06–2026-09-062026-09-07: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-07–2026-09-072026-09-08: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-08–2026-09-082026-09-15: 6 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-15–2026-09-152026-09-19: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-19–2026-09-192026-09-21: 9 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-21–2026-09-212026-09-26: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-26–2026-09-262026-09-27: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-27–2026-09-272026-09-28: 2 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-28–2026-09-282026-09-30: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-09-30–2026-09-302026-10-02: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-02–2026-10-022026-10-03: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-03–2026-10-032026-10-06: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-06–2026-10-062026-10-07: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-07–2026-10-072026-10-08: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-08–2026-10-082026-10-09: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-09–2026-10-092026-10-12: 8 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-12–2026-10-122026-10-13: 9 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-13–2026-10-132026-10-14: 4 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-14–2026-10-142026-10-18: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-18–2026-10-182026-10-20: 1 · observed 2026-10-21T12:37:17.8059096Z · period 2026-10-20–2026-10-20
23 Jul20 Oct

pypistats · 40 observations shown. Missing days are unknown. Source category: overall: without mirrors.

View observed values
Date / source periodValueObserved at
2026-10-20 – 2026-10-2012026-10-21T12:37:17.8059096Z
2026-10-18 – 2026-10-1812026-10-21T12:37:17.8059096Z
2026-10-14 – 2026-10-1442026-10-21T12:37:17.8059096Z
2026-10-13 – 2026-10-1392026-10-21T12:37:17.8059096Z
2026-10-12 – 2026-10-1282026-10-21T12:37:17.8059096Z
2026-10-09 – 2026-10-0912026-10-21T12:37:17.8059096Z
2026-10-08 – 2026-10-0812026-10-21T12:37:17.8059096Z
2026-10-07 – 2026-10-0712026-10-21T12:37:17.8059096Z
2026-10-06 – 2026-10-0612026-10-21T12:37:17.8059096Z
2026-10-03 – 2026-10-0312026-10-21T12:37:17.8059096Z
2026-10-02 – 2026-10-0212026-10-21T12:37:17.8059096Z
2026-09-30 – 2026-09-3012026-10-21T12:37:17.8059096Z
2026-09-28 – 2026-09-2822026-10-21T12:37:17.8059096Z
2026-09-27 – 2026-09-2712026-10-21T12:37:17.8059096Z
2026-09-26 – 2026-09-2612026-10-21T12:37:17.8059096Z
2026-09-21 – 2026-09-2192026-10-21T12:37:17.8059096Z
2026-09-19 – 2026-09-1922026-10-21T12:37:17.8059096Z
2026-09-15 – 2026-09-1562026-10-21T12:37:17.8059096Z
2026-09-08 – 2026-09-0812026-10-21T12:37:17.8059096Z
2026-09-07 – 2026-09-0722026-10-21T12:37:17.8059096Z
2026-09-06 – 2026-09-0662026-10-21T12:37:17.8059096Z
2026-09-02 – 2026-09-0212026-10-21T12:37:17.8059096Z
2026-09-01 – 2026-09-0112026-10-21T12:37:17.8059096Z
2026-08-31 – 2026-08-3112026-10-21T12:37:17.8059096Z
2026-08-28 – 2026-08-2842026-10-21T12:37:17.8059096Z
2026-08-25 – 2026-08-2512026-10-21T12:37:17.8059096Z
2026-08-24 – 2026-08-2482026-10-21T12:37:17.8059096Z
2026-08-23 – 2026-08-2332026-10-21T12:37:17.8059096Z
2026-08-21 – 2026-08-2112026-10-21T12:37:17.8059096Z
2026-08-17 – 2026-08-1722026-10-21T12:37:17.8059096Z
2026-08-15 – 2026-08-1522026-10-21T12:37:17.8059096Z
2026-08-14 – 2026-08-1422026-10-21T12:37:17.8059096Z
2026-08-09 – 2026-08-0942026-10-21T12:37:17.8059096Z
2026-08-08 – 2026-08-0812026-10-21T12:37:17.8059096Z
2026-08-04 – 2026-08-0422026-10-21T12:37:17.8059096Z
2026-08-02 – 2026-08-0212026-10-21T12:37:17.8059096Z
2026-07-31 – 2026-07-3112026-10-21T12:37:17.8059096Z
2026-07-27 – 2026-07-2722026-10-21T12:37:17.8059096Z
2026-07-26 – 2026-07-2632026-10-21T12:37:17.8059096Z
2026-07-23 – 2026-07-2322026-10-21T12:37:17.8059096Z

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
2.0.320 Jul 20253

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
rcdrodrigo/ahs-compressor

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 09:43 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:2967cd14a8ede0387d38f8a27d182891a0c11362a22d07f43d2803b6d56a23c6