Skip to main content

Framework for setting up service

Project description

service-bootstrap

Helper for starting up a service in python

Function start_service()

Usage:

from bootstrap.bootstrap import start_service

config, logger, timezone = start_service()

Configuration

start_service() will look for a config YAML file and load it into a dict, using the following algorithm:

  • if the env variable CONFIG is defined, it will be used to determine the location of the config file
  • otherwise a file ./config.yaml is expected to be present

The file will be parsed and returned as a first returned variable

Logging

start_service() will configure the logger will in the following way:

  1. if ./logging.yaml exists, it will be loaded into a dict and used to configure logging (using dictConfig)
  2. otherwise the default logging format will be applied, which is defined as writing logs on INFO level to stdout

Additionally, start_service() will look for ./loglevels.yaml file with the following structure:

'apscheduler.scheduler': 'ERROR',
'apscheduler.executors.default': 'WARN'

and use this file to configure per-logger log levels. Note that the settings two mentioned above ('apscheduler.scheduler': 'ERROR' and 'apscheduler.executors.default': 'WARN') will be used as a default.

Finally, start_service() will create a logger called main, log two messages

logger.info("Starting application!")
logger.info("Your timezone is %s" % timezone)

and return this logger as a second returned variable

Timezone

The third returned variable will contain the local timezone as a string (f.ex Europe/Warsaw), detected using the following algorithm:

  • if the env variable TIMEZONE is defined, it will be used
  • otherwise timezone will be autodetected using tzlocal

Note on YAML loading

All yaml files are loaded using load_yaml() and may contain env variables!

Function load_yaml()

Usage:

from bootstrap.utils import load_yaml

content = load_yaml("file.yaml")

It will load the content of file.yaml into a dict resolving ENV variables

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file service_bootstrap-0.0.5.dev1677012300-py3-none-any.whl.

File metadata

File hashes

Hashes for service_bootstrap-0.0.5.dev1677012300-py3-none-any.whl
Algorithm Hash digest
SHA256 2593dedf85615f33a4e060643a1d1881ec5247c5b1360737d16e190829310e14
MD5 553687a7b7bc8f7a31d09be3b27b7a63
BLAKE2b-256 481e2b96822b5b9a660cb6d2fde4f9eb40fc65becf3ced7436e969a5f006c016

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