Skip to content

Latest commit

 

History

History
174 lines (137 loc) · 3.83 KB

api.rst

File metadata and controls

174 lines (137 loc) · 3.83 KB

API Overview

Note

This documentation is mostly for Plugin developers, who want to improve their editors/IDE with Jedi.

The API consists of a few different parts:

  • The main starting points for complete/goto: .Script and .Interpreter. If you work with Jedi you want to understand these classes first.
  • API Result Classes <api-classes>
  • Python Versions/Virtualenv Support <environments> with functions like .find_system_environments and .find_virtualenvs
  • A way to work with different Folders / Projects <projects>
  • Helpful functions: .preload_module and .set_debug_function

The methods that you are most likely going to use to work with Jedi are the following ones:

jedi

Script.complete Script.goto Script.infer Script.help Script.get_signatures Script.get_references Script.get_context Script.get_names Script.get_syntax_errors Script.rename Script.inline Script.extract_variable Script.extract_function Script.search Script.complete_search Project.search Project.complete_search

Script

jedi.Script

Interpreter

jedi.Interpreter

Projects

jedi.api.project

jedi.get_default_project

jedi.Project

Environments

jedi.api.environment

jedi.find_system_environments

jedi.find_virtualenvs

jedi.get_system_environment

jedi.create_environment

jedi.get_default_environment

jedi.InvalidPythonEnvironment

jedi.api.environment.Environment

Helper Functions

jedi.preload_module

jedi.set_debug_function

Errors

jedi.InternalError

jedi.RefactoringError

Examples

Completions

python

>>> import jedi >>> code = '''import json; json.l''' >>> script = jedi.Script(code, path='example.py') >>> script <Script: 'example.py' <SameEnvironment: 3.5.2 in /usr>> >>> completions = script.complete(1, 19) >>> completions [<Completion: load>, <Completion: loads>] >>> completions[1] <Completion: loads> >>> completions[1].complete 'oads' >>> completions[1].name 'loads'

Type Inference / Goto

python

>>> import jedi >>> code = '''... def my_func(): ... print 'called' ... ... alias = my_func ... my_list = [1, None, alias] ... inception = my_list[2] ... ... inception()''' >>> script = jedi.Script(code) >>> >>> script.goto(8, 1) [<Name full_name='__main__.inception', description='inception = my_list[2]'>] >>> >>> script.infer(8, 1) [<Name full_name='__main__.my_func', description='def my_func'>]

References

python

>>> import jedi >>> code = '''... x = 3 ... if 1 == 2: ... x = 4 ... else: ... del x''' >>> script = jedi.Script(code) >>> rns = script.get_references(5, 8) >>> rns [<Name full_name='__main__.x', description='x = 3'>, <Name full_name='__main__.x', description='x = 4'>, <Name full_name='__main__.x', description='del x'>] >>> rns[1].line 3 >>> rns[1].column 4

Deprecations

The deprecation process is as follows:

  1. A deprecation is announced in the next major/minor release.
  2. We wait either at least a year and at least two minor releases until we remove the deprecated functionality.