Skip to main content

It loads different configurations depending on the environment variable.

Project description

bjorn

https://img.shields.io/pypi/v/bjorn.svg https://img.shields.io/travis/juanmcristobal/bjorn.svg Documentation Status Updates

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

bjorn-0.1.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

bjorn-0.1.2-py2.py3-none-any.whl (4.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file bjorn-0.1.2.tar.gz.

File metadata

  • Download URL: bjorn-0.1.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for bjorn-0.1.2.tar.gz
Algorithm Hash digest
SHA256 026f68f3c072470b3ac0fc66612ae6645abed5542a28911b3dd636029319c3a0
MD5 64b2315f56836a20bcdcb5c8c3889670
BLAKE2b-256 3418d6de76f675593d2c0ea85b11af32a758842ed0be7d88d25cc4a32235a136

See more details on using hashes here.

File details

Details for the file bjorn-0.1.2-py2.py3-none-any.whl.

File metadata

  • Download URL: bjorn-0.1.2-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.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for bjorn-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1b7724c1fce009035c64aad8d263a37ff2ac26aee1f3d9e760f4401d94c0fd65
MD5 16361460b0553fcdaaeb04dea52666ac
BLAKE2b-256 c0d15a8254fd4880e28aa404f36548d50009a1b94af190cf7eecb455b98aacc7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page