Julia/Python bridge with IPython support enabling seamless interoperability between Python and Julia programming languages.
—
Command-line utilities for running Julia through PyJulia (julia-py) and Python within Julia processes (python-jl), providing seamless integration for shell-based workflows and cross-language development.
Launch Julia interpreter through PyJulia with Python integration enabled.
def julia_py(julia: str, pyjulia_debug: bool, jl_args: list):
"""
Launch Julia interpreter through PyJulia.
Parameters:
- julia: Path to Julia executable
- pyjulia_debug: Enable PyJulia debugging output
- jl_args: Arguments to pass to Julia
"""
def main(args=None, **kwargs):
"""
Command line interface for julia-py script.
Parameters:
- args: Command line arguments (default: sys.argv)
- **kwargs: Additional configuration options
"""
def parse_args(args: list, **kwargs) -> argparse.Namespace:
"""
Parse command line arguments for julia-py.
Parameters:
- args: Command line arguments to parse
- **kwargs: Parser configuration options
Returns:
- Parsed arguments namespace
"""
def is_pyjulia_in_julia_debug(julia_debug: bool) -> bool:
"""
Check if PyJulia debugging is enabled.
Parameters:
- julia_debug: Julia debug flag
Returns:
- True if PyJulia debugging should be enabled
"""Run Python interpreter inside Julia process for enhanced integration.
def main(args=None):
"""
Python interpreter running inside Julia process.
Parameters:
- args: Command line arguments (default: sys.argv)
"""
def remove_julia_options(args: list) -> list:
"""
Remove Julia-specific options from argument list.
Parameters:
- args: Original argument list
Returns:
- Filtered argument list with Julia options removed
"""
def parse_pyjl_args(args: list):
"""
Parse arguments for python-jl script.
Parameters:
- args: Command line arguments to parse
Returns:
- Parsed configuration for python-jl execution
"""Python-like command line interface with Julia integration.
class PyArgumentParser:
"""Argument parser that mimics Python's argparse behavior."""
def python(module: str = None, command: str = None, script: str = None,
args: list = None, interactive: bool = False):
"""
Execute Python-like commands with Julia integration.
Parameters:
- module: Python module to run (-m option)
- command: Python command to execute (-c option)
- script: Python script file to run
- args: Arguments to pass to script/module
- interactive: Enable interactive mode (-i option)
"""
def make_parser(description: str) -> PyArgumentParser:
"""
Create argument parser with description.
Parameters:
- description: Parser description text
Returns:
- Configured PyArgumentParser instance
"""
def parse_args_with(parser: PyArgumentParser, args: list):
"""
Parse arguments using given parser.
Parameters:
- parser: PyArgumentParser instance
- args: Arguments to parse
Returns:
- Parsed arguments
"""
def parse_args(args: list):
"""
Parse command line arguments for pseudo Python CLI.
Parameters:
- args: Command line arguments
Returns:
- Parsed configuration
"""# Basic usage - start Julia with PyJulia integration
julia-py
# Run Julia script through PyJulia
julia-py my_script.jl
# Pass arguments to Julia script
julia-py my_script.jl arg1 arg2 arg3
# Enable PyJulia debugging
julia-py --pyjulia-debug
# Use specific Julia executable
julia-py --julia /path/to/julia
# Pass Julia-specific options
julia-py --julia-args "--threads=4 --optimize=2"
# Execute Julia code directly
julia-py -e "println(\"Hello from Julia-Py!\")"
# Interactive Julia session with PyJulia
julia-py -i# Run Python inside Julia process
python-jl
# Execute Python script in Julia process
python-jl my_script.py
# Pass arguments to Python script
python-jl my_script.py arg1 arg2
# Execute Python code directly
python-jl -c "print('Hello from Python-JL!')"
# Interactive Python in Julia
python-jl -i
# Run Python module
python-jl -m module_name
# Combine Julia and Python options
python-jl --julia-args "--threads=4" -c "import julia; print('Integrated!')"from julia.julia_py import main as julia_py_main
from julia.python_jl import main as python_jl_main
# Launch julia-py programmatically
julia_py_main([
"--pyjulia-debug",
"-e",
"println(\"Programmatic launch\")"
])
# Launch python-jl programmatically
python_jl_main([
"-c",
"print('Python in Julia process')"
])from julia.julia_py import parse_args, julia_py
# Parse custom arguments
args = parse_args([
"--julia", "/custom/julia",
"--pyjulia-debug",
"script.jl", "arg1", "arg2"
])
# Launch with parsed configuration
julia_py(
julia=args.julia,
pyjulia_debug=args.pyjulia_debug,
jl_args=args.remaining_args
)#!/bin/bash
# Shell script using PyJulia console scripts
# Set up environment
export JULIA_NUM_THREADS=4
export PYTHON_PATH="/path/to/python/env"
# Run data processing in Julia with Python integration
julia-py --pyjulia-debug data_processing.jl input.csv output.csv
# Post-process results with Python in Julia context
python-jl -c "
import pandas as pd
import julia
jl = julia.Julia()
# Access Julia variables from Python
result = jl.eval('result_data')
df = pd.DataFrame(result)
df.to_csv('final_output.csv')
print('Processing complete!')
"# Development script using both console entry points
import subprocess
import os
def run_julia_analysis():
"""Run Julia analysis using julia-py."""
cmd = [
"julia-py",
"--pyjulia-debug",
"analysis.jl",
"--input", "data.csv",
"--output", "results.json"
]
subprocess.run(cmd, check=True)
def run_python_visualization():
"""Run Python visualization in Julia context."""
cmd = [
"python-jl",
"visualize.py",
"results.json",
"plots/"
]
subprocess.run(cmd, check=True)
def integrated_workflow():
"""Complete analysis and visualization workflow."""
print("Running Julia analysis...")
run_julia_analysis()
print("Creating Python visualizations...")
run_python_visualization()
print("Workflow complete!")
if __name__ == "__main__":
integrated_workflow()from julia.pseudo_python_cli import python, main as pseudo_main
# Execute module through pseudo CLI
python(module="my_module", args=["arg1", "arg2"])
# Execute command through pseudo CLI
python(command="print('Hello world!')")
# Execute script with interactive mode
python(script="my_script.py", interactive=True)
# Command line interface
pseudo_main(["-m", "my_module", "arg1", "arg2"])# Add PyJulia console scripts to system PATH
export PATH="$PATH:$(python -c 'import julia; print(julia.__path__[0])')/bin"
# Create aliases for common operations
alias jpy="julia-py --pyjulia-debug"
alias pyjl="python-jl"
# Use in pipelines
data_generator.py | julia-py process_data.jl | python-jl post_process.py > final_results.txt// VS Code task configuration for PyJulia console scripts
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Julia with PyJulia",
"type": "shell",
"command": "julia-py",
"args": ["${file}"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
}
},
{
"label": "Run Python in Julia",
"type": "shell",
"command": "python-jl",
"args": ["${file}"],
"group": "build"
}
]
}Console scripts provide detailed error reporting and debugging options:
# Enable verbose debugging
julia-py --pyjulia-debug --verbose script.jl
# Capture and handle errors in shell scripts
if ! julia-py analysis.jl; then
echo "Julia analysis failed"
exit 1
fi
# Check console script availability
command -v julia-py >/dev/null 2>&1 || {
echo "julia-py not found. Please install PyJulia."
exit 1
}--julia PATH: Path to Julia executable--pyjulia-debug: Enable PyJulia debugging output--julia-args ARGS: Arguments to pass to Julia-e CODE: Execute Julia code-i: Interactive mode--help: Show help message--julia-args ARGS: Arguments to pass to Julia runtime-c CODE: Execute Python code-m MODULE: Run Python module-i: Interactive mode after script--help: Show help messageThese console scripts provide the foundation for integrating PyJulia into automated workflows, shell scripts, and development environments.
Install with Tessl CLI
npx tessl i tessl/pypi-julia