Skip to main content

Export a repository into LLM-friendly Markdown or JSONL.

Project description

Flatten Repo

Export a repository into LLM-friendly Markdown (.md) or chunked JSONL (.jsonl).

What It Does

flatten-repo scans a project, applies include/exclude filters, and generates:

  • md: a human-readable project export (tree + per-file blocks)
  • jsonl: chunked records for ingestion pipelines (RAG, indexing, search)

It prefers git ls-files to respect Git tracking, with filesystem fallback when needed.

Installation

From PyPI:

pip install flatten-repo

From source (editable):

pip install -e ".[dev]"

CLI Usage

flatten-repo --help
flatten-repo --version
flatten-repo sync-pyproject-deps --help

Common examples

Export source-focused markdown:

flatten-repo --repo . --output repo_export.md

Export full repository to JSONL:

flatten-repo --repo . --all --format jsonl --output corpus.jsonl

Include tests and add custom filters:

flatten-repo \
  --repo . \
  --output out.md \
  --include-tests \
  --include-glob "src/**/*.py" \
  --exclude-glob "**/*.png"

Export Python files without docstrings:

flatten-repo --repo . --output out.md --strip-docstrings

Synchronize static dependencies into pyproject.toml from requirements*.txt:

flatten-repo sync-pyproject-deps --root .

Use minimum pins (>=) instead of exact pins (==) and compact TOML output:

flatten-repo sync-pyproject-deps --no-compile-in --pin-strategy minimum --compact-toml

Enable stricter validation and backup before overwrite:

flatten-repo sync-pyproject-deps --no-compile-in --validate-pep508 --fail-on-unpinned --backup

Disable fallback reconstruction from pyproject.toml when requirements* are missing:

flatten-repo sync-pyproject-deps --no-compile-in --no-reconstruct

sync-pyproject-deps behavior notes:

  • If requirements*.in are missing but requirements*.txt are present, it uses .txt as compile fallback inputs.
  • If compile inputs are still incomplete, compile is skipped and it attempts reconstruction from pyproject.toml (unless --no-reconstruct is used).
  • requirements-dev.txt include directives like -r requirements.txt are ignored when parsing compiled files.

Project Layout

src/flatten_repo/
  cli.py                  # CLI argument parsing and orchestration
  settings.py             # Runtime settings model
  logging.py              # Structlog setup
  config.py               # Shared enums/constants/models
  file_manipulation.py    # Filesystem/git/filter/content processing
  output_construction.py  # Markdown/JSONL rendering and chunking

tests/
  unit/
  integration/
  end2end/

Development & Quality

Run checks from the local virtualenv:

./.venv/bin/ruff check .
./.venv/bin/ruff format --check .
./.venv/bin/ty check src/ tests/
./.venv/bin/pytest
./.venv/bin/pytest -m integration
./.venv/bin/pytest -m end2end

Pre-commit hooks are configured in .pre-commit-config.yaml.

Scope & Filtering Notes

  • Default scope: src/ + key files (pyproject.toml, requirements, pre-commit config, etc.).
  • --src-only: strict src/ scope (excludes key files).
  • --tests-only: restricts export to tests/ (+ key files unless --no-key-first).
  • --max-bytes: files larger than this threshold are truncated to head/tail excerpts.
  • --drop: supports presets api, ci, data, docker, docs, documentation, front, README, tests.
  • --strip-docstrings: removes Python module/class/function docstrings from exported content.

Markdown Output Notes

  • The file tree is rendered under a ## Structure section.
  • File section titles contain only the relative path (no size/SHA by default).

Quality Gates

  • Coverage gate is configured in pyproject.toml (fail_under = 30).
  • Unit tests remain the default pytest selection via marker configuration.

Publish To PyPI

Release checklist:

# 1) Update version in pyproject.toml + src/flatten_repo/__init__.py
./.venv/bin/ruff check .
./.venv/bin/pytest

# 2) Build artifacts
./.venv/bin/python -m build

# 3) Validate metadata and long description
./.venv/bin/python -m twine check dist/*

Dry-run on TestPyPI first:

./.venv/bin/python -m twine upload --repository testpypi dist/*
python -m pip install --index-url https://test.pypi.org/simple/ flatten-repo

Publish production release:

./.venv/bin/python -m twine upload dist/*

See RELEASING.md for full release process and options (API token or Trusted Publishing via GitHub Actions).

License

MIT (see LICENSE).

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

flatten_repo-0.3.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

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

flatten_repo-0.3.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file flatten_repo-0.3.0.tar.gz.

File metadata

  • Download URL: flatten_repo-0.3.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for flatten_repo-0.3.0.tar.gz
Algorithm Hash digest
SHA256 29683c94b4f095370ccded62f891f762d5c767990314d63a5b6aa0f22af7ff69
MD5 93fbc45549c3ef517fd2e1e6307e5fc2
BLAKE2b-256 03b7cda3e18f236e4324f7da045ace25847e0f15537ec13024165306d0feae24

See more details on using hashes here.

File details

Details for the file flatten_repo-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: flatten_repo-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for flatten_repo-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6a18be0fdbc16fdffe2d20110c9c016866f048a129a95eb2e335062df1f6abf
MD5 936902d309e342b235d792b106d57cb8
BLAKE2b-256 a59f3707401809213833873312f0a4de3f1dccfd91568e78aa095c1a580ed080

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