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
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
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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flatten_repo-0.2.0.tar.gz.
File metadata
- Download URL: flatten_repo-0.2.0.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01adc3d7b10fd9a5945bf1fa358dcae665a6738a74f6a02dc10e2a2b7b36c2c5
|
|
| MD5 |
1903ed0a7ec5c0481a491a63335834be
|
|
| BLAKE2b-256 |
9c5dac8f7ac94e54cdc084cdc1101adb3609b36ce8a6b46024eded4e1524f7df
|
File details
Details for the file flatten_repo-0.2.0-py3-none-any.whl.
File metadata
- Download URL: flatten_repo-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83436fb87dc6d5dc24b22df499b1e54a0893480d1f6326f9daf63375f2f17327
|
|
| MD5 |
19905d5d7e992184d9bcc04431d7ea51
|
|
| BLAKE2b-256 |
35a13c376d4b80a76a592a55b07f65f0050cc7c436438d7732b4a275dcd57176
|