Generate beautiful literate programming-style description of your code from comment annotations
Project description
Litterate
A Python command-line tool to generate beautiful literate programming-style documentation from comment annotations in your code.
This is a complete Python port of the original litterate JavaScript tool, built as a modern Python package managed with pixi.
Check out Litterate's own source code, annotated with litterate, on GitHub Pages.
Features
- 📝 Generate beautiful documentation websites from annotated source code
- 🎨 Clean, readable two-column layout (annotations + code)
- 🔧 Highly configurable via command-line or config files
- 🐍 Python-first with sensible defaults for Python projects
- 📦 Easy installation and distribution via pixi
- 🌐 Support for any language with line-comment syntax
Installation
Using pixi (recommended)
Install globally using pixi:
pixi global install litterate
From source
Clone this repository and install with pixi:
git clone https://github.com/yourusername/litterate.git
cd litterate
pixi install
pixi shell
Usage
Quick Start
Run Litterate with default settings:
litterate
This will process all Python files in ./src/**/*.py and generate documentation in ./docs/.
Note: By default, documentation is generated with relative paths so you can view it locally by opening docs/index.html directly in your browser. For web deployment (like GitHub Pages), set baseURL to your site's base path.
With Configuration File
Create a litterate.config.py file:
# litterate.config.py
name = "My Project"
description = """
A cool project that does amazing things.
You can use **Markdown** here!
"""
files = [
"./src/**/*.py",
"./scripts/**/*.py",
]
baseURL = "/my-project" # For GitHub Pages
output_directory = "./docs/"
Run with config:
litterate --config litterate.config.py
Command-Line Options
Options:
--config PATH Specify a Python or JSON file for configuration
-n, --name TEXT Name of your project
-d, --description TEXT Description text for your project
-w, --wrap INTEGER Wrap long lines to N characters (0 = no wrapping)
-b, --base-url TEXT Base URL for the site (e.g., /project for GitHub Pages)
-v, --verbose Verbose output
-o, --output PATH Destination directory for generated docs
--help Show this message and exit
Annotation Syntax
By default, Litterate processes Python-style comments starting with #>:
#> This is a documentation annotation.
# You can continue the annotation on multiple lines.
# Markdown is supported: **bold**, *italic*, `code`, etc.
def hello_world():
# Regular comments are ignored
print("Hello, World!")
Configuration Options
All options can be set via config file or command-line:
name: Project name shown in the generated sitedescription: Project description (Markdown supported)files: List of glob patterns for source files to processwrap: Character limit for line wrapping (0 = no wrapping)baseURL: Base URL for the generated site (default:"./"for local viewing, use"/"for web root or"/project-name"for GitHub Pages)verbose: Enable verbose outputoutput_directory: Where to save generated docs (default:./docs/)annotation_start_mark: Comment prefix for annotation blocks (default:#>)annotation_continue_mark: Comment prefix for continuation lines (default:#)
Using with Other Languages
Litterate can work with any language that has line comments. For JavaScript/TypeScript:
# litterate.config.py
files = ["./src/**/*.js"]
annotation_start_mark = "//>"
annotation_continue_mark = "//"
Development
Setup Development Environment
# Install dependencies
pixi install
# Activate the environment
pixi shell
Run Tests
pixi run test
Lint and Format
pixi run lint
pixi run fmt
Generate Documentation
Generate Litterate's own documentation:
pixi run docs
Pixi Tasks
This project includes several pixi tasks for convenience:
pixi run test- Run the test suitepixi run lint- Run linting checkspixi run fmt- Format codepixi run docs- Generate documentation for this project
How It Works
- Parse: Litterate reads your source files and identifies annotation comments (lines starting with
#>by default) - Transform: Annotations are processed as Markdown, code is syntax-highlighted
- Generate: HTML pages are created with a beautiful two-column layout
- Output: A static website is generated in your output directory
Publishing to GitHub Pages
- Configure your build to output to
./docs/:
# litterate.config.py
output_directory = "./docs/"
baseURL = "/your-repo-name" # Match your repo name
- Generate docs:
litterate --config litterate.config.py
- Commit and push to GitHub
- Enable GitHub Pages in your repository settings, using the
docs/folder as the source
Differences from Original
This Python port maintains feature parity with the original JavaScript version while adding:
- Native Python support with modern tooling (pixi, click, jinja2)
- Better type hints and documentation
- Pytest-based test suite
- Improved error handling
- Support for both
.pyand.jsonconfig files
License
MIT License - See LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
Original concept and implementation by Linus Lee. This is a complete Python port of the original litterate tool.
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 litterate-0.1.0.tar.gz.
File metadata
- Download URL: litterate-0.1.0.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb2407adedb0651094f0faf59d36ba82f108d3570f2b9020000f608d04be9608
|
|
| MD5 |
dbf99904bb67c4bf495bf4217ca0e3ce
|
|
| BLAKE2b-256 |
9d096726b53537ea3be6f9d5fad42b5f0f4b6dbf827300a1f92b790411813f1c
|
File details
Details for the file litterate-0.1.0-py3-none-any.whl.
File metadata
- Download URL: litterate-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0212ac3390f9df871b5092c4675df0fefb4c8bb8551d00419a6f5b371782af19
|
|
| MD5 |
37f2bc1ca13ad2126895b4d3107188a0
|
|
| BLAKE2b-256 |
163beb781e9588cfc56e0e63c5f1544c1ceacef2c2270aae0cb375cbb3972353
|