or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

console-scripts.mdcore-runtime.mddevelopment-tools.mdindex.mdipython-integration.mdlow-level-api.md

index.mddocs/

0

# PyJulia

1

2

A comprehensive Python library that enables seamless interoperability between Python and Julia programming languages. PyJulia allows Python developers to call Julia functions directly from Python code, leverage Julia's high-performance numerical computing capabilities within Python workflows, and provides automatic type conversion between Python and Julia data structures.

3

4

## Package Information

5

6

- **Package Name**: julia

7

- **Language**: Python

8

- **Installation**: `pip install julia`

9

- **Version**: 0.6.2

10

11

## Core Imports

12

13

```python

14

import julia

15

```

16

17

For the main Julia interface:

18

19

```python

20

from julia import Julia

21

```

22

23

For accessing Julia modules directly:

24

25

```python

26

from julia import Base, Main

27

```

28

29

For IPython/Jupyter magic commands:

30

31

```python

32

%load_ext julia.magic

33

```

34

35

## Basic Usage

36

37

```python

38

import julia

39

40

# Install required Julia packages (run once)

41

julia.install()

42

43

# Create Julia interface

44

jl = julia.Julia()

45

46

# Access Julia's Base module

47

from julia import Base

48

49

# Call Julia functions

50

result = Base.sind(90) # Sin in degrees

51

print(result) # 1.0

52

53

# Execute Julia code directly

54

jl.eval('println("Hello from Julia!")')

55

56

# Access Julia variables

57

jl.eval('x = [1, 2, 3, 4, 5]')

58

x = jl.eval('x')

59

print(x) # [1, 2, 3, 4, 5]

60

61

# Use Julia's powerful array operations

62

import numpy as np

63

arr = np.array([1.0, 2.0, 3.0])

64

jl_result = jl.eval('sum(x -> x^2, [1, 2, 3])')

65

print(jl_result) # 14.0

66

```

67

68

## Architecture

69

70

PyJulia implements a multi-layered architecture for Python-Julia interoperability:

71

72

- **High-level Interface**: `Julia` class provides easy-to-use Python API with automatic type conversion

73

- **Module System**: Direct importing of Julia modules (`from julia import Base, Main`)

74

- **Low-level API**: `LibJulia` class provides direct access to Julia's C API for advanced users

75

- **IPython Integration**: Magic commands and completion for interactive Jupyter workflows

76

- **Console Scripts**: `julia-py` and `python-jl` executables for command-line integration

77

78

This design enables both casual scientific computing users and performance-critical applications to leverage Julia's capabilities from Python environments.

79

80

## Capabilities

81

82

### Core Julia Runtime

83

84

Primary interface for executing Julia code from Python, including runtime initialization, module importing, function calling, and automatic type conversion between Python and Julia data structures.

85

86

```python { .api }

87

class Julia:

88

def __init__(self, runtime=None, jl_init_path=None, **kwargs): ...

89

def eval(self, code: str): ...

90

def using(self, module_name: str): ...

91

92

def install(julia="julia", color="auto", python=None, quiet=False): ...

93

94

# Direct module access

95

from julia import Base, Main

96

```

97

98

[Core Runtime](./core-runtime.md)

99

100

### IPython and Jupyter Integration

101

102

Magic commands, code completion, and interactive development features for Jupyter notebooks and IPython environments, including Revise.jl integration for automatic code reloading.

103

104

```python { .api }

105

class JuliaMagics:

106

def julia(self, line, cell=None): ... # Line and cell magic

107

108

# Magic command usage in Jupyter

109

%julia code

110

%%julia

111

multi-line

112

code

113

```

114

115

[IPython Integration](./ipython-integration.md)

116

117

### Low-level LibJulia API

118

119

Direct access to Julia's C API for advanced users who need fine-grained control over the Julia runtime, memory management, and performance-critical operations.

120

121

```python { .api }

122

class LibJulia:

123

def __init__(self, **kwargs): ...

124

def eval_string(self, code: str): ...

125

def call(self, func, *args): ...

126

127

def get_libjulia(): ...

128

def set_libjulia(libjulia): ...

129

```

130

131

[Low-level API](./low-level-api.md)

132

133

### Development Tools and Utilities

134

135

Utilities for PyCall.jl installation, system image building, testing infrastructure, and development workflow support including PyCall rebuild and Julia executable management.

136

137

```python { .api }

138

def install(julia="julia", color="auto", python=None, quiet=False): ...

139

def build_pycall(julia="julia", python=sys.executable, **kwargs): ...

140

def build_sysimage(output, julia="julia", script=None, debug=False): ...

141

```

142

143

[Development Tools](./development-tools.md)

144

145

### Console Scripts and Entry Points

146

147

Command-line utilities for running Julia through PyJulia (`julia-py`) and Python within Julia processes (`python-jl`), providing seamless integration for shell-based workflows.

148

149

```python { .api }

150

# Console scripts (available after installation)

151

# julia-py [julia-options] [script] [script-args]

152

# python-jl [python-options] [script] [script-args]

153

```

154

155

[Console Scripts](./console-scripts.md)

156

157

## Types

158

159

```python { .api }

160

class JuliaError(Exception):

161

"""Wrapper for Julia exceptions raised during execution."""

162

163

class JuliaNotFound(Exception):

164

"""Raised when Julia executable cannot be found."""

165

166

class UnsupportedPythonError(Exception):

167

"""Raised for unsupported Python configurations."""

168

169

class JuliaModule:

170

"""Represents a Julia module accessible from Python."""

171

172

class JuliaMainModule(JuliaModule):

173

"""Special Julia Main module with assignment support."""

174

```