{"id":20576470,"url":"https://github.com/hazarddede/argresolver","last_synced_at":"2025-06-15T05:34:02.388Z","repository":{"id":57411458,"uuid":"133425773","full_name":"HazardDede/argresolver","owner":"HazardDede","description":"Resolves missing function arguments at runtime","archived":false,"fork":false,"pushed_at":"2019-03-30T10:58:25.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T08:49:49.590Z","etag":null,"topics":["arguments","framework","python3","utility"],"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/HazardDede.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":"2018-05-14T21:54:03.000Z","updated_at":"2019-03-30T10:58:26.000Z","dependencies_parsed_at":"2022-08-27T19:12:41.375Z","dependency_job_id":null,"html_url":"https://github.com/HazardDede/argresolver","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/HazardDede/argresolver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HazardDede%2Fargresolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HazardDede%2Fargresolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HazardDede%2Fargresolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HazardDede%2Fargresolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HazardDede","download_url":"https://codeload.github.com/HazardDede/argresolver/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HazardDede%2Fargresolver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259926947,"owners_count":22933132,"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":["arguments","framework","python3","utility"],"created_at":"2024-11-16T05:45:55.090Z","updated_at":"2025-06-15T05:34:02.344Z","avatar_url":"https://github.com/HazardDede.png","language":"Python","readme":"# ArgResolver v0.3.3\n\n[![PyPI version](https://badge.fury.io/py/argresolver.svg)](https://badge.fury.io/py/argresolver)\n[![Build Status](https://travis-ci.org/HazardDede/argresolver.svg?branch=master)](https://travis-ci.org/HazardDede/argresolver)\n[![Coverage Status](https://coveralls.io/repos/github/HazardDede/argresolver/badge.svg?branch=master)](https://coveralls.io/github/HazardDede/argresolver?branch=master)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nResolver is a simple decorator for resolving (missing) arguments at runtime.\nIt performs various tasks from looking up arguments from the environment variable scope to simple service dependency injection.\n\n1\\.  [Resolver](#resolver)  \n1.1\\.  [Environment](#environment)  \n1.2\\.  [Map](#map)  \n1.3\\.  [Chain](#chain)  \n\n\u003ca name=\"resolver\"\u003e\u003c/a\u003e\n\n## 1\\. Resolver\n\n\u003ca name=\"environment\"\u003e\u003c/a\u003e\n\n### 1.1\\. Environment\n\n```python\n# We inject arguments from the environment variables scope to a simple function\n# We use a `prefix` to minimize clashes with other components\n# username will have a correponding DB_USERNAME, same for password and database\n\nfrom argresolver import Environment\nfrom argresolver.utils import modified_environ  # We use it to alter the environment variables\n\n@Environment()\ndef connect(host, user, password):\n    print(\"Connecting: {user}:{password}@{host}\".format(**locals()))\n\nwith modified_environ(PASSWORD='my_pass'):\n    connect('localhost', 'admin')\n# Prints: Connecting: admin:my_pass@localhost\n```\n\n```python\n# We inject arguments from the environment variables scope \n# to an instance __init__.\n# We use a `prefix` to minimize clashes with other components that have a username / password.\n# Argument username will have a correponding DB_USERNAME, same for password and database\n\nfrom argresolver import Environment\nfrom argresolver.utils import modified_environ  # We use it to alter the environment variables\n\nclass Connection:\n    @Environment(prefix='DB')\n    def __init__(self, username, password, database='default'):\n        self.username = username\n        self.password = password\n        self.database = database\n\n    def __str__(self):\n        # Hint: In a real world example you won't put your password in here ;-)\n        return \"Connection(username='{self.username}', password='{self.password}'\"\\\n        \", database='{self.database}')\".format(self=self)\n\nwith modified_environ(DB_USERNAME='admin', DB_PASSWORD='secret'):\n    conn = Connection()\nprint(str(conn))  # Connection(username='admin', password='secret', database='default')\n```\n\n\u003ca name=\"map\"\u003e\u003c/a\u003e\n\n### 1.2\\. Map\n\n```python\n# We use the Map resolver to override an argument's default value \n# that is better suited for our needs.\n\nfrom argresolver import Map\n\n# Let's assume we cannot touch this code...\nclass Foo:\n    def __init__(self, arg1, arg2='I_dont_like_this_default'):\n        self.arg1 = arg1\n        self.arg2 = arg2\n\n    def __str__(self):\n        return \"Foo(arg1='{self.arg1}', arg2='{self.arg2}')\".format(self=self)\n\n# But we can alter the class and wrap a resolver around the class __init__ \nFoo.__init__ = Map(dict(arg2=\"better_default\"), default_override=True)(Foo.__init__)\n\nfoo = Foo(\"this is arg1\")\nprint(str(foo))  # Foo(arg1='this is arg1', arg2='better_default')\n```\n\n\u003ca name=\"chain\"\u003e\u003c/a\u003e\n\n### 1.3\\. Chain\n\n```python\n# We do some automatic dependency injection with fallback\n\nfrom argresolver import Chain, Const, Map\n\ninject = Chain(\n    Map(dict(service1=\"Service1\", service2=\"Service2\")), \n    Const(\"Fallback Service\")\n)\n\nclass Orchestration:\n    @inject\n    def business_process1(self, service1, service2):\n        print(\"Calling service:\", service1)\n        print(\"Calling service:\", service2)\n\n    @inject\n    def business_process2(self, service1, service3):\n        print(\"Calling service:\", service1)\n        print(\"Calling service:\", service3)\n\norchester = Orchestration()\norchester.business_process1()\n# Prints:\n# Calling service: Service1\n# Calling service: Service2\n\norchester.business_process2()\n# Prints:\n# Calling service: Service1\n# Calling service: Fallback Service\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazarddede%2Fargresolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhazarddede%2Fargresolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazarddede%2Fargresolver/lists"}