{ "info": { "author": "Paulo Phagula", "author_email": "pphagula@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Topic :: Software Development :: Libraries" ], "description": "# TinyDIC\n\n[![Build Status](https://travis-ci.org/dareenzo/tinydic.svg?branch=master)](https://travis-ci.org/dareenzo/tinydic)\n[![Coverage Status](https://coveralls.io/repos/github/dareenzo/tinydic/badge.svg?branch=master)](https://coveralls.io/github/dareenzo/tinydic?branch=master)\n\nTiny Python Dependency Injection Container.\n\n## Why *TinyDIC*?\n\nI was looking for a Dependency Injection Container in Python, googled a\nbit, but only found solutions which were huge and use constructs -- such\nas decorators and so on -- which I'm not so fond of, or at least don't\nfind a good justification for their use, for such a simple and small\nthing as an DIC.\n\nSo, inspired (or copying) the PHP [Twittee IoC](https://github.com/fabpot-graveyard/twitte)\nwritten by [Fabien Potencier](http://fabien.potencier.org) of [Symfony](http://symfony.com)\nfame, I wrote this small class.\n\nAlthough this is inspired by Twittee, it doesn't fit in 140 chars,\nso I could not call it that. But thankfully, Fabien Potencier has another\nmore full fledged IoC, called Pimple, and that's where I stole the name from.\nJust made it *Py* instead of *Pi* because .. err you know... it's Python.\n\nLast, but not least, I've had lots of help on [StackOverflow reviews](http://codereview.stackexchange.com/questions/146964/simple-python-ioc)\n... to setup this -- thank you so much!\n\nLast but not least, I've to say that this is a very tiny thing meant for small personal projects so I don't recommend production use.\nFor something more proper and mature I recommend you check [Pymple](https://github.com/BernhardPosselt/pymple)\n\n## Installation\n\n```sh\npip install tinydic\n```\n\n## Usage\n\n```python\nfrom tinydic import Container\n\n\nclass MailService:\n\n def __init__(self, user, password, server):\n self.user = user\n self.password = password\n self.server = server\n\n def send_mail(self, to, subject, contents):\n # uses stored settings to send email\n pass\n\n\ndef email_validator_service(container):\n def functor(email):\n return container.MAIL_REGEX.match(email)\n return functor\n\n\nclass MailClient:\n\n def __init__(self, mail_service, validate_email):\n self.mail_service = mail_service\n self.validate_email = validate_email\n\n def send_mail(self, to, message):\n if self.validate_email(to):\n self.mail_service.send_mail(a, b)\n\n# create container\ncontainer = Container()\n\n# register constants / params\ncontainer.MAIL_REGEX = 'ugly long regex here'\ncontainer.username = 'spam' # container.register('username', 'spam', constant = True)\ncontainer.password = 'eggs'\ncontainer.server = 'foo.bar.com'\n\n# register objects / services\ncontainer.mail_service = lambda c: MailService(c.username, c.password, c.server))\n# container.register('mail_service', lambda c: MailService(c.username, c.password, c.server), False)\ncontainer.email_validator = email_validator_service\ncontainer.client = lambda c: MailClient(c.mail_service, c.email_validator)\n\ncontainer.client.send_mail('eggs@foo.bar.com', 'yo')\n```\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dareenzo/tinydic", "keywords": "dic,ioc,dependency injection,inversion of control", "license": "See LICENSE", "maintainer": "", "maintainer_email": "", "name": "TinyDIC", "package_url": "https://pypi.org/project/TinyDIC/", "platform": "", "project_url": "https://pypi.org/project/TinyDIC/", "project_urls": { "Homepage": "https://github.com/dareenzo/tinydic" }, "release_url": "https://pypi.org/project/TinyDIC/0.1.2/", "requires_dist": null, "requires_python": "", "summary": "Tiny Python Dependency Injection Container.", "version": "0.1.2" }, "last_serial": 3858752, "releases": { "0.1.0": [], "0.1.2": [ { "comment_text": "", "digests": { "md5": "8aa8bdf2035bc9e22197a4ed6f220366", "sha256": "7f5f7e05093e581d871c46f67ede8e3fdc43c501e78e23b543c1a369852b6279" }, "downloads": -1, "filename": "TinyDIC-0.1.2-py2-none-any.whl", "has_sig": false, "md5_digest": "8aa8bdf2035bc9e22197a4ed6f220366", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 3278, "upload_time": "2018-05-13T16:19:13", "url": "https://files.pythonhosted.org/packages/a6/37/aefb0662b53ebd48acf18ce66fcc4dfada6a42c5e42d364c1c67db1c8d30/TinyDIC-0.1.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b1249bfdca25058d30113bfa7f4fcf25", "sha256": "c30ee5f5ff79f25de190028b3ab6c79548012ece4ae00c76ac2b55b91d3e9a9f" }, "downloads": -1, "filename": "TinyDIC-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b1249bfdca25058d30113bfa7f4fcf25", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3454, "upload_time": "2018-05-13T16:19:21", "url": "https://files.pythonhosted.org/packages/84/f9/96dd50323c13523977808353fa1873bc632dcfc5f4a85ec5837e63584b98/TinyDIC-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8aa8bdf2035bc9e22197a4ed6f220366", "sha256": "7f5f7e05093e581d871c46f67ede8e3fdc43c501e78e23b543c1a369852b6279" }, "downloads": -1, "filename": "TinyDIC-0.1.2-py2-none-any.whl", "has_sig": false, "md5_digest": "8aa8bdf2035bc9e22197a4ed6f220366", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 3278, "upload_time": "2018-05-13T16:19:13", "url": "https://files.pythonhosted.org/packages/a6/37/aefb0662b53ebd48acf18ce66fcc4dfada6a42c5e42d364c1c67db1c8d30/TinyDIC-0.1.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b1249bfdca25058d30113bfa7f4fcf25", "sha256": "c30ee5f5ff79f25de190028b3ab6c79548012ece4ae00c76ac2b55b91d3e9a9f" }, "downloads": -1, "filename": "TinyDIC-0.1.2.tar.gz", "has_sig": false, "md5_digest": "b1249bfdca25058d30113bfa7f4fcf25", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3454, "upload_time": "2018-05-13T16:19:21", "url": "https://files.pythonhosted.org/packages/84/f9/96dd50323c13523977808353fa1873bc632dcfc5f4a85ec5837e63584b98/TinyDIC-0.1.2.tar.gz" } ] }