or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

code-navigation.mdcode-refactoring.mdconfiguration.mdenvironment-management.mdindex.mdinterpreter-integration.mdproject-configuration.mdscript-analysis.md

index.mddocs/

0

# Jedi

1

2

Jedi is a comprehensive static analysis library for Python that provides intelligent autocompletion, code navigation (goto definitions), documentation lookup, and refactoring capabilities primarily designed for integration into IDEs, editors, and development tools. The library offers a simple and powerful API that can analyze Python code without executing it, supporting features like method completion, parameter suggestions, variable inference, reference finding, and code search across projects and modules.

3

4

## Package Information

5

6

- **Package Name**: jedi

7

- **Version**: 0.19.2

8

- **Language**: Python

9

- **Installation**: `pip install jedi`

10

11

## Core Imports

12

13

```python

14

import jedi

15

```

16

17

For basic script analysis:

18

19

```python

20

from jedi import Script

21

```

22

23

For REPL/interpreter usage:

24

25

```python

26

from jedi import Interpreter

27

```

28

29

For environment and project management:

30

31

```python

32

from jedi import Project, get_default_project

33

from jedi.api.environment import find_virtualenvs, get_default_environment

34

```

35

36

## Basic Usage

37

38

```python

39

import jedi

40

41

# Analyze code for completions

42

source_code = '''

43

import json

44

json.lo'''

45

46

script = jedi.Script(code=source_code, path='example.py')

47

48

# Get completions at position

49

completions = script.complete(line=3, column=len('json.lo'))

50

for completion in completions:

51

print(f"{completion.name}: {completion.complete}")

52

53

# Get function signatures

54

signatures = script.get_signatures(line=3, column=len('json.loads('))

55

for sig in signatures:

56

print(f"Function: {sig.name}")

57

for param in sig.params:

58

print(f" {param.name}: {param.description}")

59

60

# Type inference

61

definitions = script.infer(line=2, column=len('json'))

62

for definition in definitions:

63

print(f"Type: {definition.type}, Module: {definition.module_name}")

64

```

65

66

## Architecture

67

68

Jedi's architecture centers around static analysis and inference:

69

70

- **Script**: Main entry point for analyzing source code files with full project context

71

- **Interpreter**: Specialized for REPL environments with runtime namespace integration

72

- **InferenceState**: Core inference engine that tracks types, scopes, and relationships

73

- **Environment**: Python environment abstraction supporting virtualenvs and multiple Python versions

74

- **Project**: Project-level configuration including sys.path, extensions, and search scope

75

76

The inference system works by parsing code with Parso, building syntax trees, and applying type inference rules to determine completions, definitions, and references without code execution. This enables safe analysis of any Python code while maintaining accuracy through sophisticated static analysis techniques.

77

78

## Capabilities

79

80

### Script Analysis

81

82

Core functionality for analyzing Python source code, providing completions, type inference, definition lookup, and navigation. Supports both file-based and string-based code analysis with full project context.

83

84

```python { .api }

85

class Script:

86

def __init__(self, code=None, *, path=None, environment=None, project=None): ...

87

def complete(self, line=None, column=None, *, fuzzy=False): ...

88

def infer(self, line=None, column=None, *, only_stubs=False, prefer_stubs=False): ...

89

def goto(self, line=None, column=None, *, follow_imports=False, follow_builtin_imports=False, only_stubs=False, prefer_stubs=False): ...

90

```

91

92

[Script Analysis](./script-analysis.md)

93

94

### Interpreter Integration

95

96

REPL and interactive environment support with runtime namespace integration. Enables completions and analysis in interactive Python sessions using actual runtime objects and namespaces.

97

98

```python { .api }

99

class Interpreter(Script):

100

def __init__(self, code, namespaces, *, project=None, **kwds): ...

101

```

102

103

[Interpreter Integration](./interpreter-integration.md)

104

105

### Code Navigation and Search

