Julia/Python bridge with IPython support enabling seamless interoperability between Python and Julia programming languages.
—
Magic commands, code completion, and interactive development features for Jupyter notebooks and IPython environments, including Revise.jl integration for automatic code reloading during interactive development workflows.
IPython magic commands for executing Julia code directly in Jupyter notebooks and IPython shells.
class JuliaMagics:
"""IPython magics for Julia integration in Jupyter notebooks."""
def julia(self, line: str, cell: str = None):
"""
Line and cell magic for executing Julia code.
Line magic usage: %julia code
Cell magic usage: %%julia
Parameters:
- line: Julia code for line magic
- cell: Julia code for cell magic
"""
# Magic properties for configuration
highlight: bool # Enable syntax highlighting
completion: bool # Enable code completion
redirect_output_streams: bool # Redirect Julia output to notebook
revise: bool # Enable Revise.jl integrationLoad Julia magic commands in IPython and Jupyter environments.
# Load extension in IPython/Jupyter
%load_ext julia.magic
# Or programmatically
from julia.magic import JuliaMagics
get_ipython().register_magic_function(JuliaMagics().julia)Enhanced code completion for Julia code in IPython environments.
class JuliaCompleter:
"""Julia code completion provider for IPython."""
class IPCompleterPatcher:
"""Patches IPython completer with Julia support."""
def patch_ipcompleter():
"""Apply Julia completion patches to IPython."""Automatic code reloading for interactive development using Julia's Revise.jl package.
def enable_revise():
"""Enable Revise.jl integration for automatic code reloading."""
def disable_revise():
"""Disable Revise.jl integration."""
def make_revise_wrapper(revise):
"""Create Revise.jl wrapper function."""
def register_revise_hook(ip):
"""Register Revise.jl hook with IPython shell."""Enhanced IPython shell features for Julia integration.
class TerminalInteractiveShellPatcher:
"""Patches terminal interactive shell for Julia integration."""
def patch_interactiveshell(ip):
"""Apply shell patches for Julia integration."""# In a Jupyter notebook cell
%load_ext julia.magic
# Line magic - single line Julia code
%julia println("Hello from Julia!")
# Cell magic - multi-line Julia code
%%julia
function fibonacci(n)
if n <= 2
return 1
else
return fibonacci(n-1) + fibonacci(n-2)
end
end
println(fibonacci(10))# In Python cell
import numpy as np
data = np.array([1, 2, 3, 4, 5])
# Pass Python variable to Julia
%julia -i data println("Data from Python: $data")
# Execute Julia code and get result back
%%julia -o result
result = sum(data .^ 2)
# Use result in Python
print(f"Sum of squares: {result}")%load_ext julia.magic
# Configure magic settings
from julia.magic import JuliaMagics
magic = JuliaMagics()
# Enable syntax highlighting
magic.highlight = True
# Enable code completion
magic.completion = True
# Enable output stream redirection
magic.redirect_output_streams = True
# Enable Revise.jl for automatic reloading
magic.revise = True# Enable Revise.jl for development
from julia.ipy.revise import enable_revise
enable_revise()
# Now Julia code changes are automatically reloaded
%%julia
# Define a function in a .jl file, then modify it
# Changes will be automatically detected and reloaded
include("my_functions.jl")
my_function(10)%load_ext julia.magic
# Set up Julia plotting in notebook
%%julia
using Plots
gr() # Use GR backend
# Create plots that display in notebook
%%julia
x = range(0, 2π, length=100)
y = sin.(x)
plot(x, y, title="Sine Wave", xlabel="x", ylabel="sin(x)")%%julia
# Install Julia packages from notebook
using Pkg
Pkg.add("DataFrames")
Pkg.add("CSV")
# Use packages immediately
using DataFrames, CSV
# Create and manipulate data
df = DataFrame(x=1:10, y=rand(10))
println(df)try:
%julia undefined_function()
except Exception as e:
print(f"Julia magic error: {e}")
# Julia errors are displayed with proper formatting
%%julia
# This will show a nicely formatted Julia stack trace
error("Something went wrong!")# Enable debug output for magic commands
from julia.core import enable_debug
enable_debug()
# Now magic commands show detailed execution info
%%julia
println("Debug information will be visible")
# Check magic configuration
%julia println("Magic is working!")The Julia magic commands support various options for customizing behavior:
-i VARS: Input variables from Python to Julia-o VARS: Output variables from Julia to Python--no-return: Don't return the last expression value--redirect-stderr: Redirect Julia stderr to notebook--no-redirect-stderr: Don't redirect Julia stderrExample usage:
# Input Python variables to Julia
data = [1, 2, 3, 4, 5]
%julia -i data result = sum(data)
# Output Julia variables to Python
%julia -o result result = 42
print(result) # 42 in Python
# Complex example with multiple variables
x, y = 10, 20
%%julia -i x,y -o z
z = x * y + 100
println("Computed z = $z")Install with Tessl CLI
npx tessl i tessl/pypi-julia