{"id":16513220,"url":"https://github.com/hmiladhia/configdmanager","last_synced_at":"2025-03-02T10:18:22.319Z","repository":{"id":62564380,"uuid":"244375276","full_name":"hmiladhia/ConfigDmanager","owner":"hmiladhia","description":"A simple configuration files manager package","archived":false,"fork":false,"pushed_at":"2020-03-27T16:17:36.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-29T09:02:14.803Z","etag":null,"topics":[],"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/hmiladhia.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":"2020-03-02T13:16:17.000Z","updated_at":"2020-03-27T16:17:39.000Z","dependencies_parsed_at":"2022-11-03T16:00:38.669Z","dependency_job_id":null,"html_url":"https://github.com/hmiladhia/ConfigDmanager","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2FConfigDmanager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2FConfigDmanager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2FConfigDmanager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hmiladhia%2FConfigDmanager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hmiladhia","download_url":"https://codeload.github.com/hmiladhia/ConfigDmanager/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241488197,"owners_count":19970829,"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-11T16:08:10.382Z","updated_at":"2025-03-02T10:18:22.277Z","avatar_url":"https://github.com/hmiladhia.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ConfigDmanager\n\n## Installation\n\nA simple pip install will do :\n\n```bash\npython -m pip install ConfigDmanager\n```\n\n## Use\n\n- Suppose we have two Configuration files ( of json type ) :\n  - ParentConfig.json :\n\n    ```json\n    {\n    \"__name\": \"ParentConfig\",\n    \"param1\": \"Value 1\"\n    }\n    ```\n    \n  - MainConfig.json :\n    \n    - The **__parent** parameter specifies the path to another configuration file that will give us default values ( Think of it as inheritance ). \n    - The text contained between brackets will be reinterpreted in runtime : \n    \n    in the example below **${param1}** will be reinterpreted as \"Value 1\"\n    \n    - The use of environment variables for sensitive data like passwords is also possible : through this text **${os_environ[password]}**\n    - You can also read the content of a text file with a simple : **${read_file[file_path]}** as shown in the example below.\n\n    ```json\n    {\n      \"__name\": \"MainConfig\",\n      \"__parent\": \"demo.ParentConfig\",\n      \"param2\": \"Value 2 and ${param1}\",\n      \"user_info\": {\"user\": \"username\", \"password\": \"${os_environ[password]}\"},\n      \"long_text\": \"${read_file[./demo.py]}\"\n    }\n    ```\n\n\n\n- To import those configuration using **configDmanager**, use this demo code :\n\n```python\nfrom configDmanager import import_config\n\n\nclass RandomClass:\n    def __init__(self, param1, param2, user_info, long_text):\n        print(f\"param1: {param1}\")\n        print(f\"param2: {param2}\")\n        print(f'my user: {user_info.user}')\n        print(f'my user: {user_info.password}')\n        print(f'my long text: \"{long_text[:40]}\"')\n\n\nconfig = import_config('MainConfig')\n\nprint(\"## Object 1\")\nobj = RandomClass(**config)\n\n\n# You can also select specific keys\nprint(\"## Object 2\")\nanother_obj = RandomClass(param2='Another Value', long_text=\"Not so long\", **config[['param1', 'user_info']])\n\n```\n\n\n\n## Export Config file\n\nYou can export a Config by simply using the **export_config** function\n\n```python\nfrom configDmanager import export_config, Config\n\nconfig = Config({'my_param': 'my_value'})\n\nexport_config(config, 'NewConfig')\n```\n\nIf you wish to modify an existing config, you can use **update_config** function :\n\n```python\nfrom configDmanager import update_config\n\n# You can use a dict to update Config values\nupdate_config({'param' : 'value'}, 'MyConfig')\n\n# You can also use a callable that takes the config returns a dict\nupdate_config(lambda conf: {'numeric': conf['numeric'] + 1}, 'MyConfig')\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmiladhia%2Fconfigdmanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhmiladhia%2Fconfigdmanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhmiladhia%2Fconfigdmanager/lists"}