Where should I place a Django DRF client module?

14 Views Asked by At

My project consists of several components, among them a django app and a streamlit app. I've designed an API with Django Rest Framework, but I also want an easy way of dealing with it in Python, essentially a client module (that could be caled from the streamlit app, for example). Therefore, I wrote a class DjangoClient inside a module django_client.py, which I placed inside the django project folder (it sounded like the best option as in the future I plan to add more components that make use of such module, and storing a copy inside each component defeats the purpose of a module).

I have each component inside a folder, so my folder structure looks like this:

src
├── djangoapp # django project folder
│   ├── README.md
│   ├── db.sqlite3
│   ├── django_client.py # THIS IS THE FILE I WANT TO IMPORT
│   ├── djangoapp # "core" application
│   │   ├── __init__.py
│   │   ├── admin.py
│   │   ├── asgi.py
│   │   ├── models.py
│   │   ├── serializers.py
│   │   ├── settings.py
│   │   ├── urls.py
│   │   ├── views.py
│   │   └── wsgi.py
│   ├── manage.py
│   └── media
└── streamlit
    └── main.py # THE FILE THAT SHOULD IMPORT django_client.py MODULE

However, it seems that sibling import problems in Python are a very common problem, and after some hours of research I couldn't find a way to reliably import the django_client.py module into main.py without resorting to sys.path hacks. Note that I am running the streamlit app with "streamlit run main.py", so I wouldn't even know how to use the -m flag here (a common solution to import sibling modules). Should django_client.py be somewhere else? Or is there a way to import it?

0

There are 0 best solutions below