A Python package and command-line tool for interacting with RT (Request Tracker) systems. Provides authenticated access to RT servers for querying ticket information, attachments, and other data.
- Complete Ticket Downloads: Download entire tickets with metadata, complete history, individual history items, and attachments
- Smart Attachment Processing: Automatically skips zero-byte attachments and outgoing emails, with automatic XLSX→TSV conversion
- Recursive History Fetching: Handles broken RT API parameters with robust fallback methods
- Persistent Authentication: Automatically manages RT session cookies with secure keychain integration
- SSL Certificate Verification: Custom certificate support for secure RT server connections
- Flexible Logging: Configurable log levels (quiet, normal, verbose) for debugging and production use
- Command-line Interface: Multiple CLI tools for accessing RT ticket data and attachments
# Clone the repository
git clone <repository-url>
cd rt-tools
# Install in development mode with dev dependencies
pip install -e .[dev]
# Or using uv
uv pip install -e .[dev]pip install rt-toolsNote: The package includes openpyxl for automatic XLSX→TSV conversion of Excel attachments.
Before using RT Tools, you need to set up:
- SSL Certificate: Place
rt.hgsc.bcm.edu.pemin your working directory for RT server verification - Keychain Entry: Store your RT password in macOS keychain with service name "foobar"
security add-generic-password -s "foobar" -a "your_username" -w "your_password"
download-ticket - Downloads complete tickets with metadata, history, and attachments:
# Download ticket to current directory (creates ./rt37525/)
download-ticket 37525
# Download to specific directory (creates local/output/rt37525/)
download-ticket 37525 --output-dir local/output
# With verbose logging to see download progress
download-ticket --verbose 37525
# With quiet mode for minimal output
download-ticket --quiet 37525 --output-dir /tmpTarget Directory Resolution:
The download-ticket command resolves the output directory in the following order:
--output-dircommand-line option (highest priority)$DOWNLOAD_TICKET_DIRenvironment variable~/.config/download-ticket/config.tomlconfig file (default_dirsetting)- Current working directory (fallback)
# Environment variable example
export DOWNLOAD_TICKET_DIR="~/Downloads/rt-tickets"
download-ticket 37525 # Creates ~/Downloads/rt-tickets/rt37525/
# Config file example (~/.config/download-ticket/config.toml)
# default_dir = "~/Documents/rt-data"
download-ticket 37525 # Creates ~/Documents/rt-data/rt37525/Directory Structure:
output_directory/ # Resolved from --output-dir, env var, config, or cwd
└── rt37525/ # Ticket directory (rt{ticket_id} format)
├── metadata.txt # Ticket basic information
├── history.txt # Complete ticket history
├── 456/ # History entry directory
│ └── message.txt # Individual history entry content
├── 458/ # Another history entry directory
│ ├── message.txt # History entry content
│ ├── n800.pdf # Attachment for this history entry
│ └── n801.xlsx # Another attachment (with auto-generated .tsv)
└── ...
Features:
- Organized structure: Each history entry and its attachments are grouped in individual directories
- Consistent filtering: Automatically skips zero-byte attachments and outgoing emails from both attachments and individual history items
- Uses recursive history fetching to handle broken RT API parameters
- Downloads attachments with format:
n{attachment_id}.{extension}within each history directory (the "n" prefix ensures message.txt sorts first) - Individual history items: Each history entry is saved as
{history_id}/message.txtfor detailed analysis (excluding outgoing emails) - Automatic XLSX→TSV conversion: Excel files are automatically converted to tab-separated values for easier analysis
- Creates comprehensive ticket metadata and history files
dump-ticket - Retrieves and displays RT ticket information:
# Basic ticket information
dump-ticket 37525
# Ticket with additional path components (e.g., attachments)
dump-ticket 37525 attachments/1483996/content
# With verbose logging (shows authentication details, headers, etc.)
dump-ticket --verbose 37525
# With quiet mode (only errors and warnings)
dump-ticket --quiet 37525dump-rest - Retrieves content from RT REST API URLs (relative to REST/1.0 endpoint):
# List all tickets
dump-rest
# Show specific ticket
dump-rest ticket/37525/show
# Access ticket attachments
dump-rest ticket/37525/attachments
# With logging options
dump-rest --verbose ticket/37525/show
dump-rest --quiet user/usernamedump-url - Retrieves content from arbitrary RT URLs (relative to server base):
# Access REST API directly
dump-url REST/1.0/
# Access specific RT paths
dump-url NoAuth/css/base/main.css
# With logging options
dump-url --verbose REST/1.0/ticket/37525/show
dump-url --quiet some/pathfrom rt_tools import RTSession
# Create an authenticated session
with RTSession() as session:
session.authenticate()
# Access ticket data programmatically
response = session.get("https://rt.hgsc.bcm.edu/REST/1.0/ticket/37525/show")
print(response.text)RTSession: Extendsrequests.Sessionwith RT-specific authentication and cookie management- Authentication: Automatic login using stored credentials with session persistence
- Cookie Management: Mozilla-format cookie jar for maintaining authentication across sessions
- Logging: Structured logging with configurable levels
- Loads existing cookies from
cookies.txtif available - Checks authorization status by parsing RT server responses
- If unauthorized, fetches password from macOS keychain
- Performs authentication POST request and saves new cookies
- Subsequent requests use stored authentication cookies
RT URLs are constructed as: BASE_URL/ticket/{id}/{path_components...}
- Base URL:
https://rt.hgsc.bcm.edu/REST/1.0/ - Ticket ID: Numeric identifier (e.g.,
37525) - Path components: Optional additional paths (e.g.,
attachments/1483996/content)
# Run linting
ruff check src/rt_tools/
# Auto-fix issues
ruff check --fix src/rt_tools/
# Run tests
pytest
# Install pre-commit hooks (one-time setup)
uv pip install pre-commit
pre-commit install
# Run pre-commit on all files
pre-commit run --all-filesPre-commit hooks are configured to run:
- Ruff linting and formatting
- MyPy type checking
- Basic file hygiene (trailing whitespace, end-of-file fixes)
- YAML/TOML validation
- Large file detection
Binary test fixtures (.bin files) are excluded from text processing hooks.
# Build package
python -m build- Default (INFO): Shows basic operation status and responses
- Verbose (DEBUG): Shows detailed request/response information, headers, authentication steps
- Quiet (WARNING): Shows only warnings and errors, suppresses routine operational messages
- Passwords are stored in macOS keychain, never in code or configuration files
- SSL certificate verification prevents man-in-the-middle attacks
- Session cookies are stored locally and reused to minimize authentication requests
- Python 3.13+
- macOS (for keychain integration)
- Network access to RT server
- Valid RT user credentials
- SSL certificate file for RT server
This project is licensed under the MIT License - see the LICENSE file for details.