106

107

Advanced code navigation including reference finding, symbol search, context analysis, and help lookup. Provides IDE-level navigation capabilities across entire projects.

108

109

```python { .api }

110

def get_references(self, line=None, column=None, **kwargs): ...

111

def search(self, string, *, all_scopes=False): ...

112

def help(self, line=None, column=None): ...

113

def get_context(self, line=None, column=None): ...

114

```

115

116

[Code Navigation](./code-navigation.md)

117

118

### Environment Management

119

120

Python environment detection and management supporting virtualenvs, system environments, and custom Python installations. Provides environment-aware analysis and completion.

121

122

```python { .api }

123

def find_virtualenvs(paths=None, *, safe=True, use_environment_vars=True): ...

124

def find_system_environments(*, env_vars=None): ...

125

def get_default_environment(): ...

126

def create_environment(path, *, safe=True, env_vars=None): ...

127

```

128

129

[Environment Management](./environment-management.md)

130

131

### Project Configuration

132

133

Project-level configuration and management including sys.path customization, extension loading, and multi-file analysis scope. Enables project-aware analysis and search.

134

135

```python { .api }

136

class Project:

137

def __init__(self, path, *, environment_path=None, load_unsafe_extensions=False, sys_path=None, added_sys_path=(), smart_sys_path=True): ...

138

def search(self, string, *, all_scopes=False): ...

139

```

140

141

[Project Configuration](./project-configuration.md)

142

143

### Code Refactoring

144

145

Code refactoring operations including rename, extract variable, extract function, and inline operations. Provides safe refactoring with proper scope analysis and conflict detection.

146

147

```python { .api }

148

def rename(self, line=None, column=None, *, new_name): ...

149

def extract_variable(self, line, column, *, new_name, until_line=None, until_column=None): ...

150

def extract_function(self, line, column, *, new_name, until_line=None, until_column=None): ...

151

def inline(self, line=None, column=None): ...

152

```

153

154

[Code Refactoring](./code-refactoring.md)

155

156

### Configuration and Debugging

157

158

Global configuration settings and debugging utilities for controlling jedi behavior, performance tuning, and troubleshooting analysis issues.

159

160

```python { .api }

161

def set_debug_function(func_cb=debug.print_to_stdout, warnings=True, notices=True, speed=True): ...

162

def preload_module(*modules): ...

163

```

164

165

[Configuration](./configuration.md)

166

167

## Constants

168

169

```python { .api }

170

__version__: str = "0.19.2" # Library version

171

```

172

173

## Result Types

174

175

Core result types returned by jedi analysis operations:

176

177

```python { .api }

178

class BaseName:

179

name: str

180

type: str # 'module', 'class', 'instance', 'function', 'param', 'path', 'keyword', 'property', 'statement'

181

module_name: str

182

module_path: str

183

line: int

184

column: int

185

description: str

186

full_name: str

187

188

def docstring(self, raw=False, fast=True): ...

189

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

190

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

191

def get_line_code(self, before=0, after=0): ...

192

def get_signatures(self): ...

193

def execute(self): ...

194

def get_type_hint(self): ...

195

def is_stub(self): ...

196

def is_side_effect(self): ...

197

def in_builtin_module(self): ...

198

def parent(self): ...

199

200

class Name(BaseName):

201

def defined_names(self): ...

202

def is_definition(self): ...

203

204

class Completion(BaseName):

205

complete: str

206

name_with_symbols: str

207

208

class Signature(BaseName):

209

params: list

210

index: int

211

bracket_start: tuple

212

213

class ParamName(Name):

214

kind: str

215

def infer_default(self): ...

216

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

217

```

218

219

## Exception Types

220

221

```python { .api }

222

class InternalError(Exception): ...

223

class RefactoringError(Exception): ...

224

class InvalidPythonEnvironment(Exception): ...

225

class WrongVersion(Exception): ... # Reserved for future use

226

```