Skip to content

Home

Import Linter Import Linter

Lint your Python architecture.

Package version Python versions CI status BSD license


Import Linter allows you to impose constraints on the imports between your Python modules.

It also provides a browser-based user interface for exploring the architecture of any Python package.

Get started Try the Interactive UI


How it works

Let's say your Python project looks like this:

myproject
├── __init__.py
├── blue/
└── green/

After installation, create a file called .importlinter:

# .importlinter

[importlinter]
root_package = myproject

[importlinter:contract:one]
name = Green must not import blue
type = forbidden
source_modules = myproject.green
forbidden_modules = myproject.blue

Then, running lint-imports will error if any modules in myproject.green import from myproject.blue.

That's just a simple example: Import Linter supports lots of different contract types, and you can even create your own!

Contract types

Forbidden


Prevent one set of modules being imported by another.

Read more

Protected


Prevent modules from being directly imported, except by modules in an allow-list.

Read more

Layers


Enforce a 'layered architecture'.

Read more

Independence


Prevent a set of modules depending on each other.

Read more

Acyclic siblings


Forbid dependency cycles between siblings.

Read more

Custom contract types


Design your own architecture.

Read more