{ "info": { "author": "meadsteve", "author_email": "meadsteve@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License" ], "description": "# Lagom - Dependency injection container\n[![Build Status](https://travis-ci.org/meadsteve/lagom.svg?branch=master)](https://travis-ci.org/meadsteve/lagom)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/meadsteve/lagom/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/meadsteve/lagom/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/meadsteve/lagom/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/meadsteve/lagom/?branch=master)\n![PyPI](https://img.shields.io/pypi/v/lagom.svg?style=plastic)\n## Usage\nEverything in Lagom is based on types. To create an object\nyou pass the type to the container:\n```python\ncontainer = Container()\nsome_thing = container[SomeClass]\n```\n\n### Defining a singleton\n```python\ncontainer[SomeExpensiveToCreateClass] = SomeExpensiveToCreateClass(\"up\", \"left\")\n```\nalternatively if you want to defer construction until it's needed:\n```python\ncontainer[SomeExpensiveToCreateClass] = Singleton(SomeExpensiveToCreateClass)\n```\n\n\n### Defining a type that gets recreated every time\n```python\ncontainer[SomeClass] = lambda: SomeClass(\"down\", \"spiral\")\n```\nif the type needs things from the container the lambda can take a\nsingle argument which is the container:\n```python\ncontainer[SomeClass] = lambda c: SomeClass(c[SomeOtherDep], \"spinning\")\n```\n\n### Alias a concrete instance to an ABC\n```python\ncontainer[SomeAbc] = ConcreteClass\n```\n\n### Partially bind a function\nApply a function decorator to any function.\n```python\n@bind_to_container(container)\ndef handle_some_request(request: typing.Dict, game: Game):\n # do something to the game\n pass\n```\n\nThis function can now be called omitting any arguments \nthat the container knows how to build.\n```python\n# we can now call the following. the game argument will automagically\n# come from the container\nhandle_some_request(request={\"roll_dice\": 5})\n```\n\n\n## Example\n\n### App setup\n```python\nfrom abc import ABC\nfrom dataclasses import dataclass\n\nfrom lagom import Container\n\n#--------------------------------------------------------------\n# Here is an example of some classes your application may be built from\n\n\n@dataclass\nclass DiceApiUrl:\n url: str\n\n\nclass RateLimitingConfig:\n pass\n\n\nclass DiceClient(ABC):\n pass\n\n\nclass HttpDiceClient(DiceClient):\n\n def __init__(self, url: DiceApiUrl, limiting: RateLimitingConfig):\n pass\n\n\nclass Game:\n def __init__(self, dice_roller: DiceClient):\n pass\n\n#--------------------------------------------------------------\n# Next we setup some definitions\n\ncontainer = Container()\n# We need a specific url\ncontainer[DiceApiUrl] = DiceApiUrl(\"https://roll.diceapi.com\")\n# Wherever our code wants a DiceClient we get the http one\ncontainer[DiceClient] = HttpDiceClient\n\n#--------------------------------------------------------------\n# Now the container can build the game object\n\ngame = container[Game]\n\n```\n\n### Testing without patching\nTaking the container from above we can now swap out\nthe dice client to a test double/fake. When we get an\ninstance of the `Game` class it will have the new\nfake dice client injected in.\n\n```python\ndef some_test(container: Container):\n container[DiceClient] = FakeDice(always_roll=6)\n game_to_test = container[Game]\n # TODO: act & assert on something\n```\n\n## Design Goals\n* Everything should be done by type. No reliance on names.\n* All domain code should remain unmodified. No special decorators.\n* Make use of modern python features (3.7 at the time of creation)\n* The API should expose sensible typing (for use in pycharm/mypy)", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "lagom", "package_url": "https://pypi.org/project/lagom/", "platform": "", "project_url": "https://pypi.org/project/lagom/", "project_urls": null, "release_url": "https://pypi.org/project/lagom/0.3.2/", "requires_dist": null, "requires_python": "~=3.7", "summary": "Lagom, a type based dependency injection container", "version": "0.3.2" }, "last_serial": 5694415, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "8dc2fd6de6d43471d57587b1e8dc62fe", "sha256": "e740e63a543816a83a594c07bbb8a2b88ae132117cc72f1af0321612894f2993" }, "downloads": -1, "filename": "lagom-0.1.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "8dc2fd6de6d43471d57587b1e8dc62fe", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7555, "upload_time": "2019-06-02T11:28:14", "url": "https://files.pythonhosted.org/packages/f1/c9/f3af210317a26c15a244314c2e7a6ae6fdb5936f2adbda5c432f9ec47f66/lagom-0.1.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2591b60b9043077e632454b1da593f0c", "sha256": "10f97c23e113882d4a6d2d337ae58f7228218ea73b9f35cfff473bd0ce0364a2" }, "downloads": -1, "filename": "lagom-0.1.0.tar.gz", "has_sig": false, "md5_digest": "2591b60b9043077e632454b1da593f0c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10355, "upload_time": "2019-06-02T11:28:21", "url": "https://files.pythonhosted.org/packages/e6/53/8174b5076c0f172cdde6c84e25edcf2dd7d072219a83217406ac761f3ba0/lagom-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "abf5e753ecc98ad88000b71fc41f6f7b", "sha256": "4800cc9016cb0fbe37c9642f423b049b31bdeee8be0ad6f0f9e3c95263e99e5b" }, "downloads": -1, "filename": "lagom-0.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "abf5e753ecc98ad88000b71fc41f6f7b", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.7", "size": 8517, "upload_time": "2019-06-02T11:45:53", "url": "https://files.pythonhosted.org/packages/23/80/4d0ad9a911be1b8b3b33fbad3b4b3c22ce21c81329ee70c69834ec88c053/lagom-0.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6c81d20005ad6d551dd997c1049e746b", "sha256": "32dbafa7c3866d82db2af821846b90f971320d863da7664b9e268668819a4d05" }, "downloads": -1, "filename": "lagom-0.1.1.tar.gz", "has_sig": false, "md5_digest": "6c81d20005ad6d551dd997c1049e746b", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.7", "size": 10750, "upload_time": "2019-06-02T11:45:57", "url": "https://files.pythonhosted.org/packages/df/6b/848715f89f24993f62b69aa8ad64cf33aa9254e467c6fb99081fb039c7b5/lagom-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "082cb04baff085db2faefd162f9a7cdb", "sha256": "e7637d004de4f703392fd5f0955317c33f0588a213734452c18ef3a6c899f975" }, "downloads": -1, "filename": "lagom-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "082cb04baff085db2faefd162f9a7cdb", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.7", "size": 10014, "upload_time": "2019-06-06T12:21:37", "url": "https://files.pythonhosted.org/packages/21/ee/64d67ef0f1ebad3cdadd64e90f9ee57f3aff6f801cf836c98ca8fe1303bf/lagom-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e1e152b58f834753216939edffd1b674", "sha256": "25e448af0ea46bb0fb912bf520722250da1b67aeb07ec9936ec943051bb1667b" }, "downloads": -1, "filename": "lagom-0.2.0.tar.gz", "has_sig": false, "md5_digest": "e1e152b58f834753216939edffd1b674", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.7", "size": 14119, "upload_time": "2019-06-06T12:21:43", "url": "https://files.pythonhosted.org/packages/bc/85/6796ba28efcf4e18f72d63aa2a13237ed941f60bc6c5fb4bc31b2d39e2d4/lagom-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "84d32d1ab63c1276dc6196e516225f05", "sha256": "cf3858ad86525a5612c8732c5550e0ec8927e6d0ca7c881dc11852c473ccd6ec" }, "downloads": -1, "filename": "lagom-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "84d32d1ab63c1276dc6196e516225f05", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.7", "size": 10225, "upload_time": "2019-08-01T07:01:21", "url": "https://files.pythonhosted.org/packages/47/fe/00d3b947e81310cc17039f5a4a3773070c5147d3ea9e6d5be5d6fbe19949/lagom-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7d8c21b96700492c04dedd50252538d1", "sha256": "8b837285692b333215cd9b3aec4f69c9d516d4f555b175db91a868d589feb0f6" }, "downloads": -1, "filename": "lagom-0.3.0.tar.gz", "has_sig": false, "md5_digest": "7d8c21b96700492c04dedd50252538d1", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.7", "size": 14121, "upload_time": "2019-08-01T07:01:28", "url": "https://files.pythonhosted.org/packages/a3/e3/cd0cc0b0c307cdded439738647cf72c311056d32b30b53874f997e568af4/lagom-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "eb8d687e2623ba46d90fd7cecc78ea1e", "sha256": "ed6ef7b5d0fa44cfe069ce792ff4269bfae340e93057caee75f639fe88e82943" }, "downloads": -1, "filename": "lagom-0.3.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "eb8d687e2623ba46d90fd7cecc78ea1e", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.7", "size": 10434, "upload_time": "2019-08-10T10:53:13", "url": "https://files.pythonhosted.org/packages/d4/88/68c70acbc5e13c73d4327739c23cdf01486ccdfca2ea9cb560fd2c0ddbe0/lagom-0.3.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "38b1af6af587d6876cbdefd50dbc0d0e", "sha256": "1f10f0ebddf0f89010957a47e72ebf5d6f666e644a2452a6b9007b35dd780e56" }, "downloads": -1, "filename": "lagom-0.3.1.tar.gz", "has_sig": false, "md5_digest": "38b1af6af587d6876cbdefd50dbc0d0e", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.7", "size": 14655, "upload_time": "2019-08-10T10:53:17", "url": "https://files.pythonhosted.org/packages/1c/e7/c46518471530664078b93d48f4aad9ddf0af693aba91c76758e166c97098/lagom-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "3c3e45a43f44e8d7ec83126c6227241f", "sha256": "8ca013d33ab8efd4ac8d9c48ad6418975c87f0bcbb78dce5172f9c48c0048b84" }, "downloads": -1, "filename": "lagom-0.3.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3c3e45a43f44e8d7ec83126c6227241f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.7", "size": 10277, "upload_time": "2019-08-18T12:17:43", "url": "https://files.pythonhosted.org/packages/c8/06/62c28a8903d71853546ae77ff62155b3bb8c1851dfaafec7c2d38df29033/lagom-0.3.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6775214fdc83e8d8679bd8aa298be628", "sha256": "fc0d066ed1b102ccdf43fe70326cf962c1c75bb44ca1f53d10edf0f537c48b4a" }, "downloads": -1, "filename": "lagom-0.3.2.tar.gz", "has_sig": false, "md5_digest": "6775214fdc83e8d8679bd8aa298be628", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.7", "size": 14800, "upload_time": "2019-08-18T12:17:48", "url": "https://files.pythonhosted.org/packages/f5/01/44a91e50aa938b2fb8e04a3f650cce8922f952d5fa857e7e1d4b99eadbef/lagom-0.3.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3c3e45a43f44e8d7ec83126c6227241f", "sha256": "8ca013d33ab8efd4ac8d9c48ad6418975c87f0bcbb78dce5172f9c48c0048b84" }, "downloads": -1, "filename": "lagom-0.3.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "3c3e45a43f44e8d7ec83126c6227241f", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": "~=3.7", "size": 10277, "upload_time": "2019-08-18T12:17:43", "url": "https://files.pythonhosted.org/packages/c8/06/62c28a8903d71853546ae77ff62155b3bb8c1851dfaafec7c2d38df29033/lagom-0.3.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6775214fdc83e8d8679bd8aa298be628", "sha256": "fc0d066ed1b102ccdf43fe70326cf962c1c75bb44ca1f53d10edf0f537c48b4a" }, "downloads": -1, "filename": "lagom-0.3.2.tar.gz", "has_sig": false, "md5_digest": "6775214fdc83e8d8679bd8aa298be628", "packagetype": "sdist", "python_version": "source", "requires_python": "~=3.7", "size": 14800, "upload_time": "2019-08-18T12:17:48", "url": "https://files.pythonhosted.org/packages/f5/01/44a91e50aa938b2fb8e04a3f650cce8922f952d5fa857e7e1d4b99eadbef/lagom-0.3.2.tar.gz" } ] }