{"id":18863057,"url":"https://github.com/ramonhagenaars/jacked","last_synced_at":"2025-04-14T13:06:06.617Z","repository":{"id":62572021,"uuid":"183658095","full_name":"ramonhagenaars/jacked","owner":"ramonhagenaars","description":"Python on roids!","archived":false,"fork":false,"pushed_at":"2019-07-05T19:19:27.000Z","size":86,"stargazers_count":5,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T09:14:28.448Z","etag":null,"topics":["dependency-injection","python","python3","python35","python36","python37"],"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/ramonhagenaars.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-26T16:05:01.000Z","updated_at":"2019-10-29T08:57:41.000Z","dependencies_parsed_at":"2022-11-03T19:53:35.563Z","dependency_job_id":null,"html_url":"https://github.com/ramonhagenaars/jacked","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramonhagenaars%2Fjacked","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramonhagenaars%2Fjacked/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramonhagenaars%2Fjacked/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramonhagenaars%2Fjacked/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ramonhagenaars","download_url":"https://codeload.github.com/ramonhagenaars/jacked/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223634012,"owners_count":17176872,"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":["dependency-injection","python","python3","python35","python36","python37"],"created_at":"2024-11-08T04:36:33.182Z","updated_at":"2024-11-08T04:36:33.646Z","avatar_url":"https://github.com/ramonhagenaars.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/ramonhagenaars/jacked.svg?branch=master)](https://travis-ci.org/ramonhagenaars/jacked)\n[![Pypi version](https://badge.fury.io/py/jacked.svg)](https://badge.fury.io/py/jsons)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ramonhagenaars/jacked/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ramonhagenaars/jacked/?branch=master)\n[![codecov](https://codecov.io/gh/ramonhagenaars/jacked/branch/master/graph/badge.svg)](https://codecov.io/gh/ramonhagenaars/jacked)\n\n\n_NOTE: This project is in ALPHA state_\n# jacked ~ *python on roids*\n\n* A light and easy to use dependency injection framework.\n* Inject _objects_, _functions_, _classes_ or _lists_ containing any of these.\n* Let **jacked** automatically discover your injectables in a package.\n* Loose coupling _on the juice_!\n* Excellent for making your code testable!\n\n## Install\n```\npip install jacked\n```\n\n## Usage\n\n### Inject instances\nTo inject instances, mark a class with the ``injectable`` decorator:\n```python\nfrom jacked import injectable\n\n@injectable\nclass Cat:\n    def sound(self):\n        return 'meow'\n```\nYou can now inject it in a function anywhere. Place the ``inject`` decorator on \ntop of the function or method. Let **jacked** know what type to inject by type \nhinting your parameters:\n```python\n@inject\ndef what_sound_does_it_make(cat: Cat):\n    print(cat.sound())\n    \nwhat_sound_does_it_make()\n```\n\n### Inject functions\nInjecting functions works similarly. Just make sure that your function has the\nproper type hints:\n\n```python\n@injectable\ndef some_func(x: int, y: int) -\u003e str:\n    return f'The sum of {x} and {y} is {x + y}'\n```\nAnd like with instances, inject as follows:\n```python\n@inject\ndef do_something(func: Callable[[int, int], str]):\n    print(func(21, 21))\n    \ndo_something()\n```\n### Inject classes\nAssuming that we have the same ``Cat`` injectable like before, we can inject\nthat class as follows:\n\n```python\nfrom typing import Type\n\n@inject\ndef do_something(cat_type: Type[Cat]):\n    print(cat_type.__name__)\n    \ndo_something()\n```\n\n\n### Inject lists\nLet's suppose that we have the following two injectables of the same parent:\n```python\nclass Animal(ABC):\n    @abstractmethod\n    def sound(self):\n        raise NotImplementedError\n        \n@injectable\nclass Cat(Animal):\n    def sound(self):\n        return 'meow'\n        \n@injectable\nclass Dog(Animal):\n    def sound(self):\n        return 'bark'\n```\nYou can now inject them in a list:\n```python\n@inject\ndef what_sound_does_it_make(animals: List[Animal]):\n    for animal in animals:\n        print(f'The {animal.__class__.__name__} does {animal.sound()}')\n        \nwhat_sound_does_it_make()\n```\nYou could have also injected a ``list`` of classes or functions by hinting\n``List[Type[...]]`` or ``List[Callable[...]]`` (the ``...`` replaced by your\ninjection target).\n\n### Singletons\nYou can annotate an injectable as singleton, meaning that if the injectable is \na class, only one instance is ever injected:\n\n```python\n@injectable(singleton=True)\nclass Dog(Animal):\n    def sound(self):\n        return 'bark'\n```\n\n### Auto discovery\nYou can let **jacked** discover injectables in some package using the \n``discover`` function:\n```python\nfrom jacked import discover\n\ndiscover('path/to/your/package')\n```\nAll python modules in that package are imported and the injectables are \nregistered.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framonhagenaars%2Fjacked","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Framonhagenaars%2Fjacked","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framonhagenaars%2Fjacked/lists"}