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:
- if
./logging.yaml
exists, it will be loaded into a dict and used to configure logging (using dictConfig) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file service-bootstrap-0.0.5.dev1677012293.tar.gz
.
File metadata
- Download URL: service-bootstrap-0.0.5.dev1677012293.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f86691d0a6b46c275f62e580c42ce6d0d2dbdb845eedbbe2c72a1b02b9ba988 |
|
MD5 | 4368deb43d0bfa645a071024e0579904 |
|
BLAKE2b-256 | 3f6025f651885df797f1b5371367bbcc604392bdd0be7c40e643db69fc551fab |