{"id":24511424,"url":"https://github.com/theherk/figgypy","last_synced_at":"2025-04-14T08:21:48.433Z","repository":{"id":57429288,"uuid":"44401494","full_name":"theherk/figgypy","owner":"theherk","description":"A simple configuration parser for Python","archived":false,"fork":false,"pushed_at":"2019-09-24T04:30:57.000Z","size":126,"stargazers_count":64,"open_issues_count":0,"forks_count":11,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-27T21:52:15.684Z","etag":null,"topics":["configuration","configuration-parser","gnupg","kms","python","python-gnupg"],"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/theherk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-16T17:49:18.000Z","updated_at":"2025-03-17T13:32:57.000Z","dependencies_parsed_at":"2022-08-27T17:01:24.415Z","dependency_job_id":null,"html_url":"https://github.com/theherk/figgypy","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theherk%2Ffiggypy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theherk%2Ffiggypy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theherk%2Ffiggypy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theherk%2Ffiggypy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theherk","download_url":"https://codeload.github.com/theherk/figgypy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844038,"owners_count":21170506,"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","configuration-parser","gnupg","kms","python","python-gnupg"],"created_at":"2025-01-22T00:37:44.053Z","updated_at":"2025-04-14T08:21:48.388Z","avatar_url":"https://github.com/theherk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"figgypy\n=======\n\n[![Chat on Gitter](https://badges.gitter.im/theherk/figgypy.svg)](https://gitter.im/theherk/figgypy?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Build Status](https://travis-ci.org/theherk/figgypy.svg)](https://travis-ci.org/theherk/figgypy)\n\nA simple configuration parser.\n\nInstallation\n------------\n\n    pip install figgypy\n\nUsage\n-----\n\n``` python\nimport figgypy\ncfg = figgypy.set_config(conf_file)\ncfg.get_value('somevalue', optional_default)\n# or\ncfg.values['somevalue']\n# or\ncfg.values.get('somevalue', optional_default)\n# or\nfiggypy.get_value('somevalue', optional_default)\n```\n\nConfig object can be created with a filename only, relative path, or absolute path.\nIf only name or relative path is provided, look in this order:\n\n1. current directory\n2. `~/.config/\u003cfile_name\u003e`\n3. `/etc/\u003cfile_name\u003e`\n\nIt is a good idea to include you `__package__` in the file name.\nFor example, `cfg = Config(os.path.join(__package__, 'config.yaml'))`.\nThis way it will look for `your_package/config.yaml`,\n`~/.config/your_package/config.yaml`, and `/etc/your_package/config.yaml`.\n\n### Features ###\n\n#### Supports multiple formats ####\n\nThe configuration file currently supports json, _xml*_, and yaml.\n\n_* note_ - xml will work, but since it requires having only one root, all of the configuration will be in a dictionary named that root. See examples below.\n\n#### Global configuration (optional) ####\n\n``` python\n# a.py\nfrom figgypy import Config, set_config\ncfg = Config(config_file='config.yaml')\nfiggypy.set_config(cfg)\n\n# b.py\nimport figgypy\nfiggypy.get_value('somevalue')\n```\n\n#### No file needed ####\n\n``` python\nimport figgypy\ncfg = figgypy.Config()\ncfg.set_value('somedict', {'a': 'aye', 'b': 'bee'})\n```\n\n#### Optional decryption ####\n\n_note_: By default each is configured to run the decryption routine. This can be disabled.\n\n``` python\nimport figgypy\ncfg = figgypy.Config(config_file='config.yaml', decrypt_gpg=False, decrypt_kms=False)\ncfg.decrypt_kms = True\n# configuration is reloaded and decrypted\n```\n\n#### Reconstruct with updated settings ####\n\nYou can run Config.setup to reconstruct the same Config object with new settings. Like this:\n\n``` python\n# in shared.py\nimport figgypy\ncfg = figgypy.Config()\nfiggypy.set_config(cfg)\n\n# in worker.py\nimport figgypy\ncfg = get_config()\ncfg.setup(config_file=file_, kms_decrypt=False, gpg_config=gpgconf)\n```\n\nThese changes should also make testing in your applications easier, because in the tests you can reload a different configuration on the same object:\n\n``` python\nimport figgypy\nfrom mylib import totest\ntotest.config_file = 'tests/resources/config.yaml'\n```\n\nExamples\n--------\n\n### json ###\n\n```json\n{\n    \"db\": {\n        \"url\": \"mydburl.com\",\n        \"name\": \"mydbname\",\n        \"user\": \"myusername\",\n        \"pass\": \"correcthorsebatterystable\"\n    },\n    \"log\": {\n        \"file\": \"/var/log/cool_project.log\",\n        \"level\": \"INFO\"\n    }\n}\n```\n\n    cfg = Config('theabove.json')\n\nThis yields object `cfg` with attributes `db` and `log`, each of which are dictionaries.\n\n### xml ###\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cconfig\u003e\n    \u003cdb\u003e\n        \u003curl\u003emydburl.com\u003c/url\u003e\n        \u003cname\u003emydbname\u003c/name\u003e\n        \u003cuser\u003emyusername\u003c/user\u003e\n        \u003cpass\u003ecorrecthorsebatterystable\u003c/pass\u003e\n    \u003c/db\u003e\n    \u003clog\u003e\n        \u003cfile\u003e/var/log/cool_project.log\u003c/file\u003e\n        \u003clevel\u003eINFO\u003c/level\u003e\n    \u003c/log\u003e\n\u003c/config\u003e\n```\n\n    cfg = Config('theabove.xml')\n\nThis yields object `cfg` with attribute `config`, which is the complete dictionary.\n\n### yaml ###\n\n```yaml\ndb:\n  url: mydburl.com\n  name: mydbname\n  user: myusername\n  pass: correcthorsebatterystable\nlog:\n  file: /var/log/cool_project.log\n  level: INFO\n```\n\n    cfg = Config('theabove.yaml')\n\nThis yields object `cfg` with attributes `db` and `log`, each of which are dictionaries. This is the exact same behaviour as json, which makes sense given the close relationship of yaml and json.\n\nSecrets\n--------\n\nIt is possible to use gpg to store PGP and KMS encrypted secrets in a config file.\n\n```yaml\ndb:\n  host: db.heck.ya\n  pass: |\n    -----BEGIN PGP MESSAGE-----\n    Version: GnuPG v2\n\n    hQIMAzf92ZrOUZL3ARAAgWexav8+pc2lnqISEuQafFZrqYI0pU3xCuMXnFZp+hpU\n    gb0LsaExZ136p4ATIinFHuaLt94hFx7gULgqoSigt/2fubnUCsOGedq122xYZdtV\n    Ep/24WPVQPcMVIP9pDTJTk82A41BQsOrVYorAGjjB13zFizizYHApNTcWKr4/gfR\n    jmCqAX5qusXB84fXBecCJ886uEQI2v7+Vxnk+fQMqNt3ybd/uLuBLShMSygr6uLX\n    zktyeZvP2QqPSWe0OpttdcvD792/SI/CTznsjbMe0wr1L81csEQcj++4o5wJop3Y\n    mbQvG/FxeDdRi2aCxh7JK2xdCsrQzXKTNG2QZMwWqatB5Lb6lJ1mNiJQGX2YK+nI\n    lbjy5Cp2lHlNxa9QfB+KglueMnH9gDku5YqBDos6rCEuqK/aTDdMx0V7YGYTamZ3\n    3Za+OGi+hl/+4WX2gm+bOM2WWrIysiu9k1HMI1/onui/3hr1nClR8rGb4a5qDlpg\n    yRrt7LuLRU4vGXpYm05dXlUeI3uT04ur/DwLo32ujnPo3dc8LFegX8N8p1LLS9vq\n    vvrvXRnWsgeAvAYFBprbEYcz7sOU04HM9OGcyjYREMs3Ih6H2oBi3GavJ2x0MG75\n    M9JSTu/yytD8GCM3s+3RncKuEAxfZIk1Gbdz0pjb+U6G43qq8/vQPKtKuAeqJHDS\n    SAER9YkKqbp0y85LbhUWNWPpHQ2zy8WB71TfYE6vBP5qjoxiqP/QGWjT/3jhCY+t\n    5k7R6XqvdvbSu1avFlEgApknzn94I+gsWQ==\n    =QuDe\n    -----END PGP MESSAGE-----\n```\n\nIf you are using json, you'll need newlines. I achieved the following example with `cat the_above.yaml | seria -j -`.\n\n```json\n{\n    \"db\": {\n        \"host\": \"db.heck.ya\",\n        \"pass\": \"-----BEGIN PGP MESSAGE-----\\nVersion: GnuPG v2\\n\\nhQIMAzf92ZrOUZL3ARAAgWexav8+pc2lnqISEuQafFZrqYI0pU3xCuMXnFZp+hpU\\ngb0LsaExZ136p4ATIinFHuaLt94hFx7gULgqoSigt/2fubnUCsOGedq122xYZdtV\\nEp/24WPVQPcMVIP9pDTJTk82A41BQsOrVYorAGjjB13zFizizYHApNTcWKr4/gfR\\njmCqAX5qusXB84fXBecCJ886uEQI2v7+Vxnk+fQMqNt3ybd/uLuBLShMSygr6uLX\\nzktyeZvP2QqPSWe0OpttdcvD792/SI/CTznsjbMe0wr1L81csEQcj++4o5wJop3Y\\nmbQvG/FxeDdRi2aCxh7JK2xdCsrQzXKTNG2QZMwWqatB5Lb6lJ1mNiJQGX2YK+nI\\nlbjy5Cp2lHlNxa9QfB+KglueMnH9gDku5YqBDos6rCEuqK/aTDdMx0V7YGYTamZ3\\n3Za+OGi+hl/+4WX2gm+bOM2WWrIysiu9k1HMI1/onui/3hr1nClR8rGb4a5qDlpg\\nyRrt7LuLRU4vGXpYm05dXlUeI3uT04ur/DwLo32ujnPo3dc8LFegX8N8p1LLS9vq\\nvvrvXRnWsgeAvAYFBprbEYcz7sOU04HM9OGcyjYREMs3Ih6H2oBi3GavJ2x0MG75\\nM9JSTu/yytD8GCM3s+3RncKuEAxfZIk1Gbdz0pjb+U6G43qq8/vQPKtKuAeqJHDS\\nSAER9YkKqbp0y85LbhUWNWPpHQ2zy8WB71TfYE6vBP5qjoxiqP/QGWjT/3jhCY+t\\n5k7R6XqvdvbSu1avFlEgApknzn94I+gsWQ==\\n=QuDe\\n-----END PGP MESSAGE-----\"\n    }\n}\n```\n\nTo store a KMS secret, just add the `_kms` key to the configuration file.\n\n```yaml\ndb:\n  host: db.heck.ya\n  pass:\n    _kms: your KMS encrypted value\n```\n\nSee [below](#kms) for instructions on generating this value.\n\nThat's easy, right? Now this value will be decrypted and available just like you had typed in the value in the configuration file.\n\n### Passed in parameters ###\n\nThese can also be passed in as arguments when initializing.\n\n```python\naws_config = {'aws_access_key_id': aws_access_key_id,\n              'aws_secret_access_key': aws_secret_access_key,\n              'region_name': 'us-east-1'}\ngpg_config = {'homedir': 'noplace/like/home',\n              'keyring': 'pubring.kbx'}\ncfg = figgypy.Config('config.yaml', aws_config=aws_config, gpg_config=gpg_config)\n```\n\n### To encrypt a value ###\n\n#### GPG ####\n\n    echo -n \"Your super secret password\" | gpg --encrypt --armor -r KEY_ID\n\nAdd the resulting armor to your configuration where necessary. If you are using yaml, this is very simple. Here is an example:\n\n#### KMS ####\n\n    aws kms encrypt --key-id 'alias/your-key' --plaintext \"your secret\" --query CiphertextBlob --output text\n\nor the preferred method:\n\n```python\nfrom figgypy.util import kms_encrypt\nencrypted = kms_encrypt('your secret', 'key or alias/key-alias', optional_aws_config)\n```\n\nThanks\n------\n\nThis tool uses [Seria](https://github.com/rtluckie/seria) to serialize between supported formats. Seria is a great tool if you want convert json, xml, or yaml to another of the same three formats.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheherk%2Ffiggypy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheherk%2Ffiggypy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheherk%2Ffiggypy/lists"}