- Python 3.10+ (recommend 3.12+ for best performance)
- pip (
pip install -r requirements-dev.txt)
- Rust 1.70+ (install from rustup.rs)
- Cargo (comes with Rust)
git clone https://github.com/ai-ptd-dev/ptd-python-cli
cd ptd-python-clipip install -r requirements-dev.txt./bin/compileptd-python-cli/
├── src/
│ ├── basiccli/
│ │ ├── cli.py # Python CLI entry point
│ │ ├── commands/
│ │ │ ├── hello.py # Python command
│ │ │ ├── hello.rs # Rust command (side-by-side)
│ │ │ ├── version.py
│ │ │ ├── version.rs
│ │ │ └── ...
│ │ └── utils/
│ │ ├── logger.py # Python utility
│ │ ├── logger.rs # Rust utility (side-by-side)
│ │ └── ...
│ ├── cli.rs # Rust CLI entry point
│ └── lib.rs # Rust library exports
├── tests/
│ ├── commands/
│ │ ├── test_hello.py # Python tests
│ │ ├── test_hello.rs # Rust tests (side-by-side)
│ │ └── ...
│ └── utils/
│ ├── test_logger.py # Python utility tests
│ ├── test_logger.rs # Rust utility tests (side-by-side)
│ └── ...
├── bin/
│ ├── basiccli-python # Python executable
│ ├── basiccli-rust # Rust executable
│ ├── compile # Build Rust binary
│ ├── test # Run Rust tests
│ ├── pytest # Run Python tests
│ └── lint # Lint both languages
└── docs/ # Documentation
# Using the script
./bin/basiccli-python hello "World"
# Direct execution
PYTHONPATH=src python -m basiccli.cli hello "World"# First compile
./bin/compile
# Then run
./bin/basiccli-rust hello "World"
# Or directly
./target/release/basiccli-rust hello "World"# Basic greeting
./bin/basiccli-python hello "Alice"
# With options
./bin/basiccli-python hello "Bob" --uppercase --repeat 3# Human-readable
./bin/basiccli-python version
# JSON output
./bin/basiccli-python version --json# Run benchmarks
./bin/basiccli-python benchmark 1000
# Output formats
./bin/basiccli-python benchmark 1000 --output json
./bin/basiccli-python benchmark 1000 --output csv
# Verbose mode
./bin/basiccli-python benchmark 1000 --verbose# Process JSON file
./bin/basiccli-python process data.json
# With options
./bin/basiccli-python process data.json --pretty --statsCreate your command in src/basiccli/commands/:
from dataclasses import dataclass
from typing import Optional
from ..utils.result import Result
@dataclass
class MyCommand:
name: str
options: Optional[dict] = None
def execute(self) -> Result:
print(f"Hello from MyCommand, {self.name}!")
return Result(success=True, message="Command executed successfully")Register in src/basiccli/cli.py:
@cli.command()
@click.argument('name')
def mycommand(name: str):
"""Description here"""
command = MyCommand(name)
result = command.execute()
if not result.success:
click.echo(f"Error: {result.message}", err=True)
sys.exit(1)Create tests/commands/test_mycommand.py:
import sys
sys.path.insert(0, "src")
from basiccli.commands.mycommand import MyCommand # noqa: E402
def test_executes_successfully():
command = MyCommand("TestUser")
result = command.execute()
assert result.success is True
assert "TestUser" in result.message./bin/pytestCreate side-by-side src/basiccli/commands/mycommand.rs:
use anyhow::Result;
pub struct MyCommand {
name: String,
}
impl MyCommand {
pub fn new(name: String) -> Self {
Self { name }
}
pub fn execute(&self) -> Result<()> {
println!("Hello from MyCommand, {}!", self.name);
Ok(())
}
}./bin/compile
./bin/testBuilds the Rust binary with optimizations:
./bin/compileRuns Rust tests:
./bin/testRuns Python tests:
./bin/pytestLints and auto-fixes both Python and Rust:
./bin/lintCompare Python vs Rust performance:
# Python version
time ./bin/basiccli-python benchmark 1000
# Rust version
time ./bin/basiccli-rust benchmark 1000- Explore the code: Look at existing commands for patterns
- Add your command: Follow the development workflow
- Benchmark: Compare Python vs Rust performance
- Optimize: Profile and improve bottlenecks
- Deploy: Use the Rust binary in production
- Keep Python and Rust implementations functionally identical
- Use Python for rapid prototyping
- Transpile to Rust for production deployment
- Run both test suites to ensure parity
- Use the performance benchmarks to validate improvements
- Files are organized side-by-side for easy comparison and maintenance