zhanymkanov / fastapi-best-practices

FastAPI Best Practices and Conventions we used at our startup
9.4k stars 701 forks source link

How can i import from the src directory into package #18

Closed tsalkenov closed 1 year ago

tsalkenov commented 1 year ago

using sys.path.append in every file to access src doesn't seem like such a great idea to me. Maybe I'm doing it wrong i don't know a proper way to do this

zhanymkanov commented 1 year ago

It's ok when you have few packages, but once your project grows it's good to explicitly show that the package you are importing is local via from src.notifications import client rather than from notifications import client

tsalkenov commented 1 year ago

So there is no way to avoid using sys.path.append()?

zhanymkanov commented 1 year ago

I think the only reason you have to do that is improper project startup. You can check this template.

In short, I start projects from the root folder with python -m src.main so that interpreter knows the project boundaries and packages

tsalkenov commented 1 year ago

Oh i get it now, my interpreter was treating python files like they were separate. Now i get how it works thank you so much. Your this repository is a lifesaver. Thank you again for letting us learn from your experience