Integrating with ruff

If you rely on sqliteimport’s auto-loading of .sqlite3 files on the PYTHONPATH, the import sqliteimport line needs to appear before third-party modules:

import os
import sys

import sqliteimport

import boto3
import requests

However, ruff copies isort’s behavior and will sort these lines alphabetically, breaking the imports:

import os
import sys

import boto3
import requests
import sqliteimport  # <--- Sorted to the bottom. Bad!

It also copies flake8’s behavior and will throw an F401 error to flag that the sqliteimport module appears to be unused.

There are several ways to resolve these issues.

Import sorting: custom section

You can configure ruff to put sqliteimport into a custom section that always sorts before third-party packages:

pyproject.toml
[tool.ruff.lint.isort.sections]
sqliteimport = ["sqliteimport"]

[tool.ruff.lint.isort]
section-order = [
    "future",
    "standard-library",
    "sqliteimport",  # <-- Add this above 'third-party'
    "third-party",
    "first-party",
    "local-folder",
]
ruff.toml
[lint.isort.sections]
sqliteimport = ["sqliteimport"]

[lint.isort]
section-order = [
    "future",
    "standard-library",
    "sqliteimport",  # <-- Add this above 'third-party'
    "third-party",
    "first-party",
    "local-folder",
]

Result:

import os
import sys

import sqliteimport

import boto3
import requests

Import sorting: force-to-top

You can force sqliteimport to the top of the third party section:

pyproject.toml
[tool.ruff.lint.isort]
force-to-top = ["sqliteimport"]
ruff.toml
[lint.isort]
force-to-top = ["sqliteimport"]

Result:

import os
import sys

import sqliteimport
import boto3
import requests

F401 errors: Ignore it

You can add a comment to the end of the line to disable ruff’s flake8 F401 error:

import os
import sys

import sqliteimport  # noqa: F401

import boto3
import requests