Configuration tool for all Navigator Services Tool for accessing Config info from different sources.
Project description
Navigator NavConfig
NavConfig is a configuration tool for getting variables from environment and other sources. Is used by Navigator Framework, but is possible to use in other applications as well.
Navigator NavConfig can load Configuration directives from different sources:
- Environment files (.env)
- Memcached Variables
- INI files (using configParser)
- Redis Server
The main goal of NavConfig is centralize configuration access in a single and immutable unique point of truth.
NavConfig can be shared across several modules.
Motivation
Any Application require too many configuration options, some configuration options need to be secrets, credentials, etc, and also, can be dependable of the environment an application runs (development, testing, production, etc.).
Instead of creating python files, we are using python-dotenv + INI files to separate concerns (secrets vs configuration options), NavConfig support also getting data instead of INI files from YAML or TOML files (for complex types).
Installation
pip install navconfig
Quickstart
First of all, let's create a simple configuration environment.
Creates a directory for an .INI file and the environment (.env) file.
mkdir {env,etc}
put a .env file inside of the "env" folder, the first line is the directive to know where the "INI" file lives (even if we can put the . INI file outside of the current dir).
the directory tree is very clear:
|- myapp/
| |- __init__.py
| |- env/
| | |- .env
| | |- dev/
| | |- .env
| | |- prod/
| | |- .env
| |- etc/
| | |- myconfig.ini
| | ...
# file: .env
CONFIG_FILE=etc/myconfig.ini
APP_NAME=My App
Then, in your code, call navconfig "config" object, and start getting your environment variables inside your application.
from navconfig import config
APP_NAME = config.get('APP_NAME')
# the result is "My App".
but also you can use config as a object:
from navconfig import config
APP_NAME = config.APP_NAME
# the result is "My App".
Working with Environments
NavConfig can load all environment variables (and the .INI files associated within the .env file) from different directories, every directory works as a new Environment and you can split your configuration for different environments, like this:
env/
.
├── dev
| |- .env
├── prod
| |- .env
├── staging
| |- .env
└── experimental
| |- .env
Then, you can load your application using the "ENV" environment variable:
ENV=dev python app.py
Configure Logging
NavConfig has owns logging facility, if you load logging_config from Navconfig, you will get a logging configuration using the Python dictConfig format.
also, if you put an environment variable called "logstash_enabled = True", there is a ready to use Logging facility using Logstash.
import logging
from navconfig.logging import (
logdir,
loglevel,
logging_config
)
from logging.config import dictConfig
dictConfig(logging_config)
To use just the logger as expected with logging.getLogger(), e.g.
logger = logging.getLogger('MY_APP_NAME')
logger.info('Hello World')
By default, the current logging configuration make echo to the standard output:
[INFO] 2022-03-11 19:31:39,408 navigator: Hello World
Custom Settings
with Navconfig, users can create a python module called "settings.py" on package "settings" to create new configuration options and fine-tune their configuration.
|- myapp/
| |- settings/
| |- __init__.py
| |- settings.py
on "settings.py", we can create new variables using python code:
from navconfig import config, DEBUG
print('::: LOADING SETTINGS ::: ')
# we are in local aiohttp development?
LOCAL_DEVELOPMENT = (DEBUG is True and sys.argv[0] == 'run.py')
SEND_NOTIFICATIONS = config.get('SEND_NOTIFICATIONS', fallback=True)
And those variables are reachable using "navconfig.conf" module:
from navconfig.conf import LOCAL_DEVELOPMENT
if LOCAL_DEVELOPMENT is True:
print('We are in a Local instance.')
Dependencies
- ConfigParser
- Python-Dotenv
- pytomlpp
- PyYAML
- redis
- pylibmc
Requirements
- Python >= 3.8
- asyncio (https://pypi.python.org/pypi/asyncio/)
- python-dotenv
Contribution guidelines
Please have a look at the Contribution Guide
- Writing tests
- Code review
- Other guidelines
Who do I talk to?
- Repo owner or admin
- Other community or team contact
License
NavConfig is released under MIT license.
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 Distributions
Built Distributions
Hashes for navconfig-1.5.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7c08d3579a4f1d5aec4146faa19aba4cccd4f510b084beaa6bdd635d29c7b45 |
|
MD5 | fa56c6e39a84ee6345fd2ba161d8d304 |
|
BLAKE2b-256 | 23dd598ab6fe8873081327831c9bb2a6cebd61ae811b73d936b914c7139c1aa3 |
Hashes for navconfig-1.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e38f6c5d9bb4b2de29b279b5d9d4e7388ac8b9aedd312e840d03426e0b0f3be8 |
|
MD5 | 4c021bd3d4473268a7492787d2519f62 |
|
BLAKE2b-256 | 41eb13b7dfb0841768509de3afbee643808aa3c37569d48a7ed2c10a88f3c74d |
Hashes for navconfig-1.5.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | feee64728fde357f28e130752f1b3f7b77d9a1150f133b65ac1f4d1c766689bf |
|
MD5 | 46064297adb87b30fe7fe238fa744304 |
|
BLAKE2b-256 | dfccf819a08b76ac700c39f5559ff3155b8eaa47d5ed2792f8cd7e001656f447 |