{"id":16949653,"url":"https://github.com/tailhook/trafaret-config","last_synced_at":"2025-03-17T08:37:12.698Z","repository":{"id":57476856,"uuid":"63908343","full_name":"tailhook/trafaret-config","owner":"tailhook","description":"A small wrapper around trafaret and yaml that does nice error reporting (python)","archived":false,"fork":false,"pushed_at":"2019-09-04T12:35:28.000Z","size":73,"stargazers_count":41,"open_issues_count":2,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-28T06:59:22.666Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://trafaret-config.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tailhook.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-21T23:17:19.000Z","updated_at":"2023-04-18T10:42:47.000Z","dependencies_parsed_at":"2022-09-12T14:33:14.275Z","dependency_job_id":null,"html_url":"https://github.com/tailhook/trafaret-config","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailhook%2Ftrafaret-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailhook%2Ftrafaret-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailhook%2Ftrafaret-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tailhook%2Ftrafaret-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tailhook","download_url":"https://codeload.github.com/tailhook/trafaret-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243852485,"owners_count":20358271,"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":[],"created_at":"2024-10-13T21:55:43.694Z","updated_at":"2025-03-17T08:37:12.310Z","avatar_url":"https://github.com/tailhook.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"===============\nTrafaret Config\n===============\n\n\n:Status: Stable\n:Documentation: http://trafaret-config.readthedocs.io/\n\n\nThis is a wrapper that loads yaml and checks config using trafaret_ while\nkeeping track of actual lines of file where error has happened. Additionally,\nit can pretty print the error.\n\nBasic Usage:\n\n.. code-block:: python\n\n    import argparse\n    import trafaret\n    from trafaret_config import commandline\n\n    TRAFARET = trafaret.Dict({'x': trafaret.String()})\n\n    def main():\n        ap = argparse.ArgumentParser()\n        commandline.standard_argparse_options(ap, default_config='config.yaml')\n        #\n        # define your command-line arguments here\n        #\n        options = ap.parse_args()\n        config = commandline.config_from_options(options, TRAFARET)\n        pprint.pprint(config)\n\nExample output when there is an error in config (from a `example.py` which\nhas better trafaret than example above)::\n\n    bad.yaml:3: smtp.port: value can't be converted to int\n      -\u003e 'unknown'\n    bad.yaml:4: smtp.ssl_port: value can't be converted to int\n      -\u003e 'NaN'\n    bad.yaml:5: port: value can't be converted to int\n      -\u003e '???'\n\nHelp looks like this::\n\n    usage: example.py [-h] [-c CONFIG] [--print-config] [--print-config-vars] [-C]\n\n    optional arguments:\n      -h, --help            show this help message and exit\n      -c CONFIG, --config CONFIG\n                            Configuration file (default: 'config.yaml')\n      --print-config        Print config as it is read after parsing and exit\n      --print-config-vars   Print variables used in configuration file\n      -C, --check-config    Check configuration and exit\n\n\nSince trafaret-config 2.0 environment variables in the config are replaced\nby default, this means that config like this:\n\n.. code-block:: yaml\n\n    url: http://${HOST}:$PORT/\n\nWill get ``HOST`` and ``PORT`` variables insert from the environment, and if\nvariable does not exist, you will get the following error::\n\n    config.yaml:2: variable 'PORT' not found\n      -\u003e 'http://${HOST}:$PORT/'\n\nLow-level interface, without relying on argparse:\n\n.. code-block:: python\n\n   import sys\n   import trafaret\n   from trafaret_config import ConfigError, read_and_validate\n\n   TRAFARET = trafaret.Dict({'x': trafaret.String()})\n\n   try:\n       config = read_and_validate('config.yaml', TRAFARET)\n   except ConfigError as e:\n       e.output()\n       sys.exit(1)\n\n\n\n.. _trafaret: http://github.com/Deepwalker/trafaret\n\nInstallation\n============\n\n::\n\n    pip install trafaret-config==2.0.2\n\n\nLicense\n=======\n\nLicensed under either of\n\n* Apache License, Version 2.0,\n  (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)\n* MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT)\n  at your option.\n\n------------\nContribution\n------------\n\nUnless you explicitly state otherwise, any contribution intentionally\nsubmitted for inclusion in the work by you, as defined in the Apache-2.0\nlicense, shall be dual licensed as above, without any additional terms or\nconditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailhook%2Ftrafaret-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftailhook%2Ftrafaret-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftailhook%2Ftrafaret-config/lists"}