{"id":24678968,"url":"https://github.com/evinism/supplier","last_synced_at":"2025-03-21T18:26:14.161Z","repository":{"id":57472455,"uuid":"338967988","full_name":"evinism/supplier","owner":"evinism","description":"Pass values deeply with Python!","archived":false,"fork":false,"pushed_at":"2021-02-18T23:28:09.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-26T13:19:31.148Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evinism.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-15T04:37:06.000Z","updated_at":"2021-03-26T02:28:15.000Z","dependencies_parsed_at":"2022-08-31T02:11:59.950Z","dependency_job_id":null,"html_url":"https://github.com/evinism/supplier","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evinism%2Fsupplier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evinism%2Fsupplier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evinism%2Fsupplier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evinism%2Fsupplier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evinism","download_url":"https://codeload.github.com/evinism/supplier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244846413,"owners_count":20520119,"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":"2025-01-26T13:19:38.636Z","updated_at":"2025-03-21T18:26:14.130Z","avatar_url":"https://github.com/evinism.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Supplier: Python library for passing values deeply, easily!\n\nHave you ever had a piece of configuration that you want access to deeply in a function, but you don't want to always have to pass it, and you don't want to have a singleton?\n\nThis is for you!\n\n### Example\n\nHere's a basic before/after for passing variables deeply.\n\nBefore:\n```py\ndef outer_function(config):\n  middle_function(config)\n\ndef middle_function(config):\n  inner_function(config)\n  \ndef inner_function(config):\n  # To supply config here, we have to manually pass the config through 2 layers of function calls!\n  do_something_based_on(config)\n  \nouter_function(Config())\n```\n\nAfter:\n```py\nfrom supplier import Supplier, supply\nconfig_supplier = Supplier('config')\n\ndef outer_function():\n  middle_function()\n\ndef middle_function():\n  inner_function()\n  \n@supply(config_supplier)\ndef inner_function(config):\n  # No longer have to manually pass the config through 2 layers!\n  do_something_based_on(config)\n\nwith config_supplier.use(Config()):\n  outer_function()\n```\n\nThis is essentially python contextvars + contextlib in one convenient package\n\n## @supply allows multiple function arguments\n\nSupplier prepends the function's arguments with the supplied value.\n\n```py\n@supply(foo_supplier)\ndef func_with_args(foo, arg1, arg2):\n  print(foo, arg1, arg2)\n\nwith foo_supplier.use(\"foo\"):\n  func_with_args(\"arg1\", \"arg2\")\n```\n\n## @supply works with multiple suppliers\n\nYou can supply multiple variables simultaneously.\n\n```py\n@supply(foo_supplier, bar_supplier)\ndef doubly_provided_func(foo, bar, arg):\n  print(foo, bar, arg)\n\nwith foo_supplier.use(\"foo\"), bar_supplier.use(\"bar\"):\n  doubly_provided_func(\"arg\")\n```\n\n## @supply keeps `self` argument in the same place.\n\nWhen using supply to decorate class method, supply keeps the `self` argument in the same place, for ease of use.\n\n```py\nclass A(Printer):\n  @supply(foo_supplier):\n  def print_foo(self, foo):\n    self.print(foo)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevinism%2Fsupplier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevinism%2Fsupplier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevinism%2Fsupplier/lists"}