It loads different configurations depending on the environment variable.
Project description
bjorn
The Bjorn module loads a configuration file for your python script.
Installation
To install bjorn, run this command in your terminal:
$ pip install bjorn
The basics
A settings file is just a Python module with module-level variables. Settings example:
import os
LOGGING_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"standard": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"},
},
"handlers": {
"default": {
"level": "INFO",
"formatter": "standard",
"class": "logging.StreamHandler",
},
"file_handler": {
"level": "INFO",
"filename": "/tmp/mylogfile.log",
"class": "logging.FileHandler",
"formatter": "standard",
},
},
"loggers": {
"job": {
"handlers": ["default"],
"level": os.environ.get("LOGGER_LEVEL", "INFO"),
"propagate": True,
},
},
}
VALUE_TO_TEST = "A"
Because a settings file is a Python module, the following apply:
It doesn’t allow for Python syntax errors.
It can assign settings dynamically using normal Python syntax. For example:
MY_SETTING = [str(i) for i in range(30)]
Designating the settings
JOB_SETTINGS When you use Bjorn, you have to tell it which settings you’re using. Do this by using an environment variable, JOB_SETTINGS.
The value of JOB_SETTINGS should be in Python path syntax, e.g. mysite.settings. Note that the settings module should be on the Python import search path.
Usage
Create a settings.py file in the root of the project. Then you can call it from your script using the following way.
from bjorn.config import settings
if __name__ == '__main__':
print(settings.VALUE_TO_TEST)
History
0.1.0 (2021-01-23)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bjorn-0.1.3.tar.gz
.
File metadata
- Download URL: bjorn-0.1.3.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a4a859ef8f0cc2fcf00e89220679ea13cf3a621fb35b6c870273cf9651ebaf3 |
|
MD5 | 3d202080dfdb3127cc8f86f5169a6eb1 |
|
BLAKE2b-256 | 215015fc728ca43cae97c064a3bf69bb3906dfbfafa9b0d6d341b9d55ef66171 |
File details
Details for the file bjorn-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: bjorn-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 279d82baff38b998de143e40b4a814454a781fe743d2698926ce01f9eb9b82b9 |
|
MD5 | 1158999328d1aca4b1dc3b1ff24f391a |
|
BLAKE2b-256 | 84a04031e7c83fd9c9ca4bf41bbc4b2c2a975d368f7f3af2feb480282266e813 |