Convert Python code to beautifully formatted, syntax-highlighted PDFs
Project description
📄 Prettipy
Beautiful Python Code to PDF Converter
Transform your Python source code into professionally formatted, syntax-highlighted PDF documents with ease.
✨ Features
- 🎨 Syntax Highlighting: Beautiful, GitHub-style syntax highlighting using Pygments
- 📦 Smart Line Wrapping: Intelligently wraps long lines at natural break points
- 🎯 Multiple Input Modes: Convert entire directories or specific files
- ⚙️ Highly Configurable: Customize colors, fonts, page size, and more
- 🚀 CLI & Python API: Use from command line or integrate into your projects
- 📋 Rich Output: Beautiful progress bars and formatted output (when
richis installed) - 🔍 Smart Filtering: Automatically excludes common directories like
venv,__pycache__, etc. - 📄 Professional Layout: Clean, readable formatting with proper spacing and margins
🚀 Quick Start
Installation
# Basic installation
pip install prettipy
# With rich formatting (recommended)
pip install prettipy[rich]
Basic Usage
# Convert current directory
prettipy
# Convert specific directory
prettipy /path/to/your/project
# Convert specific files
prettipy -f script1.py script2.py utils.py
# Specify output file
prettipy -o my_code.pdf
# Custom line width
prettipy -w 100
📖 Detailed Usage
Command Line Interface
usage: prettipy [-h] [-o OUTPUT] [-f FILES [FILES ...]] [-w WIDTH]
[--config CONFIG] [-t TITLE] [--theme {default}]
[--page-size {letter,a4}] [-v] [--version] [--init-config]
[directory]
Convert Python code to beautifully formatted PDFs
positional arguments:
directory Directory to scan for Python files (default: current)
optional arguments:
-h, --help Show this help message and exit
-o, --output OUTPUT Output PDF file path (default: output.pdf)
-f, --files FILES Specific Python files to convert
-w, --width WIDTH Maximum line width before wrapping (default: 90)
--config CONFIG Path to configuration JSON file
-t, --title TITLE Custom title for the PDF document
--theme {default} Color theme to use
--page-size {letter,a4}
PDF page size (default: letter)
-v, --verbose Enable verbose output
--version Show program's version number and exit
--init-config Generate a sample configuration file
Examples
Convert Current Directory
prettipy
This will create output.pdf with all Python files from the current directory.
Convert With Custom Settings
prettipy /path/to/project \
-o project_code.pdf \
-w 100 \
--title "My Awesome Project" \
--page-size a4
Convert Specific Files
prettipy -f main.py utils.py models.py -o core_files.pdf
Use Configuration File
# Generate sample config
prettipy --init-config
# Edit prettipy-config.json, then use it
prettipy --config prettipy-config.json
Python API
You can also use Prettipy programmatically in your Python code:
from prettipy import PrettipyConverter, PrettipyConfig
# Basic usage with defaults
converter = PrettipyConverter()
converter.convert_directory("./my_project", output="project.pdf")
# Custom configuration
config = PrettipyConfig(
max_line_width=100,
page_size='a4',
title='My Project Documentation',
verbose=True
)
converter = PrettipyConverter(config)
converter.convert_directory("./src")
# Convert specific files
converter.convert_files(
files=['main.py', 'utils.py', 'models.py'],
output='core.pdf'
)
⚙️ Configuration
Configuration File
Generate a sample configuration file:
prettipy --init-config
This creates prettipy-config.json:
{
"exclude_dirs": [
".git",
"venv",
"__pycache__",
"node_modules"
],
"exclude_patterns": [],
"include_patterns": ["*.py"],
"max_line_width": 90,
"font_size": 9,
"line_spacing": 14,
"page_size": "letter",
"title": null,
"show_line_numbers": false,
"theme": "default",
"output_file": "output.pdf",
"verbose": false
}
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
exclude_dirs |
list | See config | Directories to exclude |
exclude_patterns |
list | [] |
File patterns to exclude |
include_patterns |
list | ["*.py"] |
File patterns to include |
max_line_width |
int | 90 |
Max characters before wrapping |
font_size |
int | 9 |
Font size for code |
line_spacing |
int | 14 |
Line spacing in points |
page_size |
string | "letter" |
Page size (letter/a4) |
title |
string | null |
PDF title |
show_line_numbers |
bool | false |
Show line numbers (future) |
theme |
string | "default" |
Color theme |
output_file |
string | "output.pdf" |
Default output path |
verbose |
bool | false |
Verbose output |
🎨 Themes
Currently, Prettipy includes a beautiful default theme with GitHub-style syntax highlighting:
- Keywords: Green (
#007020) - Functions: Dark Blue (
#06287e) - Classes: Teal (
#0e7c7b) - Strings: Blue (
#4070a0) - Numbers: Green (
#40a070) - Comments: Gray-Blue (
#60a0b0)
More themes coming soon!
🛠️ Development
Setup Development Environment
# Clone the repository
git clone https://github.com/yourusername/prettipy.git
cd prettipy
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode with all dependencies
pip install -e ".[dev,rich]"
Run Tests
pytest
pytest --cov=prettipy # With coverage
Code Quality
# Format code
black src/prettipy
# Lint
flake8 src/prettipy
# Type checking
mypy src/prettipy
📦 Building and Publishing
Build Package
# Install build tools
pip install build twine
# Build distribution
python -m build
This creates files in dist/:
prettipy-0.1.0-py3-none-any.whlprettipy-0.1.0.tar.gz
Publish to PyPI
# Test on TestPyPI first
twine upload --repository testpypi dist/*
# Then publish to PyPI
twine upload dist/*
🤝 Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and ensure they pass
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📋 Roadmap
- Additional color themes (Monokai, Solarized, etc.)
- Line numbering option
- Table of contents generation
- Support for more file types (JavaScript, Java, etc.)
- Customizable syntax highlighting rules
- PDF bookmarks for easy navigation
- Export to other formats (HTML, Markdown)
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
📬 Contact
- Author: Hyun-Hwan Jeong
- Email: hyun-hwan.jeong@bcm.edu
- GitHub: @hyunhwan-bcm
Made with ❤️ by developers, for developers.
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 prettipy-0.1.0.tar.gz.
File metadata
- Download URL: prettipy-0.1.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54d841c6e10325e17c3c4c8fd2b9315d8a097e0df7545de7901a8a36ea85901c
|
|
| MD5 |
b17b0118bdb377c3560498b06d873600
|
|
| BLAKE2b-256 |
f092dcc2ee919f7c3e1ce68b3ef303cc964cf8696730450624947a0a41d3ae36
|
File details
Details for the file prettipy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: prettipy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adf048efefbbe7fdb02387d83aded268a61ab649d164353379156ca4c267143e
|
|
| MD5 |
cd0d87cca8acf53c9181abbed123a7a8
|
|
| BLAKE2b-256 |
b9ee8dc14ac70cec1d9274c9b0de957cd5f4623e5cbb7eefafb32c734cef3a05
|