Debian Codegraph @

docs/quick_start/3.-api.md

raw
1 # Programmatic Python API Usage
2
3 In addition to the powerful command line interface, isort exposes a complete Python API.
4
5 To use the Python API, `import isort` and then call the desired function call:
6
7 <script id="asciicast-346604" src="https://asciinema.org/a/346604.js" async></script>
8
9 Every function is fully type hinted and requires and returns only builtin Python objects.
10
11 Highlights include:
12
13 - `isort.code` - Takes a string containing code, and returns it with imports sorted.
14 - `isort.check_code` - Takes a string containing code, and returns `True` if all imports are sorted correctly, otherwise, `False`.
15 - `isort.stream` - Takes an input stream containing Python code and an output stream. Outputs code to output stream with all imports sorted.
16 - `isort.check_stream` - Takes an input stream containing Python code and returns `True` if all imports in the stream are sorted correctly, otherwise, `False`.
17 - `isort.file` - Takes the path of a Python source file and sorts the imports in-place.
18 - `isort.check_file` - Takes the path of a Python source file and returns `True` if all imports contained within are sorted correctly, otherwise, `False`.
19 - `isort.place_module` - Takes the name of a module as a string and returns the categorization determined for it.
20 - `isort.place_module_with_reason` - Takes the name of a module as a string and returns the categorization determined for it and why that categorization was given.
21
22 For a full definition of the API see the [API reference documentation](../reference/isort.rst) or try `help(isort)` from an interactive interpreter.