1 year ago

#354933

test-img

Peter F

Is there a way to control what can be imported in each package and file in python (fastapi)?

For a large API project we are trying to enforce a folder structure and what package is allowed to be imported from other packages. Is there a package that can check this for you to be used in git pre-commit or CICD?

For example:

  • views are allowed to import anything
  • services are not allowed to import from views
  • repositories are not allowed to import services

In Java i know there is a package called checkstyle that does this with ImportControl. Where it basically checks for a regex in each file.

Is there something similar in some python package ?

python

import

format

controls

0 Answers

Your Answer

Accepted video resources