How to include config.py within Python package? #1056
Unanswered
mitches-got-glitches
asked this question in
Q&A
Replies: 1 comment 1 reply
-
From what I've talked to Bruno, Dynaconf was mainly moved forward by webserver/app needs (not libs), so that may help explain some default behaviors. But that doesn't inherently prevent other uses. The init (the way I see it) is only a utility to help get something working from day 0, but in any case (webservers or libraries) you'll have to fine-tune this for a real project.
This seems reasonable to me. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This question seems quite simple but I'm really struggling to find a clear answer. So when you run
dynaconf init
theconfig.py
file is created in the project root along with thesettings.toml
. In order to import this asfrom config import settings
you need to add the project root to your PYTHONPATH. In the docs it looks like you put all of the Validators in the .py file. When a user installs your package I assume you want the config validation rules to be installed with them. So how do you supplyconfig.py
within the main package?The alternative approach I tend to take is to put
config.py
in the top level of the package. Therefore it's already installed on the path when you install the package as editable and is importable withfrom my_package.config import settings
.Is there anything wrong with this approach? What am I missing on the default approach where the file is in the project root?
Beta Was this translation helpful? Give feedback.
All reactions