{ "info": { "author": "Bob Gregory", "author_email": "bob@codefiend.co.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Software Development :: Libraries :: Application Frameworks", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Punq\n====\n\n.. image:: https://travis-ci.org/bobthemighty/punq.svg?branch=master\n :target: https://travis-ci.org/bobthemighty/punq\n\n.. image:: https://img.shields.io/codecov/c/github/bobthemighty/punq.svg?style=flat\n :target: https://codecov.io/gh/bobthemighty/punq\n\n.. image:: https://readthedocs.org/projects/punq/badge/?version=latest\n :target: https://punq.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n\nAn unintrusive library for dependency injection in modern Python.\nInspired by `Funq`_, Punq is a dependency injection library you can understand.\n\n- No global state\n- No decorators\n- No weird syntax applied to arguments\n- Small and simple code base with 100% test coverage and developer-friendly comments.\n\nInstallation\n------------\n\nPunq is available on the `cheese shop`_.\n\n.. code:: bash\n\n pip install punq\n\nDocumentation is available on `Read the docs`_.\n\nQuick Start\n-----------\n\nPunq avoids global state, so you must explicitly create a container in the entrypoint of your application:\n\n.. code:: python\n\n import punq\n \n container = punq.Container()\n\nOnce you have a container, you can register your application's dependencies. In the simplest case, we can register any arbitrary object with some key:\n\n.. code:: python\n\n container.register(\"connection_string\", \"postgresql://...\")\n\nWe can then request that object back from the container:\n\n.. code:: python\n\n conn_str = container.resolve(\"connection_string\")\n\nUsually, though, we want to register some object that implements a useful service.:\n\n.. code:: python\n\n class ConfigReader:\n def get_config(self):\n pass\n \n class EnvironmentConfigReader(ConfigReader):\n def get_config(self):\n return {\n \"logging\": {\n \"level\": os.env.get(\"LOGGING_LEVEL\", \"debug\")\n }\n \"greeting\": os.env.get(\"GREETING\", \"Hello world\")\n }\n\n container.register(ConfigReader, EnvironmentConfigReader)\n\nNow we can `resolve` the `ConfigReader` service, and receive a concrete implementation:\n\n.. code:: python\n\n config = container.resolve(ConfigReader).get_config()\n\nIf our application's dependencies have their *own* dependencies, Punq will inject those, too:\n\n.. code:: python\n\n class Greeter:\n def greet(self):\n pass\n\n\n class ConsoleGreeter:\n def __init__(self, config_reader: ConfigReader):\n self.config = config_reader.get_config()\n\n def greet(self):\n print(self.config['greeting'])\n\n\n container.register(Greeter)\n container.resolve(Greeter).greet()\n \nIf you just want to resolve an object without having any base class, that's okay:\n\n.. code:: python\n\n class Greeter:\n def __init__(self, config_reader: ConfigReader):\n self.config = config_reader.get_config()\n\n def greet(self):\n print(self.config['greeting'])\n\n container.register(Greeter)\n container.resolve(Greeter).greet()\n \nAnd if you need to have a singleton object for some reason, we can tell punq to register a specific instance of an object:\n\n.. code:: python\n\n class FileWritingGreeter:\n def __init__(self, path, greeting):\n self.path = path\n self.message = greeting\n self.file = open(self.path, 'w')\n\n def greet(self):\n self.file.write(self.message)\n\n\n one_true_greeter = FileWritingGreeter(\"/tmp/greetings\", \"Hello world\")\n container.register(Greeter, instance=one_true_greeter)\n\n\nYou might not know all of your arguments at registration time, but you can provide them later:\n\n.. code:: python\n\n container.register(Greeter, FileWritingGreeter)\n greeter = container.resolve(Greeter, path=\"/tmp/foo\", greeting=\"Hello world\")\n\nConversely, you might want to provide arguments at registration time, without adding them to the container:\n\n.. code:: python\n\n container.register(Greeter, FileWritingGreeter, path=\"/tmp/foo\", greeting=\"Hello world\")\n \nFuller documentation is available on `Read the docs`_.\n\n.. _cheese shop: https://pypi.org/project/punq/\n.. _Read the docs: http://punq.readthedocs.io/en/latest/ \n.. _Funq: https://github.com/jlyonsmith/Funq\n\nChangelog\n=========\n\n`0.2.1`_ 2019-05-22\n-------------------\nFixes\n Punq will now prefer to use a provided resolution argument instead of creating it anew.\n\n`0.2.0`_ 2019-02-12\n-------------------\nFixes\n Added handling for typing.ForwardRef\n\nBreaking Changes\n Added explicit `instance` kwarg to `register` which replaces the previous behaviour where\n `container.register(Service, someInstance)` would register a concrete instance.\n This fixes https://github.com/bobthemighty/punq/issues/6\n\n0.1.2-alpha 2019-02-11\n----------------------\nFeature\n First automatic Travis deploy\n\n0.0.1\n-----\n Basic resolution and registration works\n Punq is almost certainly slow as a dog, non thread-safe, and prone to weird behaviour in the edge cases.\n\n.. _0.2.0: https://github.com/bobthemighty/punq/compare/v0.1.2-alpha...v0.2\n.. _0.2.1: https://github.com/bobthemighty/punq/compare/v0.2...v0.2.1", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/bobthemighty/punq", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "punq", "package_url": "https://pypi.org/project/punq/", "platform": "any", "project_url": "https://pypi.org/project/punq/", "project_urls": { "Homepage": "http://github.com/bobthemighty/punq" }, "release_url": "https://pypi.org/project/punq/0.3.0/", "requires_dist": null, "requires_python": "", "summary": "Unintrusive dependency injection for Python 3.6 +", "version": "0.3.0" }, "last_serial": 5526064, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "8e9e5cf139f1991d3172b7566ad51605", "sha256": "ae4c03dcbc764a59ea74e2e3ff493313b6fb93d338d764b8ee3a4e5b9ffaac96" }, "downloads": -1, "filename": "punq-0.0.1.tar.gz", "has_sig": false, "md5_digest": "8e9e5cf139f1991d3172b7566ad51605", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2917, "upload_time": "2017-09-10T21:12:11", "url": "https://files.pythonhosted.org/packages/04/5f/a23044d7b1c06e63147612e91a2c0f61176bee697694db4564562a51ff59/punq-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "c9d897083c24dc5d369e9112c601a989", "sha256": "30a980199e175b92ec96dfc5fa887d9242c4096564f53b212e771c433bf82722" }, "downloads": -1, "filename": "punq-0.0.2.tar.gz", "has_sig": false, "md5_digest": "c9d897083c24dc5d369e9112c601a989", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3036, "upload_time": "2017-09-10T21:21:51", "url": "https://files.pythonhosted.org/packages/5c/96/2365b4849e95049eb831207023ea9b46df220c23be4d514febecf2478845/punq-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "a973503ee409ae6c66609577727c2895", "sha256": "5597609ee0fe4017588fcb178349c8ca1dd2c1d09db603c0467091069741adec" }, "downloads": -1, "filename": "punq-0.0.3.tar.gz", "has_sig": false, "md5_digest": "a973503ee409ae6c66609577727c2895", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3106, "upload_time": "2017-09-10T21:39:19", "url": "https://files.pythonhosted.org/packages/be/d6/e721e8adf8eb95e187ed0f3be0b2144d2df16a1f37cc2ce7826b178f74f0/punq-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "387270380bedae35871fffd87931b8cc", "sha256": "169a5a3ee685e8c908ce93a02c220b9871d51ab6a208ee88769f27d5d776d924" }, "downloads": -1, "filename": "punq-0.0.4.tar.gz", "has_sig": false, "md5_digest": "387270380bedae35871fffd87931b8cc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3095, "upload_time": "2017-09-10T21:44:43", "url": "https://files.pythonhosted.org/packages/65/3f/06257c7867ae0b71ae09b97d50395f62ea6fe4653882069418a5104cb159/punq-0.0.4.tar.gz" } ], "0.1.2.1a0": [ { "comment_text": "", "digests": { "md5": "cde8e7aea89f18262431f63e727b59e3", "sha256": "00180f0831febfd360c4fc04e1a332bc1a18391cc5a8e77838aa62708ce092e5" }, "downloads": -1, "filename": "punq-0.1.2.1a0.tar.gz", "has_sig": false, "md5_digest": "cde8e7aea89f18262431f63e727b59e3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15441, "upload_time": "2019-02-06T07:08:53", "url": "https://files.pythonhosted.org/packages/67/c2/1fa41fb3c29d09c57bb56253758dd94a348aec5aedd79ee5c994a237332c/punq-0.1.2.1a0.tar.gz" } ], "0.1.2a0": [ { "comment_text": "", "digests": { "md5": "7bdaf86624551f540d93182e3f06da4c", "sha256": "d9eaa579b2a8b3e863f37ef6ded5a40d7aae0e70f4272e514ded55ef51bb9d53" }, "downloads": -1, "filename": "punq-0.1.2a0.tar.gz", "has_sig": false, "md5_digest": "7bdaf86624551f540d93182e3f06da4c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14966, "upload_time": "2019-02-06T06:56:56", "url": "https://files.pythonhosted.org/packages/48/a3/9ee2f16e1a77f578accb9064a876b35e9bdaa467d232d704d93773e01895/punq-0.1.2a0.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "b717e8e09aace99c87ad5cdd896dc8e6", "sha256": "3e7d531f99d35fb2f03ca1007c134bc0682a369057df0c7083c9369b665f7add" }, "downloads": -1, "filename": "punq-0.2.tar.gz", "has_sig": false, "md5_digest": "b717e8e09aace99c87ad5cdd896dc8e6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19146, "upload_time": "2019-02-12T11:30:38", "url": "https://files.pythonhosted.org/packages/15/20/87a6c98b2db54ffeadf29b84cbe8eaed2440a3c926fb7f3c7584561728ad/punq-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "d46eb30b5e16e9d62812f88952d48a88", "sha256": "381852451f4a260ee24ab6a70726210c82eda4df5859a0f78b201b181959048a" }, "downloads": -1, "filename": "punq-0.2.1.tar.gz", "has_sig": false, "md5_digest": "d46eb30b5e16e9d62812f88952d48a88", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23773, "upload_time": "2019-05-22T05:44:53", "url": "https://files.pythonhosted.org/packages/21/04/bd5066f005e5c68814f38f16548520be3f913e21b9a9e8a4b2d47873af1a/punq-0.2.1.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "80d0df400911531c10c920036149c38d", "sha256": "69b80d957eb28d7d2d89459fd16561063592f20e8bc00259dce39c29b60cfbd0" }, "downloads": -1, "filename": "punq-0.3.0.tar.gz", "has_sig": false, "md5_digest": "80d0df400911531c10c920036149c38d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23976, "upload_time": "2019-07-13T04:47:07", "url": "https://files.pythonhosted.org/packages/eb/43/78c5a5d9cf67a42bde18f2a6e05c29d647a15b49ffb6097524af161d0359/punq-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "80d0df400911531c10c920036149c38d", "sha256": "69b80d957eb28d7d2d89459fd16561063592f20e8bc00259dce39c29b60cfbd0" }, "downloads": -1, "filename": "punq-0.3.0.tar.gz", "has_sig": false, "md5_digest": "80d0df400911531c10c920036149c38d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23976, "upload_time": "2019-07-13T04:47:07", "url": "https://files.pythonhosted.org/packages/eb/43/78c5a5d9cf67a42bde18f2a6e05c29d647a15b49ffb6097524af161d0359/punq-0.3.0.tar.gz" } ] }