{ "info": { "author": "Jaap Verloop", "author_email": "j.verloop@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Knot\n****\n\n.. image:: https://badge.fury.io/py/knot.png\n :target: http://badge.fury.io/py/knot\n\n.. image:: https://travis-ci.org/jaapverloop/knot.png?branch=master\n :target: https://travis-ci.org/jaapverloop/knot\n\nKnot is a small do-it-yourself (DIY) dependency container for Python.\n\n\nGetting started\n===============\n\nUnlike other existing implementations, knot does not make use of introspection.\nTherefore, dependencies are manually defined in a straight forward manner. The\ncontainer acts as a central registry for providers and configuration settings.\n\n\nConfiguration settings\n----------------------\n\nThe container is just an ordinary dictionary with some additional methods. As a\nresult, it is very easy to assign or retrieve data from it. Probably the most\ncommon way to assign configuration settings is passing a dict to the\nconstructor.\n\n.. code-block:: python\n\n from knot import Container\n\n c = Container({'host': 'localhost', 'port': 6379})\n\nObviously it is also possible to add configuration settings to an existing\ncontainer.\n\n.. code-block:: python\n\n c = Container()\n c['host'] = 'localhost'\n c['port'] = 6379\n\n\nProviders\n---------\n\nA provider creates and returns a particular value or object. It has the ability\nto utilize an injected container to retrieve the necessary configuration\nsettings and dependencies.\n\nThe container expects a provider to adhere to the following rules:\n\n1. It must be callable.\n2. It must accept the container as the only argument.\n3. It must return anything except ``None``.\n\nAssigning a provider to a container is easy.\n\n.. code-block:: python\n\n def connection(c):\n from redis import Redis\n return Redis(host=c['host'], port=c['port'])\n\n c.add_provider(connection, True)\n\nIt is also possible to use a decorator.\n\n.. code-block:: python\n\n from knot import provider\n\n @provider(c, True)\n def connection(c):\n from redis import Redis\n return Redis(host=c['host'], port=c['port'])\n\nThe second argument in ``c.add_provider(connection, True)`` and in\n``@provider(c, True)`` indicates whether or not the return value of a provider\nmust be cached.\n\nRetrieve what you have defined.\n\n.. code-block:: python\n\n conn = c.provide('connection')\n\nFor convenience, you can also use the shortcut.\n\n.. code-block:: python\n\n conn = c('connection')\n\n\nServices\n--------\n\nA service is just a provider with the **cache** argument set to ``True``.\nBasically this means the return value is created only once.\n\n.. code-block:: python\n\n def connection(c):\n from redis import Redis\n return Redis(host=c['host'], port=c['port'])\n\n c.add_service(connection)\n\nOr with a decorator.\n\n.. code-block:: python\n\n from knot import service\n\n @service(c)\n def connection(c):\n from redis import Redis\n return Redis(host=c['host'], port=c['port'])\n\n conn1 = c('connection')\n conn2 = c('connection')\n\n print conn1 is conn2 # True\n\n\nFactories\n---------\n\nA factory is just a provider with the **cache** argument set to ``False``.\nBasically this means the return value is created on every call.\n\n.. code-block:: python\n\n def urgent_job(c):\n from somewhere import Job\n connection = c('connection')\n return Job(connection=connection, queue='urgent')\n\n c.add_factory(urgent_job)\n\n job1 = c('urgent_job')\n job1.enqueue('send_activation_mail', username='johndoe')\n\n job2 = c('urgent_job')\n job2.enqueue('send_activation_mail', username='janedoe')\n\n print job1 is job2 # False\n\nOr with a decorator.\n\n.. code-block:: python\n\n from knot import @factory\n\n @factory(c)\n def urgent_job(c):\n from somewhere import Job\n connection = c('connection')\n return Job(connection=connection, queue='urgent')\n\n\nInstallation\n============\n\nInstall Knot with the following command:\n\n.. code-block:: console\n\n $ pip install knot\n\n\nTests\n=====\n\nTo run the tests, install **tox** first:\n\n.. code-block:: console\n\n $ pip install tox\n\nThen, run the tests with the following command:\n\n.. code-block:: console\n\n $ tox\n\n\nInspiration\n===========\n\nPimple (http://pimple.sensiolabs.org/)\n\n\nLicense\n=======\n\nMIT, see **LICENSE** for more details.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/jaapverloop/knot/tarball/0.3.0", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jaapverloop/knot", "keywords": "dependency,container", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "knot", "package_url": "https://pypi.org/project/knot/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/knot/", "project_urls": { "Download": "https://github.com/jaapverloop/knot/tarball/0.3.0", "Homepage": "https://github.com/jaapverloop/knot" }, "release_url": "https://pypi.org/project/knot/0.4.0/", "requires_dist": null, "requires_python": null, "summary": "A small do-it-yourself dependency container.", "version": "0.4.0" }, "last_serial": 2131114, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "1042ef14312fc209c39b6b3d7f087d7b", "sha256": "52867bf346324d1c35a3669fde947efbab59991dff16963eda1ba694d8234ffd" }, "downloads": -1, "filename": "knot-0.1.0.tar.gz", "has_sig": false, "md5_digest": "1042ef14312fc209c39b6b3d7f087d7b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3576, "upload_time": "2013-07-30T10:32:22", "url": "https://files.pythonhosted.org/packages/46/92/a94d6dfa4750d6ed373a170e3052eac70bf22e56b9ce12c46551d709f220/knot-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "5ad30c583394eb456d8a783190531354", "sha256": "472824e5a553a08a96899e7443e1f2660abb1786e8e20cd1ff7f96e2bafdd1dc" }, "downloads": -1, "filename": "knot-0.2.0.tar.gz", "has_sig": false, "md5_digest": "5ad30c583394eb456d8a783190531354", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4053, "upload_time": "2013-09-19T21:32:45", "url": "https://files.pythonhosted.org/packages/89/4b/c8d7e356802ac7c08e826078f5ace56b44cb37046bb8b20336e259fa0a56/knot-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "c24193485b41b9fc064a429a60fc25a2", "sha256": "ad91327b720367b0f6cb66578d350b4288d1511731b6d451e39188df45b837e2" }, "downloads": -1, "filename": "knot-0.3.0.tar.gz", "has_sig": false, "md5_digest": "c24193485b41b9fc064a429a60fc25a2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6060, "upload_time": "2014-03-20T22:56:54", "url": "https://files.pythonhosted.org/packages/be/98/55ea70faf745fdf1879665776aff675dc13c303d9047e8a08a2cc5f020c1/knot-0.3.0.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "12a27dbae187790cce721066436f8ccb", "sha256": "89e0d8274dbdf1dc38ca80d1e26a1d371ce569afb9c470aba6e9184092b9b9a8" }, "downloads": -1, "filename": "knot-0.4.0.tar.gz", "has_sig": false, "md5_digest": "12a27dbae187790cce721066436f8ccb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6088, "upload_time": "2016-05-24T13:36:01", "url": "https://files.pythonhosted.org/packages/b4/e7/9bfc9313a9e603c853f5eed7607677d364a597dc64d3bb3a705f164c507c/knot-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "12a27dbae187790cce721066436f8ccb", "sha256": "89e0d8274dbdf1dc38ca80d1e26a1d371ce569afb9c470aba6e9184092b9b9a8" }, "downloads": -1, "filename": "knot-0.4.0.tar.gz", "has_sig": false, "md5_digest": "12a27dbae187790cce721066436f8ccb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6088, "upload_time": "2016-05-24T13:36:01", "url": "https://files.pythonhosted.org/packages/b4/e7/9bfc9313a9e603c853f5eed7607677d364a597dc64d3bb3a705f164c507c/knot-0.4.0.tar.gz" } ] }