Metadata-Version: 2.4
Name: django-llms-txt
Version: 0.1.0
Summary: Generate llms.txt files for Django websites. Make your content discoverable by AI assistants.
Author-email: Kerim Yildirim <kerim.yildirim@rapitek.com>
License: MIT
Project-URL: Homepage, https://github.com/rapitek/django-llms-txt
Project-URL: Documentation, https://github.com/rapitek/django-llms-txt#readme
Project-URL: Source, https://github.com/rapitek/django-llms-txt
Project-URL: Changelog, https://github.com/rapitek/django-llms-txt/blob/main/CHANGELOG.md
Keywords: django,llms,llms.txt,ai,seo,chatgpt,claude
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Framework :: Django :: 4.2
Classifier: Framework :: Django :: 5.0
Classifier: Framework :: Django :: 5.1
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
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: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: django>=4.2
Dynamic: license-file

# django-llms-txt

Generate [llms.txt](https://llmstxt.org/) files for your Django website. Make your content discoverable by AI assistants like ChatGPT, Claude, and Perplexity.

[![PyPI version](https://badge.fury.io/py/django-llms-txt.svg)](https://pypi.org/project/django-llms-txt/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Django versions](https://img.shields.io/pypi/djversions/django-llms-txt.svg)](https://pypi.org/project/django-llms-txt/)

## What is llms.txt?

[llms.txt](https://llmstxt.org/) is an open standard that helps Large Language Models understand your website's content. By providing a structured text file at `/llms.txt`, you make it easy for AI assistants to discover and reference your pages accurately.

## Features

- **Settings-based configuration** — define sections and links in your Django settings
- **Auto-generate from models** — automatically build sections from your Django models (blog posts, docs, products, etc.)
- **Dynamic serving** — serve `llms.txt` and `llms-full.txt` as Django views
- **Static generation** — generate static files via management command
- **Full text support** — optionally serve expanded content via `llms-full.txt`

## Installation

```bash
pip install django-llms-txt
```

Add to your `INSTALLED_APPS`:

```python
INSTALLED_APPS = [
    # ...
    "django_llms_txt",
]
```

## Quick Start

### 1. Configure in settings.py

```python
LLMS_TXT = {
    "SITE_NAME": "My Django Project",
    "SITE_URL": "https://example.com",
    "DESCRIPTION": "A brief description of your website.",
    "SECTIONS": [
        {
            "title": "Documentation",
            "links": [
                {
                    "name": "Getting Started",
                    "url": "/docs/start/",
                    "description": "Quick start guide",
                },
                {
                    "name": "API Reference",
                    "url": "/docs/api/",
                    "description": "Complete API documentation",
                },
            ],
        },
    ],
}
```

### 2. Add URL patterns

```python
# urls.py
from django_llms_txt.urls import urlpatterns as llms_patterns

urlpatterns = [
    # ... your URLs
] + llms_patterns
```

This adds `/llms.txt` and `/llms-full.txt` to your site.

### 3. Visit your llms.txt

Navigate to `https://yoursite.com/llms.txt` and you'll see:

```
# My Django Project

> A brief description of your website.

## Documentation

- [Getting Started](https://example.com/docs/start/): Quick start guide
- [API Reference](https://example.com/docs/api/): Complete API documentation
```

## Auto-Generate from Models

The real power of `django-llms-txt` is auto-generating sections from your Django models:

```python
LLMS_TXT = {
    "SITE_NAME": "My Blog",
    "SITE_URL": "https://example.com",
    "DESCRIPTION": "A blog about Django development.",
    "AUTO_SECTIONS": [
        {
            "title": "Blog Posts",
            "model": "blog.Post",
            "filter": {"status": "published"},
            "ordering": ["-published_date"],
            "name_field": "title",
            "url_method": "get_absolute_url",
            "description_field": "excerpt",
            "full_text_field": "content",
            "limit": 50,
        },
        {
            "title": "Categories",
            "model": "blog.Category",
            "name_field": "name",
            "url_method": "get_absolute_url",
            "description_field": "description",
        },
    ],
    "FULL_TEXT": True,
}
```

### AUTO_SECTIONS Options

| Option | Required | Description |
|--------|----------|-------------|
| `title` | Yes | Section heading |
| `model` | Yes | Django model path (e.g., `"blog.Post"`) |
| `filter` | No | QuerySet filter dict (e.g., `{"status": "published"}`) |
| `ordering` | No | QuerySet ordering (string or list) |
| `name_field` | No | Model field for link text (default: `"title"`) |
| `url_method` | No | Method/attribute for URL (default: `"get_absolute_url"`) |
| `description_field` | No | Model field for link description |
| `full_text_field` | No | Model field for full content (used in `llms-full.txt`) |
| `limit` | No | Maximum number of entries |

## Management Command

Generate static files instead of serving dynamically:

```bash
# Generate in current directory
python manage.py generate_llms_txt

# Generate in a specific directory
python manage.py generate_llms_txt --output static/
```

Set `FULL_TEXT: True` in your config to also generate `llms-full.txt`.

## Configuration Reference

```python
LLMS_TXT = {
    # Required
    "SITE_NAME": "My Site",
    "SITE_URL": "https://example.com",

    # Optional
    "DESCRIPTION": "A brief description.",
    "SECTIONS": [...],         # Static sections
    "AUTO_SECTIONS": [...],    # Model-based sections
    "FULL_TEXT": False,        # Enable llms-full.txt
    "EXCLUDE_PATTERNS": [],    # URL patterns to exclude
}
```

## Combining Static and Auto Sections

You can mix both approaches:

```python
LLMS_TXT = {
    "SITE_NAME": "My Site",
    "SITE_URL": "https://example.com",
    "DESCRIPTION": "Description here.",
    "SECTIONS": [
        {
            "title": "About",
            "links": [
                {"name": "About Us", "url": "/about/"},
                {"name": "Contact", "url": "/contact/"},
            ],
        },
    ],
    "AUTO_SECTIONS": [
        {
            "title": "Blog",
            "model": "blog.Post",
            "filter": {"status": "published"},
            "name_field": "title",
            "url_method": "get_absolute_url",
            "description_field": "excerpt",
        },
    ],
}
```

## Requirements

- Python 3.9+
- Django 4.2+

## Created by

Built by [Rapitek](https://rapitek.com) - Enterprise CRM platform with 10+ years of industry experience. We use `django-llms-txt` in production to power our own [llms.txt](https://rapitek.com/llms.txt).

## License

MIT License. See [LICENSE](LICENSE) for details.
