A configuration management for global variables in python projects.
Project description
akconfig
A configuration management for global variables in python projects. akconfig is a small python class that takes global variables and lets you manipulate them quickly. the advantage can be that you still need manipulations that are to be changed via arguments, or via environment variables. when executing the example file basic.py, it quickly becomes obvious what this is intended for.
source: https://github.com/dapkdapk/akconfig
pypi.org: https://pypi.org/project/akconfig/
get help
poetry run basic --help
Usage: basic [OPTIONS]
Options:
-c, --config <TEXT TEXT>... Config parameters are: VAR_A, VAR_B, VAR_C,
VAR_D, VAR_E, VAR_F, VAR_G, VAR_H, VARS_MASK
-f, --force-env-vars Set argument if you want force environment
variables
--help Show this message and exit.
example basic
$ poetry run basic
import click
from ak.config import AKConfig
"""
These are global variables
"""
VAR_A = "HELLO WORLD"
VAR_B = 100
VAR_C = 3.14
VAR_D = True
VAR_E = {"a": "b", "c": "d"}
VAR_F = ["a", "b", "c", "d"]
VAR_G = ("a", "b", "c", "d")
VAR_H = "SECRET"
VAR_I = r"^\sTest.*"
VAR_J = "Some text SECRET should be masked"
VARS_MASK = ["VAR_H"]
@click.command()
@click.option(
"-c",
"--config",
multiple=True,
type=(str, str),
help="Config parameters are: {}".format(", ".join(AKConfig.GetGlobals(globals()))),
)
@click.option(
"-f",
"--force-env-vars",
is_flag=True,
help="Set argument if you want force environment variables",
)
@click.option(
"-u",
"--uncolored-print",
is_flag=True,
help="Set argument and output is not colored",
)
def main(config, force_env_vars, uncolored_print):
cfg = AKConfig(
global_vars=globals(),
config_args=config,
mask_keys=VARS_MASK,
force_env_vars=force_env_vars,
uncolored=uncolored_print,
)
cfg.print_config()
if __name__ == "__main__":
main()
output:
+AKCONFIG VARIABLES+----------------------------------+
| NAME | VALUE |
+------------------+----------------------------------+
| VAR_A (str) | HELLO WORLD |
| VAR_B (int) | 100 |
| VAR_C (float) | 3.14 |
| VAR_D (bool) | True |
| VAR_E (dict) | {'a': 'b', 'c': 'd'} |
| VAR_F (list) | ['a', 'b', 'd', 'c'] |
| VAR_G (tuple) | ('a', 'b', 'c', 'd') |
| VAR_H (str) | ***** |
| VAR_I (str) | ^\sTest.* |
| VAR_J (str) | Some text ***** should be masked |
| VARS_MASK (list) | ['VAR_H'] |
+------------------+----------------------------------+
| Date | 2025-01-28 01:41:14.481035 |
+------------------+----------------------------------+
example click arguments
poetry run click-args -b World -c false
import click
from ak.config import AKConfig
VAR_TEST_A = "Hello"
@click.command()
@click.option("-b", "--test-b", envvar="VAR_TEST_B", default="you")
@click.option("-c", "--test-c", envvar="VAR_TEST_C", default=True, type=click.BOOL)
def main(test_b, test_c):
cfg = AKConfig(globals(), None, None)
result = cfg.get_arg_envvar("test_a", "test_b")
print(cfg.VAR_TEST_A, cfg.VAR_TEST_B, cfg.VAR_TEST_C, result)
cfg.print_config()
if __name__ == "__main__":
main()
output:
Hello World False [{'name': 'VAR_TEST_B', 'value': 'World', 'default': 'you', 'global_env': None, 'type': STRING}]
+AKCONFIG VARIABLES-+----------------------------+
| NAME | VALUE |
+-------------------+----------------------------+
| VAR_TEST_A (str) | Hello |
| VAR_TEST_B (str) | World |
| VAR_TEST_C (bool) | False |
+-------------------+----------------------------+
| Date | 2025-01-28 01:34:05.127236 |
+-------------------+----------------------------+
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file akconfig-0.1.7.tar.gz.
File metadata
- Download URL: akconfig-0.1.7.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.7 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6b7fb11474fa76e02ea8215cdad4a567153da00ea1243ced6c6f3ac867fa09f
|
|
| MD5 |
6e7d52d7dccabe88b5de78b69a19bb3d
|
|
| BLAKE2b-256 |
2610e7c2ac20003a40cad7e1382b43b1ceac8a14275551b790e29574aa51b48a
|
File details
Details for the file akconfig-0.1.7-py3-none-any.whl.
File metadata
- Download URL: akconfig-0.1.7-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.0 CPython/3.10.7 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2123ccc396bc09fcf29e39acdbf4fca08214aeef51246f6f693eb366d1041107
|
|
| MD5 |
07499d061460adb73a02e2b8c9163141
|
|
| BLAKE2b-256 |
2e1ce51327df6830b27ad35a38528a4630cf4c55a99b61287a3a5b9fe8a25e7d
|