Metadata-Version: 2.4
Name: c2md
Version: 1.1.1
Summary: Tool to convert Context7 formatted llms.txt to locally organized markdown library documentation
Project-URL: Homepage, https://github.com/crisp-sh/context7-to-markdown
Project-URL: Bug Reports, https://github.com/crisp-sh/context7-to-markdown/issues
Project-URL: Source, https://github.com/crisp-sh/context7-to-markdown
Author-email: crisp-sh <s@crisp.sh>
License: MIT
License-File: LICENSE
Keywords: cli,context7,converter,documentation,markdown
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Documentation
Classifier: Topic :: Software Development :: Documentation
Classifier: Topic :: Text Processing :: Markup :: Markdown
Requires-Python: >=3.8
Requires-Dist: requests>=2.31.0
Description-Content-Type: text/markdown

# Context7 to Markdown (`c2md`)

A blazing fast tool that converts Context7 to organized markdown documentation with automatic directory structure, multi-language parsing support, and table of contents generation. Supports both local files and direct URLs from Context7.com.

Install with pip
```bash
pip install c2md
```
Install with uv
```bash
uv pip install c2md
```
*or*
```bash
uvx c2md https://context7.com/org/project
```

## Why `c2md`? 🤔

MCP servers are fairly new and are quite rudimentary. They introduce latency, increase prompt size, consume tokens on every request, and, in the case of Context7, require network calls for each library lookup. Additionally, Context7's MCP server uses natural language search that can miss relevant sections or return results you don't even need.

With `c2md`, you convert a library <ins>once</ins> per project and reference it locally. Instead of making MCP calls that cost 4,000-20,000 tokens per search, you attach the generated 000-index.md (typically costs less than Context7's `resolve-library-id` alone) directly to your agent. The agent gets complete context without network delays or token waste on repeated or bad searches.

This tool excels when dealing with large libraries like Neon, which has around 240 sections (~520,000 tokens). The locally generated index provides instant, inexpensive library context to any section while consuming ~50% fewer tokens than equivalent MCP operations. You can even pass the table of contents or specific sections from the library via a rule in your favorite AI IDE.

If that didn't sell you, `c2md`:

- **⚓ converts Context7 to local markdown**
- **🧠 logically organizes the library into sections with sequential file naming**
- **🗨️ consolidates multi-language sections into a single document**
- **📜 generates Table of contents = easy context for your agent**
- **🗺️ maps source URLs to appropriate file paths and names** 
- **🏎️ is fast as hell**

## Installation

#### Using pip

```bash
pip install c2md
```

#### Using uv

```bash
uv pip install c2md
```
*or*
```bash
uvx c2md https://context7.com/org/project
```

## Requirements

- Python 3.8 or higher
- No external dependencies required unless developing

## Usage

From local file - output defaults to `./output/`
```bash
c2md /path/to/llms.txt
```
From Context7 standard URL - output defaults to `./{project}/`
```bash
c2md https://context7.com/{org}/{project}
```
From Context7 raw URL with tokens query
```bash
c2md https://context7.com/{org}/{project}/llms.txt?tokens=173800
```

### Tips

##### 1. Not all Context7 libraries are created equal. 

Most of the time, if it's generated from a Github repository, it is not the full documentation. That being said, many repositories are solely for documentation or include a documentation app/package. For instance:

**✅ GOOD**: context7/nextjs
**❌ BAD**:  vercel/next.js

### Advanced Usage

```bash
# Specify output directory, 001-index.md (ToC) generated in output root
c2md /path/to/llms.txt -d /path/to/output

# From Context7 raw URL with output directory
c2md https://context7.com/{org}/{project}/llms.txt -d .docs/neon

# Disable ToC generation
c2md /path/to/llms.txt -nt

# Disable numbered prefixes ("001-")
c2md /path/to/llms.txt -np

# Full example with all options, no table of contents
c2md https://context7.com/llmstxt/better-auth_com-llms.txt/llms.txt?tokens=1000000 -d /path/to/output -nt -np
```

### Command Line Options

- `{input_file|input_url}`: Context7 formatted llms.txt or Context7 URL (REQUIRED)
- `-d, --directory`: Output directory. Defaults to the library name if a URL is passed. If a file is passed, defaults to "output"
- `-nt, --no-toc`: Disable table of contents generation in documentation root
- `-np, --no-prefix`: Disable "000-" prefix file naming
- `-h, --help`: Show help message and exit

## Bug Reports

If you encounter any issues, please report them on the [GitHub Issues](https://github.com/crisp-sh/context7-to-markdown/issues) page.

<details>
    <summary>
    <strong>Developing locally & contributing</strong>
    </summary>

### Contributing 🤝

Contributions are welcome! Please feel free to submit a PR if you would like to contribute or have an issue.

### Development Installation

```bash
# Clone the repository
git clone https://github.com/crisp-sh/context7-to-markdown.git
cd context7-to-markdown

# Install in development mode
pip install -e .
```

### Output Structure

The tool creates an organized directory structure:

```
output/
├── 001-index.md                    # Table of contents (if enabled)
├── domain1.com/
│   ├── section1/
│   │   ├── 001-page1.md
│   │   └── 002-page2.md
│   └── section2/
│       └── 001-page3.md
└── domain2.com/
    └── docs/
        └── 001-guide.md
```

### Context7 Format

The tool processes Context7 format files, which should contain entries with:
- **SOURCE**: URL or source identifier
- **CONTENT**: The actual content to be converted
- **TITLE**: Optional title for the content
- **LANGUAGE**: Denotes a multi-language document

### Architecture

The tool consists of several modular components:

- **Parser**: Processes Context7 format files
- **URL Mapper**: Maps source URLs to file paths
- **File Organizer**: Organizes content into directory structures
- **Markdown Writer**: Generates clean markdown files
- **Index Generator**: Creates table of contents

### Testing

Run the test suite using Hatch:

```bash
# Run tests
hatch run test

# Run tests with coverage
hatch run test-cov

# Run specific test file
hatch run test tests/test_specific.py
```

### Legacy Testing

```bash
# Install development dependencies
pip install -e ".[dev]"

# Run tests
python -m unittest discover tests

# Run tests with coverage
python -m unittest discover tests
```

### Releasing

This project uses automated versioned releases with [Hatch](https://hatch.pypa.io/) for version management.

#### Quick Release

```bash
# Create a patch release (0.1.0 → 0.1.1)
hatch run release patch

# Create a minor release (0.1.0 → 0.2.0)
hatch run release minor

# Create a major release (0.1.0 → 1.0.0)
hatch run release major
```

#### Development Setup

```bash
# Clone the repository
git clone https://github.com/crisp-sh/context7-to-markdown.git
cd context7-to-markdown

# Create a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install
pip install -e .
```

#### Running Tests

```bash
# Run all tests with Hatch
hatch run test

# Run specific test file
hatch run test tests/test_specific.py

# Run tests with coverage
hatch run test-cov
```
</details>
