{"id":16544506,"url":"https://github.com/msoedov/broccoli","last_synced_at":"2025-10-11T02:06:21.628Z","repository":{"id":57416395,"uuid":"41673862","full_name":"msoedov/broccoli","owner":"msoedov","description":"A dependency injection package","archived":false,"fork":false,"pushed_at":"2019-10-22T23:48:08.000Z","size":49,"stargazers_count":8,"open_issues_count":4,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-22T11:18:29.113Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/msoedov.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-08-31T12:22:48.000Z","updated_at":"2016-09-17T03:23:59.000Z","dependencies_parsed_at":"2022-09-26T20:11:45.466Z","dependency_job_id":null,"html_url":"https://github.com/msoedov/broccoli","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/msoedov/broccoli","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoedov%2Fbroccoli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoedov%2Fbroccoli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoedov%2Fbroccoli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoedov%2Fbroccoli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msoedov","download_url":"https://codeload.github.com/msoedov/broccoli/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msoedov%2Fbroccoli/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005910,"owners_count":26083994,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11T19:03:01.756Z","updated_at":"2025-10-11T02:06:21.607Z","avatar_url":"https://github.com/msoedov.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Broccoli](broccoli.png?raw=true)\n------------------------------\n[![PyPI](https://img.shields.io/pypi/v/broccoli.svg)]()\n[![Supported versions](https://img.shields.io/pypi/pyversions/broccoli.svg)]()\n[![Build Status](https://travis-ci.org/msoedov/broccoli.svg?branch=master)](https://travis-ci.org/msoedov/broccoli)\n[![Code Climate](https://codeclimate.com/github/msoedov/broccoli/badges/gpa.svg)](https://codeclimate.com/github/msoedov/broccoli)\n![License][license-img]\n\n\n[license-img]: http://img.shields.io/badge/license-MIT-brightgreen.svg\n[license]: http://opensource.org/licenses/MIT\n\nBroccoli is a simple dependency injection package based on type annotations\n\nInstallation\n-----------\n```shell\npip install broccoli\n\n```\n\nFeatures\n--------\n- **Simple** - less than 100 lines of code without external dependencies\n- **Error check** - Function signature check on start up - less errors during refactoring\n- **Fast** - Designed to have zero runtime overhead, all dependencies injected either on module load or application start up.\n- **Powerful** - Auto-discovery of dependencies by package and by module\n- **Convenient** - Hackable and elegant programmatic API. Really easy to start using it.\n\n\nPython 2 support?\n-----------------\nOups, sorry\n\n\nBasic Usage\n-----------\n\nInject dependency to function with type annotations\n\n```python\nfrom broccoli import bind\n\nclass Dependency:\n    pass\n\ndef foo(a, bar:Dependency):\n    print(a, bar)\n\nbind(foo, Dependency())\nfoo(1)  # prints 1 \u003c__main__.Dependency object at 0x11111b7b8\u003e\n```\n\nInject dependency to module/package\n```python\n# module foo.py\n\ndef foo(a, b:DependencyA):\n    print(a, b)\n\n\ndef bar(a, b:DependencyB):\n    print(a, b)\n\n# main.py\nfrom broccoli import inject\nfrom package import foo\n\ninject(foo, DependencyA(), DependencyB())\n\n# or\ninject('package.foo', DependencyA(), DependencyB())\n\n```\n\nExample with decorator wich inject deps on demand\n```python\nfrom brocolli.fixtures.types import *\nfrom broccoli import Dependency\n\n\ndef dependecies():\n    return Db(), Service(), Cache()\n\n\ndefault_dependencies = Dependency(dependecies)\n\n\n@default_dependencies\ndef a(db: Db):\n    return db.query('User').all()\n```\n\nInject deps on application entry point\n```python\n...\n\ndefault_dependencies = Dependency()\n\n\n@default_dependencies\ndef a(db: Db):\n    return db.query('User').all()\n\nif __name__ == '__main__':\n    default_dependencies \u003c\u003c dependecies\n    # or even\n    default_dependencies \u003c\u003c dependecies()\n\n```\n\nTest examples\n--------\n[examples](https://github.com/msoedov/broccoli/tree/master/tests/fixtures)\n\n\nThis looks as dirty hack why should use it?\n---------------------------------------------\nNo reason, you can keep using module level variables and singleton objects. But if you know a good example of unit tests for such code don't hesitate to share it.\n\n\nGetting Help\n------------\n\nFor **feature requests** and **bug reports** [submit an issue\n](https://github.com/msoedov/brocolli/issues) to the GitHub issue tracker for\nBroccoli.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsoedov%2Fbroccoli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsoedov%2Fbroccoli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsoedov%2Fbroccoli/lists"}