zhanymkanov/fastapi-best-practices

Circular import

jhoanmartinez opened this issue · 1 comments

How you guys manage to avoid cirular import errors? I am following this structure but circular import just came out.

Usually, I don't get circular imports with that setup. The rule of thumb is to separate global modules at the higher level (e.g. src/schemas.py - for global schemas) and keep packages as isolated as possible, but be very explicit when importing other packages.

In cases, where package A (e.g. src/auth/schemas) requires package B (src/users/schemas) and wise-versa, solution is simple - rethink the structure you are building. Probably, you could combine them into one package or compliment them as a sub-package.