Metadata-Version: 2.4
Name: fejao_config_parser
Version: 0.0.17
Summary: A Python package for parsing configuration from various sources such as files, environment variables, and command-line arguments.
Author-email: fejao <mail@fejao.de>
License-Expression: MIT
Project-URL: Homepage, https://gitlab.com/fejao/config_parser
Project-URL: Repository, https://gitlab.com/fejao/config_parser
Project-URL: Issues, https://gitlab.com/fejao/config_parser/-/issues
Keywords: configuration,parser,yaml,json,ini,toml,environment,terminal
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Environment :: Other Environment
Classifier: Topic :: Utilities
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: System :: Shells
Classifier: Topic :: Terminals
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pyaml_env>=1.0.0
Requires-Dist: argparse>=1.4.0
Requires-Dist: configparser>=5.0.0
Requires-Dist: tomli>=2.2.1

# fejao-config-parser

[![PyPI version](https://img.shields.io/pypi/v/fejao-config-parser)](https://pypi.org/project/fejao-config-parser/)
[![License](https://img.shields.io/pypi/l/fejao-config-parser)](https://pypi.org/project/fejao-config-parser/)
[![Pipeline](https://gitlab.com/fejao/config_parser/badges/main/pipeline.svg)](https://gitlab.com/fejao/config_parser/-/pipelines)
[![Coverage](https://gitlab.com/fejao/config_parser/badges/main/coverage.svg)](https://gitlab.com/fejao/config_parser)
[![CVE Scan](https://img.shields.io/endpoint?url=https://fejao.gitlab.io/config_parser/badges/cve.json)](https://gitlab.com/fejao/config_parser/-/pipelines)

This is a package for setting up the variables that you need to you on your project from a list of dictionaries.

I was tired of everytime that I needed to set a project that should have input/variables to be set from a configuration file, environment variables or from terminal to write this code again and again. Then the unit-test , lint, pep. And so on and on...

I hope that you also find this tiredsome work not needed anymore from using this package.

- ## Links
  - [Repository](https://gitlab.com/fejao/config_parser)
  - [Source Code Documentation](https://fejao-config-parser.readthedocs.io/en/latest/)

- ## Installing
  For using this package you need to install it with:
  ```bash
  pip install fejao-config-parser
  ```

  You can import it to your code with:
  ```python
  from fejao_config_parser import my_config
  ```

- ## Configuration

  - ### Structure
    You need to set a list of dictionaries such as:
    ```python
    example_vaviables = [
      {
        <VARIABLE_1_CONFIGURATION>
      },
      {
        <VARIABLE_2_CONFIGURATION>
      },
      ...
      ...
      ...
      {
        <VARIABLE_N_CONFIGURATION>
      }
    ]
    ```

  - ### Dictionary entry for a variable
    Dictionary keys for setting a variable are:
    - **name**
      - The name of the variable that will be accessed at your project
      - This key is **required** to be set.
    - **type**
      - The type of this variable to be set, it will type-cast it as the type set here.
      - This key is **required** to be set.
      - Possible type of variables:
        - **string**
        - **bool**
        - **int**
        - **float**
        - **list**
        - **dict**
    - **default**
      - The default value of the variable to be set if any other methods were parsed.
      - This key is **required** to be set.
    - **env_name**
      - The name of the environment variable that should be read.
      - This key is **NOT required** to be set.
    - **terminal_help**
      - The name of the environment variable that should be read.
      - This key is **NOT required** to be set.
    - **terminal_name**
      - The variable name to be read from terminal. Example: *example_string*, it can be parsed at the terminal like *--example_string <VAR_VALUE>*
      - This key is **NOT required** to be set.
    - **terminal_name_short**
      - The variable short name to be read from terminal. Example: *es*, it can be parsed at the terminal like *-es <VAR_VALUE>*
      - This key is **NOT required** to be set.


  - ### Example
    ```python
    example_variables = [
        {
          "name": "example_string",
          "type": "string",
          "default": "default_string_value",
          "env_name": "EXAMPLE_STRING",
          "terminal_help": "Example of a string terminal variable.",
          "terminal_name": "example_string",
          "terminal_name_short": "es",
        },
        {
          "name": "example_bool",
          "type": "bool",
          "default": False,
          "terminal_help": "Example of a boolean terminal variable.",
          "terminal_name": "example_bool",
          "terminal_name_short": "eb",
        },
        {
          "name": "example_int",
          "type": "int",
          "default": 42,
          "env_name": "EXAMPLE_INT",
        },
        {
          "name": "example_float",
          "type": "float",
          "default": 4.2,
        },
        {
          "name": "example_list",
          "type": "list",
          "default": ["1", "2", "3"],
          "env_name": "EXAMPLE_LIST",
          "terminal_help": "Example of a list terminal variable.",
          "terminal_name": "example_list",
          "terminal_name_short": "el",
        },
        {
          "name": "example_dictionary",
          "type": "dict",
          "default": {"key1": "value1", "key2": "value2"},
          "env_name": "EXAMPLE_DICTIONARY",
          "terminal_help": "Example of a dictionary terminal variable.",
          "terminal_name": "example_dictionary",
          "terminal_name_short": "ed",
        },
    ]

    ```

- ## How to use it
  For calling the **my_config** function the possible keys are:
  - **config**
    - The list of dictionaries to be set as variables.
    - This key is **required** to be set.
  - **config_file**
    - The path of the configuration file to be used for reading the variables values.
    - This key is **NOT required** to be set.
    - Type of files that can be parsed:
      - **yaml**
      - **json**
      - **toml**
      - **ini**
        - Values should be set at the **[default]** section
        - Still don't know how till this date people keep using *ini* files.
  - **description**
    - Description of you project when running on terminal with the '--help' output.
    - This key is **NOT required** to be set.
  - **debug**
    - Boolean of setting up the output in terminal from the variables that were set using the package.
    - This key is **NOT required** to be set.

  - ### Example
    ```python
    config = my_config(
      config=example_variables,
      config_file="/tmp/foo.yaml",
      description="My project is AMAZING and not done with vibe-coding",
      debug=True
    )
    ```

  - ### Accessing the variables
    For accessing the variables is easy as:
    ```python
    from fejao_config_parser import my_config

    example_variables = [
        {
          "name": "example_string",
          "type": "string",
          "default": "default_string_value",
          "env_name": "EXAMPLE_STRING",
        }
    ]
    config = my_config(config=example_variables)

    print(f"example_string: {config.example_string}")
    ---> default_string_value
    ```

- ## To Do
  This package at the moment it's not finished yet, just trying to publish on pypi.org at the moment
  - [x] Finish README_PACKAGE.md file (The one to be publish on pypi.org)
  - [X] Add the package code to git
  - [X] Add lint tests
  - [X] Add pep tests
  - [x] Add unit-test
  - [x] Document the code (for generating the mkdocs)
  - [X] Add repository badges to the PyPi page
  - CI-CD for
    - [x] testing
    - [x] CVE tests
    - [x] building
    - [x] generate documentation
    - auto publishing
      - [x] readthedocs
      - [x] pypi
