{"id":20128415,"url":"https://github.com/teamhide/pythondi","last_synced_at":"2025-08-26T09:13:08.370Z","repository":{"id":36057282,"uuid":"221097115","full_name":"teamhide/pythondi","owner":"teamhide","description":"Python lightweight dependency injection library","archived":false,"fork":false,"pushed_at":"2023-07-28T04:19:22.000Z","size":68,"stargazers_count":52,"open_issues_count":1,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-31T21:36:54.799Z","etag":null,"topics":["dependency-injection","inversion-of-control","ioc-container","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teamhide.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-12T00:41:38.000Z","updated_at":"2025-06-10T14:31:18.000Z","dependencies_parsed_at":"2024-06-19T17:35:46.878Z","dependency_job_id":"3e50f80b-22cd-4752-928e-2118a2f63a31","html_url":"https://github.com/teamhide/pythondi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/teamhide/pythondi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fpythondi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fpythondi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fpythondi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fpythondi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teamhide","download_url":"https://codeload.github.com/teamhide/pythondi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teamhide%2Fpythondi/sbom","scorecard":{"id":871570,"data":{"date":"2025-08-11","repo":{"name":"github.com/teamhide/pythondi","commit":"a1a8a9c20c06504fa491faceac53856782691eff"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Code-Review","score":1,"reason":"Found 2/20 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/teamhide/pythondi/main.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/teamhide/pythondi/main.yml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/main.yml:24","Warn: pipCommand not pinned by hash: .github/workflows/main.yml:27","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 15 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-24T04:24:21.402Z","repository_id":36057282,"created_at":"2025-08-24T04:24:21.402Z","updated_at":"2025-08-24T04:24:21.402Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272201357,"owners_count":24890983,"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-08-26T02:00:07.904Z","response_time":60,"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":["dependency-injection","inversion-of-control","ioc-container","python"],"created_at":"2024-11-13T20:27:03.719Z","updated_at":"2025-08-26T09:13:08.171Z","avatar_url":"https://github.com/teamhide.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pythondi\n[![license]](/LICENSE)\n[![pypi]](https://pypi.org/project/pythondi/)\n[![pyversions]](http://pypi.python.org/pypi/pythondi)\n[![Downloads](https://pepy.tech/badge/pythondi)](https://pepy.tech/project/pythondi)\n\n---\n\npythondi is a lightweight dependency injection library for python\n\nSupport both sync and async functions\n\n## Installation\n\n```python\npip3 install pythondi\n```\n\n## Usage\n\nFirst, you have to binding classes to provider.\n\n```python\nfrom pythondi import Provider\n\n\nprovider = Provider()\nprovider.bind(Repo, SQLRepo)\nprovider.bind(Usecase, CreateUsecase)\n```\n\nAfter binding, you need to configure it to container\n\n```python\nfrom pythondi import configure, configure_after_clear\n\n\n# Inject with configure\nconfigure(provider=provider)\n\n# Or if you want to fresh inject, use `configure_after_clear`\nconfigure_after_clear(provider=provider)\n```\n\nImport inject\n\n```python\nfrom pythondi import inject\n```\n\nAdd type annotations that you want to inject dependencies\n\n```python\nclass Usecase:\n    def __init__(self, repo: Repo):\n        self.repo = repo\n```\n\nAdd decorator\n\n```python\nclass Usecase:\n    @inject()\n    def __init__(self, repo: Repo):\n        self.repo = repo\n```\n\nInitialize class with no arguments\n\n```python\nusecase = Usecase()\n```\n\nOr, you can also inject manually through decorator arguments\n\n```python\nclass Usecase:\n    @inject(repo=SQLRepo)\n    def __init__(self, repo):\n        self.repo = repo\n```\n\nIn this case, do not have to configure providers and type annotation.\n\n## Lazy initializing\n\n```python\nfrom pythondi import Provider\n\n\nprovider = Provider()\nprovider.bind(Repo, SQLRepo, lazy=True)\n```\n\nYou can use lazy initializing through `lazy` option. (default `False`)\n\nFor singleton, use `lazy=False`.\n\n```python\nclass Usecase:\n    @inject(repo=SQLRepo)\n    def __init__(self, repo):\n        self.repo = repo\n```\n\nBy default, manual injection is lazy. If you want a singleton, instantiate it like `repo=SQLRepo()`.\n\n## For test\n\nIn case of test codes, you probably want to use mock objects.\n\nIn that case, you must use keyword arguments.\n\n```python\nclass MockRepo:\n    pass\n\n\n@inject()\ndef test(repo: Repo):\n    return repo\n```\n\n**Yes:**\n```python\ntest(repo=MockRepo())\n```\n\n**No:**\n```python\ntest(MockRepo())\ntest(MockRepo)\n```\n\n## Note\n\nAt the moment of inject, class is automatically initialized.\n\nSo you don't have to initialize your class inside of code.\n\n**Yes:**\n```python\n@inject()\ndef __init__(self, repo: Repo):\n    self.repo = repo\n```\n\n**No:**\n```python\n@inject()\ndef __init__(self, repo: Repo):\n    self.repo = repo()\n```\n\n## General example\n\n```python\nimport abc\n\nfrom pythondi import Provider, configure, configure_after_clear, inject\n\n\nclass Repo:\n    \"\"\"Interface class\"\"\"\n    __metaclass__ = abc.ABCMeta\n\n    @abc.abstractmethod\n    def get(self):\n        pass\n\n\nclass SQLRepo(Repo):\n    \"\"\"Impl class\"\"\"\n    def get(self):\n        print('SQLRepo')\n\n\nclass Usecase:\n    @inject()\n    def __init__(self, repo: Repo):\n        self.repo = repo\n\n\nif __name__ == '__main__':\n    # Init provider\n    provider = Provider()\n\n    # Bind `Impl` class to `Interface` class\n    provider.bind(Repo, SQLRepo)\n\n    # Inject with configure\n    configure(provider=provider)\n\n    # Or if you want to fresh injection, use `configure_after_clear`\n    configure_after_clear(provider=provider)\n\n    # Init class without arguments\n    u = Usecase()\n```\n\n## FastAPI example\n\n```python\nfrom fastapi import FastAPI, APIRouter\n\nfrom pythondi import Provider, configure, inject\nimport abc\n\nrouter = APIRouter()\n\n\nclass Repo:\n    \"\"\"Interface class\"\"\"\n    __metaclass__ = abc.ABCMeta\n\n    @abc.abstractmethod\n    def get(self):\n        pass\n\n\nclass SQLRepo(Repo):\n    \"\"\"Impl class\"\"\"\n    def __init__(self):\n        pass\n\n    def get(self):\n        print('SQLRepo')\n\n\n@router.route('/')\ndef home():\n    usecase = Usecase()\n    usecase.repo.get()\n    return {'hello': 'world'}\n\n\nclass Usecase:\n    @inject()\n    def __init__(self, repo: Repo):\n        self.repo = repo\n\n\ndef create_app():\n    provider = Provider()\n    provider.bind(Repo, SQLRepo)\n    configure(provider=provider)\n    app = FastAPI()\n    app.include_router(router)\n    return app\n\n\nif __name__ == '__main__':\n    app = create_app()\n    app.run(debug=True)\n```\n\n## Flask example\n\n```python\nfrom flask import Flask, Blueprint, jsonify\n\nfrom pythondi import Provider, configure, inject\nimport abc\n\nbp = Blueprint('home', __name__)\n\n\nclass Repo:\n    \"\"\"Interface class\"\"\"\n    __metaclass__ = abc.ABCMeta\n\n    @abc.abstractmethod\n    def get(self):\n        pass\n\n\nclass SQLRepo(Repo):\n    \"\"\"Impl class\"\"\"\n    def __init__(self):\n        pass\n\n    def get(self):\n        print('SQLRepo')\n\n\n@bp.route('/')\ndef home():\n    usecase = Usecase()\n    usecase.repo.get()\n    return jsonify({'hello': 'world'})\n\n\nclass Usecase:\n    @inject()\n    def __init__(self, repo: Repo):\n        self.repo = repo\n\n\ndef create_app():\n    provider = Provider()\n    provider.bind(Repo, SQLRepo)\n    configure(provider=provider)\n    app = Flask(__name__)\n    app.register_blueprint(bp)\n    return app\n\n\nif __name__ == '__main__':\n    app = create_app()\n    app.run(debug=True)\n```\n\n## Sanic example\n```python\nimport abc\n\nfrom sanic import Sanic, Blueprint\nfrom sanic.response import json\n\nfrom pythondi import Provider, configure, inject\n\n\nclass Repo:\n    \"\"\"Interface class\"\"\"\n    __metaclass__ = abc.ABCMeta\n\n    @abc.abstractmethod\n    def get(self):\n        pass\n\n\nclass SQLRepo(Repo):\n    \"\"\"Impl class\"\"\"\n    def __init__(self):\n        pass\n\n    def get(self):\n        print('SQLRepo')\n\n\nbp = Blueprint('home', url_prefix='/')\n\n\n@bp.route('/')\nasync def home(request):\n    usecase = Usecase()\n    usecase.repo.get()\n    return json({'hello': 'world'})\n\n\nclass Usecase:\n    @inject()\n    def __init__(self, repo: Repo):\n        self.repo = repo\n\n\ndef create_app():\n    provider = Provider()\n    provider.bind(Repo, SQLRepo)\n    configure(provider=provider)\n    app = Sanic(__name__)\n    app.blueprint(bp)\n    return app\n\n\nif __name__ == '__main__':\n    app = create_app()\n    app.run(debug=True)\n\n```\n\n## Django example\n\n```python\n\"\"\"\nIn case of django, just put the initializing code inside of django startup\n\nYou can use project folder's __init__.py or urls.py\n\"\"\"\n```\n[license]: https://img.shields.io/badge/License-Apache%202.0-blue.svg\n[pypi]: https://img.shields.io/pypi/v/pythondi\n[pyversions]: https://img.shields.io/pypi/pyversions/pythondi\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamhide%2Fpythondi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteamhide%2Fpythondi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteamhide%2Fpythondi/lists"}