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*.inare missing butrequirements*.txtare present, it uses.txtas compile fallback inputs. - If compile inputs are still incomplete, compile is skipped and it attempts reconstruction from
pyproject.toml(unless--no-reconstructis used). requirements-dev.txtinclude directives like-r requirements.txtare 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: strictsrc/scope (excludes key files).--tests-only: restricts export totests/(+ key files unless--no-key-first).--max-bytes: files larger than this threshold are truncated to head/tail excerpts.--drop: supports presetsapi, 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
## Structuresection. - 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).
Metadata
Release files for flatten-repo 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flatten_repo-0.3.0.tar.gz | 28.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flatten_repo-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 60.0 kB
Release files / flatten_repo-0.3.0.tar.gz
| Download URL | flatten_repo-0.3.0.tar.gz |
|---|---|
| Size | 28.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29683c94b4f095370ccded62f891f762d5c767990314d63a5b6aa0f22af7ff69
|
|
BLAKE2b-256 checksum How to use checksums |
03b7cda3e18f236e4324f7da045ace25847e0f15537ec13024165306d0feae24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / flatten_repo-0.3.0-py3-none-any.whl
| Download URL | flatten_repo-0.3.0-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6a18be0fdbc16fdffe2d20110c9c016866f048a129a95eb2e335062df1f6abf
|
|
BLAKE2b-256 checksum How to use checksums |
a59f3707401809213833873312f0a4de3f1dccfd91568e78aa095c1a580ed080
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|