translate command converts Python source code to C++ and generates a Makefile for compilation. This is the traditional Shed Skin workflow.
Syntax
The
translate command is the default. Running shedskin myprogram.py is equivalent to shedskin translate myprogram.py.Overview
The translate command performs:- Parsing - Reads and validates your Python source code
- Type Inference - Analyzes types using iterative flow analysis
- Code Generation - Generates optimized C++ source files
- Makefile Generation - Creates a Makefile for compilation (optional)
Basic Examples
Translate to C++
example.cpp- C++ implementationexample.hpp- C++ header fileMakefile- Build configuration
Translate and compile immediately
make to build the executable.
Translate, compile, and run
Generate extension module
Generated C++ Structure
Executable Program
Forprogram.py, Shed Skin generates:
- Type-specialized functions
- Optimized data structures
- Integration with Shed Skin runtime library
Extension Module
For extension modules (--extmod):
Command Options
Basic Options
Python file or module to translate (e.g.,
program.py)Directly compile the translated code using the generated Makefile
Translate, compile, and run the executable in one step
Specify output directory for generated C++ files (default: current directory)
Generate a Python extension module instead of a standalone executable
Explicitly generate a standalone executable (this is the default)
Silent mode - only show warnings, suppress informational messages
Set debug logging level:
1- Basic debug information2- Detailed debug output3- Enables iterative flow analysis (IFA) logging
Makefile Options
Disable Makefile generation (only generate C++ files)
Specify alternate Makefile name (default:
Makefile)Provide path to alternate Makefile flags configuration file
Use static linking if possible (creates standalone binaries)
Only print the compilation command without executing it
Disable cleanup of generated intermediate files
Type Configuration
Use 32-bit integers throughout the generated code
Use 64-bit integers for better range at slight performance cost
Use 128-bit integers (Linux/macOS only, not supported on Windows)
Use 32-bit floating point (single precision) for better performance
Use 64-bit floating point (double precision) for better accuracy
Performance & Safety Options
Disable bounds checking on array/list access. Significant performance boost but removes safety checks.
Disable wrap-around checking for negative indices (e.g.,
list[-1])Disable Python assert statements in generated code
Disable garbage collection. Use only if you’re certain about memory management.
Print full traceback for uncaught exceptions in compiled code
Linking Options
Add include directories for C++ compilation. Can be specified multiple times.Example:
-I /usr/local/include -I ./headersAdd library directories for linking. Can be specified multiple times.Example:
-L /usr/local/lib -L ./libAdd libraries to link against. Can be specified multiple times.Example:
-l pthread -l mAdd an extra directory for Shed Skin builtins library extensions
Other Options
Use dependencies from bundled ext/ sources instead of system libraries
Collect and report detailed compilation statistics
Advanced Examples
Generate C++ only (no Makefile)
Custom Makefile name
Performance-optimized translation
Translation with custom output directory
Extension module with type configuration
Debug build with tracebacks
Static linking for portable binaries
Dry run to see compilation command
make would execute without actually compiling.
Translate vs Build
Use translate when:- You want a simple Makefile workflow
- You need direct control over the compilation process
- You’re integrating with existing Make-based projects
- You want to customize the generated Makefile
- You want modern CMake-based workflow
- You need better dependency management
- You want IDE integration (most IDEs support CMake)
- You need multi-configuration builds (Debug/Release)
Compiling the Generated Code
Using the generated Makefile
Using the shorthand
Complete workflow
Output Files
C++ Source Files
program.cpp - Main implementation:
program.hpp - Header declarations:
Makefile
The generated Makefile includes:- Compiler flags for optimization
- Include paths for Shed Skin runtime
- Linking configuration
- Platform-specific settings
--flags to provide alternate flags.
Extension Module Usage
After compiling an extension module:When to Use Translate
The translate command is ideal for:- Learning how Shed Skin generates C++ code
- Inspecting the generated code for optimization opportunities
- Integrating with existing Make-based build systems
- Quick prototyping and experimentation
- Manual customization of build process
See Also
- build command - Modern CMake-based compilation
- Command-line options - Complete option reference
- CLI overview - All available commands