{"id":17383794,"url":"https://github.com/numblr/python_di","last_synced_at":"2025-07-22T15:33:53.186Z","repository":{"id":79291419,"uuid":"286853275","full_name":"numblr/python_di","owner":"numblr","description":"Blueprint for Dependency Injection without external framework in Python","archived":false,"fork":false,"pushed_at":"2020-08-14T11:59:35.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T21:14:57.568Z","etag":null,"topics":["dependency-injection","python","python3"],"latest_commit_sha":null,"homepage":"","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/numblr.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-11T21:40:05.000Z","updated_at":"2020-08-14T11:59:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"f407d6a2-db24-48c4-8abd-32e05750658f","html_url":"https://github.com/numblr/python_di","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/numblr/python_di","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numblr%2Fpython_di","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numblr%2Fpython_di/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numblr%2Fpython_di/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numblr%2Fpython_di/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/numblr","download_url":"https://codeload.github.com/numblr/python_di/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/numblr%2Fpython_di/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266520994,"owners_count":23942369,"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-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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","python","python3"],"created_at":"2024-10-16T07:43:48.136Z","updated_at":"2025-07-22T15:33:52.820Z","avatar_url":"https://github.com/numblr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dependency injection pattern for Python\n\nBlueprint for a Dependency Injection (DI) pattern in Python based on container mixins. \n\n## Principle\n\nThe pattern models the dependency order in object instantiation by an invocation chain of provider\nmethods. Provider methods are resolved in a top level container that is composed from individual\ncontainers that are provided by the implementation modules as mixins.\n\nThe following diagram visualizes this pattern with a `component` who's implementation depends on a\n`service`. Instances of `service` are provided by the `ServiceImplContainer`, instances of\n`component` in turn are provided by the `ComponentImplContainer`, which injects a `service`\ninstance into the `component`. The top level `ApplicationContainer` is composed of both of these\ntwo implementation containers. Different implementations of the `service` can be injected into the\n`component` by replacing the `ServiceImplContainer` in the `ApplicationContainer` with any other\ncontainer that provides a `service`. Application code uses the `ApplicationContainer` as entry\npoint to retrieve a `component` (or `service`) instance. \n\n![](doc/Containers.png)\n\nThe red parts in the diagram and the respective `api` modules in code are not needed in Python.\nThey have no functional impact and can be (fully or partially) left out. They serve only the\npurpose of clarity.\n\n## Shortcomings\n\nThis is a very basic approach and comes with some shortcomings:\n\n * You need to write quite some boilerplate code\n * Dependencies are resolved purely by their method name in the container mixins, therefore you \n   need to be careful not to run into name conflicts between different containers. In other words,\n   method names in the container mixins need to be globally unique.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumblr%2Fpython_di","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnumblr%2Fpython_di","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnumblr%2Fpython_di/lists"}