Skip to main content

Flatten GitHub Repos into Markdown for LLM-Friendly Code Exploration

Project description

Flatr

Flatten GitHub Repos into Markdown for LLM-Friendly Code Exploration



📦 Flatr WIP!

flatr is a Python library that takes any GitHub repository and creates a flat Markdown (.md) file containing the entire codebase and documentation. It is designed to make codebases easier to feed into LLMs for tasks like code explanation, summarization, and interactive documentation.


🎯 Problem Scope

Modern software projects are often spread across multiple directories and files, making it difficult for both humans and AI models to comprehend the codebase efficiently. Large Language Models (LLMs) face these challenges:

  1. Context Window Limitations – LLMs can only process a limited amount of text at a time. Hierarchical repositories with many files make it hard for models to reason about the entire project.
  2. Scattered Documentation – README files and docstrings are often separate from code, creating gaps in understanding.
  3. Navigation Complexity – Humans also spend time jumping between folders and files to understand code dependencies.

Why Markdown is Better for LLMs:

  • Flat Structure: All code and documentation are in a single file, making it easier for the model to process.
  • Preserved Hierarchy via Headers: Markdown headers (#, ##, ###) retain the logical organization of folders and files without breaking the flat flow.
  • Syntax Awareness: Fenced code blocks (```python) preserve language context, helping LLMs understand code semantics.
  • Human and Machine Readable: Markdown is easy to read for developers and can be ingested directly by AI models.

By converting a repository into a flattened Markdown, flatr ensures that the entire project is accessible in one coherent view, maximizing the usefulness of LLMs and interactive tools.


⚡ Features

  • Fetch any public GitHub repository by URL.
  • Flatten repository structure into a single Markdown file.
  • Preserve folder and file hierarchy using Markdown headers.
  • Wrap code in fenced code blocks with syntax highlighting.
  • Include README and inline documentation.
  • Optional metadata: file size, lines of code, last commit info.

🚀 Installation

pip install flatr

💻 Usage

from flatr import flatr

# Create a flat Markdown from a GitHub repo
repo_url = "https://github.com/user/example-repo"
flattener = flatr(repo_url)
flattener.generate_md("output.md")

This generates a self-contained Markdown file with all code, docs, and structure from the repo.


Example Output

# Repository: ExampleRepo

## Folder: utils

### File: helpers.py
```python
def helper_function(x):
    return x * 2

File: validators.py

def validate(input):
    return input is not None

Folder: main

File: app.py

from utils.helpers import helper_function

🔮 Future Applications

flatr can be used to build interactive applications and developer tools, including:

  • Interactive README files – Ask questions about your code or get explanations directly inside the documentation.
  • “Chat to Code” applications – Use LLMs to navigate, analyze, and reason about your codebase.
  • Fast navigation of large codebases – Quickly jump between functions, classes, and modules in a single Markdown file.
  • Knowledge base integration – Ingest repositories into RAG pipelines for semantic search and documentation.
  • Automated code analysis – Summarize, refactor, or detect issues using AI models.

🤝 Contributing

Contributions are welcome! Feel free to submit issues or pull requests for new features, bug fixes, or multi-language support.


📄 License

MIT License – see LICENSE for details.

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

flatr-1.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

flatr-1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file flatr-1.0.tar.gz.

File metadata

  • Download URL: flatr-1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for flatr-1.0.tar.gz
Algorithm Hash digest
SHA256 1afee2ebb317eb0a62120dc90dac285dbc56f78997170722292470976be6848b
MD5 67ecf941bb8738a8e299e5984a48e9af
BLAKE2b-256 424fa9f03b46370fc5ce4ec9bb56806ca63e2c77496ede11d38191eb2afb89d0

See more details on using hashes here.

File details

Details for the file flatr-1.0-py3-none-any.whl.

File metadata

  • Download URL: flatr-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for flatr-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d6a0d1031bb17ea345f0ec3eb82a30a81728f475e6df612cbaf5e7c47062541
MD5 991e38bb8bd609b5f1fb64fac3fd920f
BLAKE2b-256 09195c7084e439d4aaf656389b181bf655d5695ed76f141e86a8f16a26287e41

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