Skip to main content

Render a repo into one LLM-ready text file

Project description

Pytoma — Repo text rendering

Pytoma condenses your python repo into one concise, LLM-friendly, text file. You choose what to show (full code, signature + docstring, partial bodies ...) per function, class, file, or folder.

You can configure what will be shown via a small YAML config or CLI options, and the output is a single text file divided in fenced code blocks, ideal for prompting an LLM or sharing a focused snapshot with collaborators. You can also use it to hide sensitive code snippets to protect your innovative ideas.

Note from the author : I originally vibe-coded a basic tool for myself because ChatGPT wouldn't accept more than 10 files and the files-to-prompts lib didn't allow me to hide certain sections ... but it turned out to be very handy and useful, so I refined it and it became this project.


Highlights

  • Policy-driven slicing: full, sig, sig+doc, body:levels=k, hide to omit sections, file:no-imports to omit imports

  • Targets:

    • by qualname (e.g. pkg.mod:Class.method or pkg.mod:*),
    • by path glob (e.g. **/repo/pkg/**/*.py),
    • or via a global default.
  • Multiple engines:

    • Python (.py): granular per function/method/class.
    • Markdown (.md): per heading or whole document (supports full/hide).
    • YAML will soon be added
    • A description or short extract of heavy files, ML artifacts, etc., is also to be expected

Installation

# For now, in a freshly cloned version of pytoma : 
pip install -e .
# There will be a more official release soon

Requires Python ≥ 3.9 (uses ast.unparse) and the following deps: libcst, pyyaml.


Quick Start (CLI)

# Basic: pack a repo with defaults (same behaviour as files-to-prompt)
pytoma ./path/to/repo > PACK.txt

# Now we use a YAML config to customize the render (skip sections, etc.)
pytoma ./repo --config config.yml --out PACK.txt

The pack looks like:

### pkg/module.py

```python
def foo(a: int, b: int) -> int:
    """Adds two numbers."""
    # … lines 12–37 body omitted (26 lines) …
```

### docs/guide.md

<!-- … lines 1–120 document omitted (120 lines) … -->

Configuration (YAML)

# config.yml
default: full        # fallback policy

# optional: exclude patterns (relative to the provided roots)
excludes:
  - ".venv/**"
  - "**/__pycache__/**"
  - "dist/**"
  - "build/**"
  - "site-packages/**"
  - "**/*.pyi"

rules:
  # Apply a file-level filter first (removes top-level imports, keeps __future__)
  - match: "/abs/path/to/repo/pkg/**/*.py"
    mode: "file:no-imports"

  # Then apply function-level policy to the same files
  - match: "/abs/path/to/repo/pkg/**/*.py"
    mode: "sig+doc"

  # Hide an entire module (replaced by an omission marker)
  - match: "/abs/path/to/repo/legacy/big_module.py"
    mode: "hide"

  # Target all defs in a given module by qualname
  - match: "pkg.special:*"
    mode: "body:levels=1"

  # Markdown supports only "full" and "hide"
  - match: "/abs/path/to/repo/README.md"
    mode: "hide"

Note : when Pytoma walks each document’s nodes, it decides a policy with this order: qualname rules > path rules > global default.


Policies

  • full — leave the node as is.

  • hide — remove and insert an omission marker:

    • On a module: replaces the whole file content.
    • On a class: replaces the whole class block.
    • On a function/method: replaces the definition or its body depending on engine mode.
  • sig — one-line header (def …:), body omitted with a marker.

  • sig+doc — header + docstring (or """…""" placeholder), body omitted.

  • body:levels=k — keep code with indentation ≤ base + 4*k, collapse deeper blocks with markers.

  • file:no-imports — strip top-level import/from … import … except from __future__ import ….

Markers are comment-style lines (or a light box) with line counts, e.g.:

# … lines 42–97 body omitted (56 lines) …

Applying a policy to a whole file or folder

Three options:

  1. Global default
pytoma /abs/repo --default "sig+doc"
  1. Path glob rule (absolute POSIX)
rules:
  - match: "/abs/repo/pkg/**/*.py"
    mode: "sig+doc"
  1. Qualname wildcard for a module
rules:
  - match: "pkg.module:*"
    mode: "sig+doc"

For file-level effects like removing imports or hiding an entire file, use file:no-imports or hide on the path glob; these apply to the module root.


Excludes

By default, Pytoma skips:

.venv/**, **/__pycache__/**, dist/**, build/**, site-packages/**, **/*.pyi

You can override in config.yml → excludes.


Pitfalls

  • Rule order can still be tricky when several rules are about the same file. I'm looking forward to improving that soon. For the moment, prefer being as explicit as possible, and for tricky setups, you can simply ask an LLM to draft the rules for you (from your repo tree and goals).
  • To name a markdown section in the config file, you still need to give the slugified version of the section

Roadmap

  • Engine for YAML / JSON (keys/tables granularity), CSV (short preview like pandas does), etc.
  • Better summary of skipped lines (for instance, when skipping imports, in the examples of skipped imports, we should probably prioritize unexpected imports over classic ones such as sys, os ...)
  • Propose the automatic addition of inferred rules: in particular, functions that are only called by hidden functions should probably be hidden by default.
  • More markers + Let the user choose their markers, rule by rule, using the configuration
  • A “custom:alternative_version” rule to simply replace a block with an alternative version of the block provided by the user.
  • Heuristics to suggest rules (and possibility to condition it by a section which we want to focus on) -> may actually become another independent tool ...
  • ... and even smarter module targeting via dependency graphs , embeddings, git edit correlations, etc.

Current engines & support matrix

Engine / Mode full hide sig sig+doc body:levels=k file:no-imports
Python (.py)
Markdown (.md)

Planned: YAML/TOML section policies (toml already started)


How it works (short)

  • Each engine parses a file into a lightweight IR:

    • Document with a flat list of Nodes (module, class, function, etc.).
  • A decision step maps nodes to Actions (full, sig+doc, …) using the precedence above.

  • Engines render actions into concrete Edits (byte spans + replacements).

  • Edits are merged.

  • The final pack concatenates per-file sections with language fences.


License

MIT

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

pytoma-0.1.0a1.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

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

pytoma-0.1.0a1-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file pytoma-0.1.0a1.tar.gz.

File metadata

  • Download URL: pytoma-0.1.0a1.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pytoma-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 5dbcdbc5c19d91bc519defd592c966613981b81254aeddbd7210b21fef2d7008
MD5 0e1d46cd9ef841b042c95cb78aeb0252
BLAKE2b-256 4a660f63cbad31681bf03a4d84c887d98009472a05b09b41745102aa2321d347

See more details on using hashes here.

File details

Details for the file pytoma-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: pytoma-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for pytoma-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 e024993cd7b7a2acbfd6369741dea0d8a56fc06f262815760e2d2f76b0bcbb4b
MD5 482fa9d53054d0a6aec17c1e8b940ba0
BLAKE2b-256 d02a0ac36c5719f6e21952b29b4cef749bcf10588a61cadeddc74937fe4cd1a2

See more details on using hashes here.

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