I am trying to package a Python module for pip, following the guide here.
One area I would like feedback on is best practices or convention for making my module configurable. The module is a library for talking to federated RESTful services / local datastores, and we use it both as a command-line library as well as a Django app. So I would like it to be manually configurable as well as configurable from Django's settings.py file.
Our current method of doing this is horrible -- it relies on a set of settings.py files inside of the library, which are overwritten whenever we pull from git, not changeable during runtime, etc.
My idea for a solution is to wrap the entire library in its own class, and in the
__init__ method, do something like:
try: from django.conf import settings self._remote_host = settings.REMOTE_HOST except: self._remote_host = DEFAULT_HOST
But that only seems to take care of Django and seems cumbersome -- what if someone wants to use our library with Flask, or something else? Is there a more universal way to make a Python module configurable by external tools plus have a default? Or is this a lost cause, and I should stick to configuration on init via arguments?