{"id":22316667,"url":"https://github.com/developerstoolbox/profiles-config-package","last_synced_at":"2025-10-05T22:58:46.316Z","repository":{"id":241750781,"uuid":"807494127","full_name":"DevelopersToolbox/profiles-config-package","owner":"DevelopersToolbox","description":"A basic package for managing profile based configuration files.","archived":false,"fork":false,"pushed_at":"2025-09-29T04:58:19.000Z","size":238,"stargazers_count":1,"open_issues_count":8,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-29T06:23:26.590Z","etag":null,"topics":["config","configparser","configuration","wolfsoftware"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevelopersToolbox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":".github/CODEOWNERS","security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["WolfSoftware","TGWolf"]}},"created_at":"2024-05-29T07:56:59.000Z","updated_at":"2025-09-29T04:53:57.000Z","dependencies_parsed_at":"2024-05-30T00:16:14.832Z","dependency_job_id":"8635a552-ea70-40a2-be80-150a2250e8bf","html_url":"https://github.com/DevelopersToolbox/profiles-config-package","commit_stats":null,"previous_names":["developerstoolbox/profiles-config-package"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/DevelopersToolbox/profiles-config-package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevelopersToolbox%2Fprofiles-config-package","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevelopersToolbox%2Fprofiles-config-package/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevelopersToolbox%2Fprofiles-config-package/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevelopersToolbox%2Fprofiles-config-package/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevelopersToolbox","download_url":"https://codeload.github.com/DevelopersToolbox/profiles-config-package/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevelopersToolbox%2Fprofiles-config-package/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278532353,"owners_count":26002346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","configparser","configuration","wolfsoftware"],"created_at":"2024-12-03T23:07:24.430Z","updated_at":"2025-10-05T22:58:46.296Z","avatar_url":"https://github.com/DevelopersToolbox.png","language":"Python","readme":"\u003c!-- markdownlint-disable --\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/\"\u003e\n        \u003cimg src=\"https://cdn.wolfsoftware.com/assets/images/github/organisations/developerstoolbox/black-and-white-circle-256.png\" alt=\"DevelopersToolbox logo\" /\u003e\n    \u003c/a\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/actions/workflows/cicd.yml\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/DevelopersToolbox/profiles-config-package/cicd.yml?branch=master\u0026label=build%20status\u0026style=for-the-badge\" alt=\"Github Build Status\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/blob/master/LICENSE.md\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/license/DevelopersToolbox/profiles-config-package?color=blue\u0026label=License\u0026style=for-the-badge\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/created-at/DevelopersToolbox/profiles-config-package?color=blue\u0026label=Created\u0026style=for-the-badge\" alt=\"Created\"\u003e\n    \u003c/a\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/releases/latest\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/v/release/DevelopersToolbox/profiles-config-package?color=blue\u0026label=Latest%20Release\u0026style=for-the-badge\" alt=\"Release\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/releases/latest\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/release-date/DevelopersToolbox/profiles-config-package?color=blue\u0026label=Released\u0026style=for-the-badge\" alt=\"Released\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/releases/latest\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/commits-since/DevelopersToolbox/profiles-config-package/latest.svg?color=blue\u0026style=for-the-badge\" alt=\"Commits since release\"\u003e\n    \u003c/a\u003e\n    \u003cbr /\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/blob/master/.github/CODE_OF_CONDUCT.md\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Code%20of%20Conduct-blue?style=for-the-badge\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/blob/master/.github/CONTRIBUTING.md\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Contributing-blue?style=for-the-badge\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/blob/master/.github/SECURITY.md\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Report%20Security%20Concern-blue?style=for-the-badge\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/DevelopersToolbox/profiles-config-package/issues\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Get%20Support-blue?style=for-the-badge\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## Overview\n\nProfiles Config is a Python package designed to handle configuration files with profiles, key-value pairs, and comments. This package\nprovides functionalities to load and preprocess configuration files, manage comments and whitespace, retrieve profiles and key-value pairs,\ndisplay the current configuration, and convert the configuration to a dictionary format.\n\nLike many of our packages this was developed as part of another project, but we felt others might be able to make use of it.\n\n## Features\n\n- **Load and preprocess configuration files**: Reads the configuration file, removes comments and extra spaces.\n- **Handle comments and whitespace**: Processes configuration files to ensure clean and accurate data.\n- **Retrieve profiles and key-value pairs**: Access specific profiles and their associated key-value pairs.\n- **Display the current configuration**: Provides a formatted string representation of the current configuration.\n- **Convert the configuration to a dictionary format**: Allows for easy manipulation and access of the configuration data.\n\n## Installation\n\nTo install the `profiles-config` package, use pip:\n\n```bash\npip install wolfsoftware.profiles-config\n```\n\n## Usage\n\nHere is an example of how to use the `ConfigHandler` class from the `profiles-config` package:\n\n```python\nfrom wolfsoftware.profiles_config import ConfigHandler\n\n# Example usage\nif __name__ == \"__main__\":\n    config_handler = ConfigHandler(\"config.ini\")\n    print(\"All Profiles:\", config_handler.list_profiles())\n    print(\"Profile 'profile name 1':\", config_handler.get_profile(\"profile name 1\"))\n    print(\"Value of 'some key' in 'profile name 1':\", config_handler.get_value(\"profile name 1\", \"some key\"))\n    print(\"Current Config:\\n\" + config_handler.display_config())\n    print(\"Config as dict:\\n\", config_handler.get_config())\n```\n\n## Example Config File\n\n```\n[  profile name 1  ]\n# This is a comment for some key\nsome key = some value\n\n# This is a random comment\n# This is a random comment also\n[profile name 2]  # Comment 1\nkeys1 = value\nkeys2 = another value  # comment 2\n\n[profile name 3]  # Comment 1\nkeys1 = value\nkeys2 = another value  # comment 2\n\n# more comments\n# comments to end the file\n# more comments\n```\n\n\u003e Note the spaces prefixing and suffixing the 'profile name 1' entry. These are stripped as part of the load and cleanse phase.\n\nOnce the config file has been loaded, parsed and cleansed the internal representation is a Python dictionary, which would look like this:\n\n```\n{\n    'profile name 1': {\n        'some key': 'some value'\n    },\n    'profile name 2': {\n        'keys1': 'value',\n        'keys2': 'another value'\n    }, \n    'profile name 3': {\n        'keys1': 'value', \n        'keys2': 'another value'\n    }\n}\n```\n\nIf you use display_config() then the output would look like this:\n\n```\n[profile name 1]\nsome key = some value\n\n[profile name 2]\nkeys1 = value\nkeys2 = another value\n\n[profile name 3]\nkeys1 = value\nkeys2 = another value\n```\n\n## Class Documentation\n\n### ConfigHandler\n\nA class to manage and manipulate configuration files.\n\n#### Attributes\n\n- **filepath**: str - Path to the configuration file.\n\n#### Methods\n\n- **`__init__(self, filepath: str, preserve_case: Optional[bool] = False)`**: Initializes the ConfigHandler with the path to the configuration file.\n- **`preprocess_file(self) -\u003e str`**: Reads and preprocesses the configuration file to remove comments and extra spaces.\n- **`load_config(self) -\u003e None`**: Loads and processes the configuration file, checking for formatting errors and duplicates.\n- **`get_config(self) -\u003e Dict`**: Returns the entire configuration as a dictionary.\n- **`get_profile(self, profile_name: str) -\u003e Dict[str, str]`**: Returns a dictionary of key-value pairs for a given profile.\n- **`get_value(self, profile_name: str, key_name: str) -\u003e str`**: Returns the value for a specific key in a given profile.\n- **`list_profiles(self) -\u003e List[str]`**: Returns a list of all profile names in the configuration file.\n- **`display_config(self) -\u003e str`**: Returns the current configuration as a formatted string.\n\n\u003e If you set preserve_case=True it will preserve the case for both sections and keys, otherwise is will lowercase BOTH.\n\n### Method Details\n\n- **`__init__(self, filepath: str, preserve_case: Optional[bool] = False)`**:\n  - Initializes the ConfigHandler with the path to the configuration file.\n  - **Arguments**:\n    - `filepath` (str): Path to the configuration file.\n    - `preserve_case` Optional[bool]: Override the default and preserve case sensitivity for names.\n\n- **`preprocess_file(self) -\u003e str`**:\n  - Reads and preprocesses the configuration file to remove comments and extra spaces.\n  - **Returns**:\n    - str: A string of the preprocessed configuration file.\n\n- **`load_config(self) -\u003e None`**:\n  - Loads and processes the configuration file, checking for formatting errors and duplicates.\n  - **Raises**:\n    - `FileNotFoundError`: If the configuration file does not exist.\n    - `ValueError`: If there are duplicate keys in a section or parsing errors.\n\n- **`get_config(self) -\u003e Dict`**:\n  - Returns the entire configuration as a dictionary.\n  - **Returns**:\n    - Dict: A dictionary representation of the entire configuration.\n\n- **`get_profile(self, profile_name: str) -\u003e Dict[str, str]`**:\n  - Returns a dictionary of key-value pairs for a given profile.\n  - **Arguments**:\n    - `profile_name` (str): The name of the profile.\n  - **Returns**:\n    - Dict[str, str]: A dictionary of key-value pairs for the given profile.\n  - **Raises**:\n    - `KeyError`: If the profile is not found in the configuration.\n\n- **`get_value(self, profile_name: str, key_name: str) -\u003e str`**:\n  - Returns the value for a specific key in a given profile.\n  - **Arguments**:\n    - `profile_name` (str): The name of the profile.\n    - `key_name` (str): The name of the key.\n  - **Returns**:\n    - str: The value associated with the key in the given profile.\n  - **Raises**:\n    - `KeyError`: If the profile or key is not found in the configuration.\n\n- **`list_profiles(self) -\u003e List[str]`**:\n  - Returns a list of all profile names in the configuration file.\n  - **Returns**:\n    - List[str]: A list of all profile names.\n\n- **`display_config(self) -\u003e str`**:\n  - Returns the current configuration as a formatted string.\n  - **Returns**:\n    - str: The formatted string representation of the configuration.\n\n\u003cbr /\u003e\n\u003cp align=\"right\"\u003e\u003ca href=\"https://wolfsoftware.com/\"\u003e\u003cimg src=\"https://img.shields.io/badge/Created%20by%20Wolf%20on%20behalf%20of%20Wolf%20Software-blue?style=for-the-badge\" /\u003e\u003c/a\u003e\u003c/p\u003e\n","funding_links":["https://github.com/sponsors/WolfSoftware","https://github.com/sponsors/TGWolf"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperstoolbox%2Fprofiles-config-package","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeveloperstoolbox%2Fprofiles-config-package","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperstoolbox%2Fprofiles-config-package/lists"}