Skip to main content

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.

get help

poetry run python examples/basic.py --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 python ./examples/basic.py

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())),
)
@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(
        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

VAR_TEST_A=Hi poetry run python ./examples/click_args.py -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()
    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:

Hi World False [{'name': 'VAR_TEST_B', 'value': 'World', 'default': 'you', 'global_env': None, 'type': STRING}]
+AKCONFIG VARIABLES-+----------------------------+
| NAME              | VALUE                      |
+-------------------+----------------------------+
| VAR_TEST_A (str)  | Hi                         |
| VAR_TEST_B (str)  | World                      |
| VAR_TEST_C (bool) | False                      |
+-------------------+----------------------------+
| Date              | 2025-02-01 09:35:31.698357 |
+-------------------+----------------------------+

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

akconfig-0.1.11.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

akconfig-0.1.11-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file akconfig-0.1.11.tar.gz.

File metadata

  • Download URL: akconfig-0.1.11.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.16 Linux/6.5.0-1025-azure

File hashes

Hashes for akconfig-0.1.11.tar.gz
Algorithm Hash digest
SHA256 54332bd7c694e1ca872e65aac80f270a3ece6355d7463882790b43dcba11f94d
MD5 c599a36fb0436664e7c687e7961c8001
BLAKE2b-256 379ffca7076812478ad9e304e9f0bd6af5bd74370d782c9d4b4c39b9eba0f2b1

See more details on using hashes here.

File details

Details for the file akconfig-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: akconfig-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.10.16 Linux/6.5.0-1025-azure

File hashes

Hashes for akconfig-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5d3075431c88c59c296021a617192f0ffba12b327bd297914224ff5304b0d8e7
MD5 a30b59f4d8ae8e88564b35577ab2fac5
BLAKE2b-256 907100ed10d2af10d4c906ce348f58b989b1d0de0ad8fee4cbab59f32d695f20

See more details on using hashes here.

Supported by

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