Imports should always be written at the top of the file, after any module comments and docstrings.
Imports should be divided according to what is being imported. There are generally three groups:
- Standard library imports (Python’s built-in modules)
- Related third party imports (modules that are installed and do not belong to the current application)
- Local application imports (modules that belong to the current application)
Each group of imports should be separated by a blank space.