{"id":19951390,"url":"https://github.com/grimen/python-config2","last_synced_at":"2025-05-03T18:34:06.432Z","repository":{"id":37822165,"uuid":"133857345","full_name":"grimen/python-config2","owner":"grimen","description":"Python environment configuration simplified - highly inspired by `node-config`.","archived":false,"fork":false,"pushed_at":"2023-11-29T18:00:46.000Z","size":119,"stargazers_count":20,"open_issues_count":14,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-31T09:12:30.609Z","etag":null,"topics":["application","config","configuration","configurations","env","environment","environments","node-config","python","python-config","settings"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/config2","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/grimen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-17T19:09:19.000Z","updated_at":"2024-02-24T01:26:01.000Z","dependencies_parsed_at":"2024-06-20T23:27:06.709Z","dependency_job_id":"fa751433-841c-4238-a3d8-e4156968affa","html_url":"https://github.com/grimen/python-config2","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-config2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-config2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-config2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-config2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grimen","download_url":"https://codeload.github.com/grimen/python-config2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224370068,"owners_count":17299969,"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":["application","config","configuration","configurations","env","environment","environments","node-config","python","python-config","settings"],"created_at":"2024-11-13T01:07:50.880Z","updated_at":"2024-11-13T01:07:51.492Z","avatar_url":"https://github.com/grimen.png","language":"Python","readme":"\n# `config2` [![PyPI version](https://badge.fury.io/py/config2.svg)](https://badge.fury.io/py/config2) [![Build Status](https://travis-ci.com/grimen/python-config2.svg?branch=master)](https://travis-ci.com/grimen/python-config2) [![Coverage Status](https://codecov.io/gh/grimen/python-config2/branch/master/graph/badge.svg)](https://codecov.io/gh/grimen/python-config2)\n\n*Python environment configuration simplified.*\n\n\n## Introduction\n\n**Config2** (for Python) - which is highly inspired by [`node-config`](https://github.com/lorenwest/node-config) - organizes hierarchical configurations for your app deployments.\n\nIt lets you define a set of default parameters, and extend them for different deployment environments (development, qa, staging, production, etc.).\n\nConfigurations are stored in **configuration files** within your application, and can be overridden and extended by **environment variables**, **command line parameters**, or **external sources**.\n\nThis gives your application a consistent configuration interface shared among a growing list of npm modules also using node-config.\n\n**NOTE:** This project is more or less in pair with [`node-config`](https://github.com/lorenwest/node-config) implementation, with exception for some fluff that could be considered too much magic such as deployment specific *multi-instance deployments* which I so far haven't found any good motivation for, and some other questionable advanced features mentioned in the wiki pages.\n\n\n## Project Guidelines\n\n...based on [`node-config`](https://github.com/lorenwest/node-config) project guidelines:\n\n- *Simple* - Get started fast\n- ~~*Powerful* - For multi-node enterprise deployment~~ - excluded because [with power comes responsability](https://en.wikipedia.org/wiki/Principle_of_least_astonishment)\n- *Flexible* - Supporting multiple config file formats\n- *Lightweight* - Small file and memory footprint\n- *Predictable* - Well tested foundation for module and app developers\n\n\n## Install\n\nInstall using **pip**:\n\n```sh\n$ pip install config2\n```\n\n\n## Use\n\n**1.** Assuming we have a **python application** project...\n\n```\nsome_project\n└── app.py\n```\n\n`app.py` - some app making serious **\u0026#36;\u0026#36;\u0026#36;**\n\n```python\n# business logic\nprint('$$$')\n```\n\n\n**2.** Let's add some environment specific **config files**...\n\n```\nsome_project\n└── config\n    ├── default.yml\n    ├── development.yml\n    ├── foo.yml\n    └── production.yml\n└── app.py\n```\n\n`default.yml` - with some bogus nested settings shared for all environments (defaults)\n\n```yaml\na1: DEFAULT 1\na2:\n    b1: [1, 2, 3]\n    b2:\n        -   foo\n        -   bar\n    b3:\n        c1: 1\n        c2: \"DEFAULT 2\"\n```\n\n`development.yml` - with some bogus nested settings overriden for `development` environment (overriden)\n\n```yaml\na2:\n    b2:\n        -   DEV 1\n    b3:\n        c2: \"DEV 2\"\nsome_key_only_for_dev: true\n```\n\n`foo.yml` - with some bogus nested settings overriden for `foo` environment (overriden)\n\n```yaml\na2:\n    b2:\n        -   FOO 1\n    b3:\n        c2: \"FOO 2\"\nsome_key_only_for_foo: true\n```\n\n`production.yml` - with some bogus nested settings overriden for `production` environment (overriden)\n\n```yaml\na2:\n    b2:\n        -   PROD 1\n    b3:\n        c2: \"PROD 2\"\nsome_key_only_for_prod: true\n```\n\n\n**3.** Let's now **run the app** using **various environments**...\n\n`$ python app.py`\n\n```python\nfrom config2.config import config\n\nconfig.get_env() # =\u003e None\nconfig.get() # =\u003e {'a1': 'DEFAULT 1', 'a2': {'b1': [1, 2, 3], 'b2': ['foo', 'bar'], 'b3': {'c1': 1, 'c2': 'DEFAULT 2'}}}\n\nconfig.a1 # =\u003e 'DEFAULT 1'\nconfig.a2 # =\u003e {'b1': [1, 2, 3], 'b2': ['foo', 'bar'], 'b3': {'c1': 1, 'c2': 'DEFAULT 2'}}\nconfig.a2.b3.c2 # =\u003e 'DEFAULT 2'\n\nprint('$$$')\n```\n\n`$ ENV=development python app.py`\n\n```python\nfrom config2.config import config\n\nconfig.get_env() # =\u003e 'development'\nconfig.get() # =\u003e {'a1': 'DEFAULT 1', 'a2': {'b1': [1, 2, 3], 'b2': ['DEV 1'], 'b3': {'c1': 1, 'c2': 'DEV 2'}}, 'some_key_only_for_dev': True}\n\nconfig.a1 # =\u003e 'DEFAULT 1'\nconfig.a2 # =\u003e {'b1': [1, 2, 3], 'b2': ['DEV 1'], 'b3': {'c1': 1, 'c2': 'DEV 2'}}\nconfig.a2.b3.c2 # =\u003e 'DEV was here 2'\n\nconfig.some_key_only_for_dev # =\u003e True\n\nconfig.some_key_only_for_foo # =\u003e AttributeError\nconfig.some_key_only_for_prod # =\u003e AttributeError\n\nprint('$$$')\n```\n\n`$ ENV=foo python app.py`\n\n```python\nfrom config2.config import config\n\nconfig.get_env() # =\u003e 'foo'\nconfig.get() # =\u003e {'a1': 'DEFAULT 1', 'a2': {'b1': [1, 2, 3], 'b2': ['FOO 1'], 'b3': {'c1': 1, 'c2': 'FOO 2'}}, 'some_key_only_for_foo': True}\n\nconfig.a1 # =\u003e 'DEFAULT 1'\nconfig.a2 # =\u003e {'b1': [1, 2, 3], 'b2': ['FOO 1'], 'b3': {'c1': 1, 'c2': 'FOO 2'}}\nconfig.a2.b3.c2 # =\u003e 'FOO was here 2'\n\nconfig.key_only_for_foo # =\u003e True\n\nconfig.some_key_only_for_dev # =\u003e AttributeError\nconfig.some_key_only_for_prod # =\u003e AttributeError\n\nprint('$$$')\n```\n\n`$ ENV=production python app.py`\n\n```python\nfrom config2.config import config\n\nconfig.get_env() # =\u003e 'production'\nconfig.get() # =\u003e {'a1': 'DEFAULT 1', 'a2': {'b1': [1, 2, 3], 'b2': ['PROD 1'], 'b3': {'c1': 1, 'c2': 'PROD 2'}}, 'some_key_only_for_foo': True}\n\nconfig.a1 # =\u003e 'DEFAULT 1'\nconfig.a2 # =\u003e {'b1': [1, 2, 3], 'b2': ['PROD 1'], 'b3': {'c1': 1, 'c2': 'PROD 2'}}\nconfig.a2.b3.c2 # =\u003e 'PROD was here 2'\n\nconfig.some_key_only_for_prod # =\u003e True\n\nconfig.some_key_only_for_dev # =\u003e AttributeError\nconfig.some_key_only_for_foo # =\u003e AttributeError\n\nprint('$$$')\n```\n\netc.\n\n\n**4.** Optionally, let's now introduce custom **config environment variables**...\n\n\n```\nsome_project\n└── config\n    ├── custom-environment-variables.yml\n    ├── default.yml\n    ├── development.yml\n    ├── foo.yml\n    └── production.yml\n└── app.py\n```\n\n`custom-environment-variables.yml` - with mappings of config keys to environment variables\n\n```yaml\na1: A1\na2:\n    b3:\n        c2: C2\n```\n\n**5.** Let's now **run the app** using **custom environment variables** to override config...\n\n`$ A1=x C2=y python app.py`\n\n```python\nfrom config2.config import config\n\nconfig.get_env() # =\u003e None\nconfig.get() # =\u003e {'a1': 'x', 'a2': {'b1': [1, 2, 3], 'b2': ['foo', 'bar'], 'b3': {'c1': 1, 'c2': 'y'}}}\n\nconfig.a1 # =\u003e 'x'\nconfig.a2 # =\u003e {'b1': [1, 2, 3], 'b2': ['foo', 'bar'], 'b3': {'c1': 1, 'c2': 'y'}}\nconfig.a2.b3.c2 # =\u003e 'y'\n\nprint('$$$')\n```\n\n\n## Test\n\nClone down source code:\n\n```sh\n$ make install\n```\n\nRun **colorful tests**, with only native environment (dependency sandboxing up to you):\n\n```sh\n$ make test\n```\n\nRun **less colorful tests**, with **multi-environment** (using **tox**):\n\n```sh\n$ make test-tox\n```\n\n\n## About\n\nThis project was mainly initiated - in lack of existing alternatives - to be used at our work at **[Markable.ai](https://markable.ai)** to have common code conventions between various programming environments where **Python** (research, CV, AI) and **Node.js** (I/O, APIs, UIs, scripts) currently are most used.\n\n\n## License\n\nReleased under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimen%2Fpython-config2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrimen%2Fpython-config2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimen%2Fpython-config2/lists"}