{"id":22332963,"url":"https://github.com/clmoreno/confvalidator","last_synced_at":"2025-08-12T22:41:45.752Z","repository":{"id":43625849,"uuid":"71679358","full_name":"clmoreno/ConfValidator","owner":"clmoreno","description":"Python package to easily parse INI style configuration files.","archived":false,"fork":false,"pushed_at":"2016-11-13T22:36:21.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-01T11:06:36.806Z","etag":null,"topics":["configuration-file","ini-style","init","parser","python"],"latest_commit_sha":null,"homepage":null,"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/clmoreno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-23T03:23:00.000Z","updated_at":"2016-10-23T06:05:36.000Z","dependencies_parsed_at":"2022-09-13T11:01:42.267Z","dependency_job_id":null,"html_url":"https://github.com/clmoreno/ConfValidator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clmoreno%2FConfValidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clmoreno%2FConfValidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clmoreno%2FConfValidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clmoreno%2FConfValidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clmoreno","download_url":"https://codeload.github.com/clmoreno/ConfValidator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245606424,"owners_count":20643178,"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","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":["configuration-file","ini-style","init","parser","python"],"created_at":"2024-12-04T04:21:02.405Z","updated_at":"2025-03-26T07:22:59.559Z","avatar_url":"https://github.com/clmoreno.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"#ConfValidator\nConfValidator is a python3 package to easily parse **INI style configuration files**.\n\nYou can create a ConfValidator object and add the expected options that the configuration file have, then validate the configuration file and it will produce a dictionary with the configuration you expect.\n\n##Getting started:\n\n###Installation\n\n```bash\npip install ConfValidator\n```\nor\n```bash\neasy_install ConfValidator\n```\n\n###Basic Validation\n\n```python\n# Expamle\n\nimport ConfValidator\n\n# Create the object\nmy_config  = ConfValidator.ConfValidator('/Path/to/my/configFile.cfg')\n\n# Add simple option to the expected configuration.\nmy_config.add_option(option='username', required=True)\n\n# Add a selction to the expected configuration.\nmy_config.add_selection(options=['password','ssk-key'], required=True)\n\n# Validate the configuration\nmy_config.validate()\n\n# If no errors parsing and validating the configuration file, get resultant dictionary.\nmy_config.config\n\n```\n\n###add_option()\nThis operation allows to add an expected option to the ConfValidator object. \n\nAs an example assume you need the user name in the configuration file, so you can use add_option() as follows.\n```python\n# Expamle\n\nmy_config.option(option='user', required=True)\n```\n\n#####Params\n```python\n:param option: \u003cString\u003e \u003crequired\u003e Name of the option.\n:param required: \u003cbool\u003e If True the option must be present in the configuration file. Default: False\n:param valid_values: \u003clist\u003e If specified, the option must contain some of these values.\n:param default_value: \u003cString\u003e If value or option are not present this is the default value. Default: None\n```\n\n\n###add_selection()\nSome times is needed to have one of many of options in the configuration file, this operation allows to add a selection of options to the ConfValidator object.\n\nAs an example assume you need an authentication method for your app, it can be ssh-key, password or token.\nYou need only one of them, so you can use add_selection() as follows.\n```python\n# Expamle\n\nmy_config.selection(options=['ssh-key', 'password', 'token'], required=True)\n```\n\n#####Params\n```python\n:param options: \u003clist\u003e \u003crequired\u003e A list of valid option in the configuration file, one of this options must be present in the configuration file.\n:param required: \u003cbool\u003e If True the option must be present in the configuration file. Default: False\n:param valid_values: :param valid_values: \u003clist\u003e If specified the option must contain some of these values.\n:param default_value:  \u003cString\u003e If value is not present this is the default value. Default: None\n:param default_option:  \u003cString\u003e If option is not present this is the default value. Default: None\n```\n\n\n###validate()\nMethod to validate the INI configuration. This method parse and evaluate each section and option to always return a valid dictionary with a valid configuration.\nNo argument need.\nNo value is returned by this method.\n```python\n# Usage\n\n# Validate configuration\nmy_config.validate()\n\n# Get configuration\nprint(my_config.conf)\n```\n\n\n###get_conf()\nThis method parse validate and returns the configuration dictionary.\nThe difference between get_conf() and validate() is that validate() only parse and validate the configuration, get_conf() parse validate and returns the configuration dictionary in one statement. \n\n```python\n# Usage\nmy_config.get_conf()\n```\n\n###valid_values argument\nCan limit the value in the configuration to allow only one of the specified values.\n\n```python\n# Expamle\n\n# Any other value than user or user2 is not allowed\nmy_config.option(option='user', required=True, valid_values=['user1', 'user2'])\n```\n\n\n###default_value argument\nIf the specified option is not present this will be the default value.\n\n```python\n# Expamle\n\n# If option is not present the value will be Administrator\nmy_config.option(option='user', required=True, default_value='Administrator')\n```\n\n## Default section  *[DEFAULT]*\n\nThe default section is designed to put the default values for options in case they are not defined on specific sections.\n - The values in the *DEFAULT* section overrides the \"default_value\" and \"default_options\" in add_option() or add_selection() methods.\n - The values in sections overrides all the *DEFAULT* values.\n \n### Example:\n```INI\n[DEFAULT]\n# This will be used when no authentication is defined\nauthentication = ldap\n\n[section1]\n# This section will use the default values (\"ldap\") because no authentication was specified.\npassword = 12345678\nuser = test_user\n\n[section2]\n# This authentication explicity speficy the authentication method, so no default authentication will be used.\nauthentication = local\npassword = 87654321\nuser = user_test\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclmoreno%2Fconfvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclmoreno%2Fconfvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclmoreno%2Fconfvalidator/lists"}