{ "info": { "author": "Jazeps Basko", "author_email": "jazeps.basko@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries" ], "description": "=========\nauto-init\n=========\n\n**auto-init** is a dependency injection tool that works in Python 3.6+ thanks to type hints.\nIf you write nice object oriented code and separate interfaces from implementations\nthen you could benefit from this.\n\nIntroduction\n++++++++++++\n\nDid you know that if you provide a type hint for an attribute in a class body and do not set a value then\nthe attribute isn't actually initialised (neither in class, nor in instances)?\n\n.. code-block:: python\n\n class Point:\n x: int\n y: int\n z: int = None\n\nFor ``p``, an instance of ``Point``, only ``p.z`` is set. This is great because we can build a dependency\ninjection mechanism on top of this!\n\nSimple Example\n--------------\n\n.. code-block:: python\n\n from auto_init import AutoInitContext\n\n ctx = AutoInitContext()\n p: Point = ctx.get_instance(Point)\n assert p.x == 0\n assert p.y == 0\n assert p.z is None\n\n\nNote that the ``Point`` class could also be a dataclass and it would work too.\n\n\nNot So Simple Example\n---------------------\n\n.. code-block:: python\n\n import logging\n\n from auto_init import AutoInitContext\n\n\n class Worker:\n enterprise: \"Enterprise\"\n log: logging.Logger\n\n\n class Reporter:\n enterprise: \"Enterprise\"\n log: logging.Logger\n\n\n class Enterprise:\n worker: Worker\n reporter: Reporter\n\n\n ctx = AutoInitContext()\n ctx.register_instance(logging.getLogger(__name__))\n ctx.register_singleton(Enterprise)\n\n enterprise: Enterprise = ctx.get_instance(Enterprise)\n assert enterprise.worker.log is enterprise.reporter.log\n assert enterprise.worker.enterprise is enterprise\n assert enterprise.reporter.enterprise is enterprise\n\nInstallation\n++++++++++++\n\n.. code-block:: shell\n\n pip install auto-init\n\n\nAPI\n+++\n\n``AutoInitContext()``\n Create a new auto-initialisation context.\n\n ``register_singleton(instance_type: Type, factory: Callable=None)``\n Register a singleton type. This is different from ``register_instance`` in that here **auto-init**\n is responsible for the creation as well as initialisation of the singleton instance. This should\n be used when the singleton itself has dependencies that need to be injected. See the *enterprise.py*\n example under ``auto_init/examples/`` .\n If ``factory`` is not supplied, the ``instance_type`` is used to create the instance.\n\n ``register_factory(instance_type: Type, factory: Callable)``\n Register a callable which is called to create a new instance of the specified type when on is requested.\n\n ``register_instance(instance, instance_type: Type=None)``\n Register an instance that should always be returned when an instance of the specified type is requested.\n\n ``get_instance(instance_type: Type) -> Any``\n Get an instance of the specified type.\n\n ``init_instance(instance)``\n Initialise any unitialised attributes of the instance.\n\n\nChangelog\n+++++++++\n\nv0.0.5\n------\n\n* Supports initialising attributes annotated with ``typing.List`` and ``typing.Dict`` as empty lists or dictionaries.\n Other ``typing.*``-annotated attributes are initialised as ``None``.\n* Do not attempt to get type hints from ``typing.*`` classes, it raises exceptions in Python 3.7 and does not return\n anything useful in Python 3.6 anyway.\n* Fixes dependencies for Python 3.6, removes unnecessary ``contextvars`` and ``dataclasses``\n dependencies for Python 3.7.\n* Travis CI setup.\n\nv0.0.4\n------\n\n* Complete rewrite to deal with circular references. Intrusive approach is no good.\n* Forward references in type hints don't really work in Python 3.7 even with futures. Let's use Python 3.6.\n\nv0.0.3\n------\n\n* Added ``AutoInitContext.explicit_only`` -- allows marking the context as only initialising the types with specified\n providers and leaving all others *untouched*.\n* If a type hint includes a default value (declares a class attribute) then the corresponding instance attribute will\n be a copy by reference of the class attribute unless there is an explicit provider specified in the context.\n This means that ``x: int = None`` will be initialised as ``None``, not as ``0``.\n\nv0.0.2\n------\n\n* Non-intrusive auto-init: function ``auto_init`` and method ``AutoInitContext.auto_init`` that initialises instances\n without making any changes to user's classes.\n* Added ``AutoInitContext.singleton_types`` -- allows to specify singleton types non-intrusively.\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/jbasko/auto-init", "keywords": "dependency injection type hinting typing", "license": "MIT", "maintainer": "Jazeps Basko", "maintainer_email": "jazeps.basko@gmail.com", "name": "auto-init", "package_url": "https://pypi.org/project/auto-init/", "platform": "", "project_url": "https://pypi.org/project/auto-init/", "project_urls": { "Homepage": "https://github.com/jbasko/auto-init" }, "release_url": "https://pypi.org/project/auto-init/0.0.5/", "requires_dist": [ "dataclasses; python_version==\"3.6\"", "contextvars; python_version==\"3.6\"" ], "requires_python": ">=3.6.0", "summary": "Dependency injection thanks to type hints in Python 3.6+", "version": "0.0.5" }, "last_serial": 4398783, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "e341c1694134ea369f9fbaa716c902a6", "sha256": "0c153fa0578d4f99dd0bbf0f2ed67bbeaf75a5f9e7e118f00d6b49c52be3c3c1" }, "downloads": -1, "filename": "auto_init-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "e341c1694134ea369f9fbaa716c902a6", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4374, "upload_time": "2018-09-29T23:35:34", "url": "https://files.pythonhosted.org/packages/24/91/7dec48f92d942651bf93969b63d800b778955f214d1a20ef120815f21f52/auto_init-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6711e5b5b01496012a47f44dc01e75db", "sha256": "743bcc3e7555545a9c52b61e5c64ad9502665c650fd9632c3c35e49fedd1f315" }, "downloads": -1, "filename": "auto-init-0.0.1.tar.gz", "has_sig": false, "md5_digest": "6711e5b5b01496012a47f44dc01e75db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4299, "upload_time": "2018-09-29T23:35:35", "url": "https://files.pythonhosted.org/packages/d2/cc/00e089fed8cb11e6a2132f4b34d9a101502b8f573381a4fc94bdb5677c6b/auto-init-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "041f77e90f2c83704195cdf0f1286431", "sha256": "b276b8fdb41a867231e535609ba7d14ecad8450101a1f42680c6541b81f87c7f" }, "downloads": -1, "filename": "auto_init-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "041f77e90f2c83704195cdf0f1286431", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5583, "upload_time": "2018-10-02T23:23:37", "url": "https://files.pythonhosted.org/packages/a8/20/beceba9357cf43d90568471b8936e371ff4f38516ef2806773124d7abe04/auto_init-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6d1293c64d84897cd6c1c12c3ccaca39", "sha256": "1131cdca6b555b5299ea735db61f61cfe9b27f6d91328190618e0193f31ae3bf" }, "downloads": -1, "filename": "auto-init-0.0.2.tar.gz", "has_sig": false, "md5_digest": "6d1293c64d84897cd6c1c12c3ccaca39", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5738, "upload_time": "2018-10-02T23:23:39", "url": "https://files.pythonhosted.org/packages/a4/d7/bb5561194c8b37949a3bb4be4f0ed9b5d55a991cb0add6b471b7def57d45/auto-init-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "361a5421df5f7a16ab3ce1f3032498bb", "sha256": "8205f7796fb129880fae732d90047dd48e244b0ac7c16d420046562dd92b92e5" }, "downloads": -1, "filename": "auto_init-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "361a5421df5f7a16ab3ce1f3032498bb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6242, "upload_time": "2018-10-03T00:15:42", "url": "https://files.pythonhosted.org/packages/13/aa/c2388a38097e2d8f753ca704a9750eed8c3a73679f4fb8a52537104828ac/auto_init-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1f030453e59777400ad1eeb317f71199", "sha256": "b3b63740dfd9ba09fbd1349929f47fab551efe9099b490a0b4a62bde89634c23" }, "downloads": -1, "filename": "auto-init-0.0.3.tar.gz", "has_sig": false, "md5_digest": "1f030453e59777400ad1eeb317f71199", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6584, "upload_time": "2018-10-03T00:15:43", "url": "https://files.pythonhosted.org/packages/c0/bb/46de122fb62676f12b45e95444af664bf7c2ddfc474a161352d734299a89/auto-init-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "a89ba8e362536ec6bf6262db3db79f1b", "sha256": "4b2f7d46628ae3d0bf54b31315a5a5ee62cb731fc0db9a8f5c3c4b8ec0c04262" }, "downloads": -1, "filename": "auto_init-0.0.4-py3-none-any.whl", "has_sig": false, "md5_digest": "a89ba8e362536ec6bf6262db3db79f1b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 5444, "upload_time": "2018-10-20T23:52:28", "url": "https://files.pythonhosted.org/packages/3f/29/78dfe53a9b0c5e4af2584069b5c318b0752d34fdbe1fd952ad0d1fe8cacf/auto_init-0.0.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5e615f897682273784dc42f6e86fd3b5", "sha256": "85e933718606974c144a67a55960e40cea1fae3e52b44a30a3aff75550f9c44b" }, "downloads": -1, "filename": "auto-init-0.0.4.tar.gz", "has_sig": false, "md5_digest": "5e615f897682273784dc42f6e86fd3b5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5349, "upload_time": "2018-10-20T23:52:29", "url": "https://files.pythonhosted.org/packages/3f/ed/54505acdaa1914c8db6ce95df30d805cdff34deeae286bc3c18b342997c8/auto-init-0.0.4.tar.gz" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "fdb6f5f076545b78fb88e0a0b5bca055", "sha256": "d2468a32d1cd5aea84dc740893e5187ee7a8829d971ec7a08b6a0ca923f2a14e" }, "downloads": -1, "filename": "auto_init-0.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "fdb6f5f076545b78fb88e0a0b5bca055", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 6154, "upload_time": "2018-10-21T07:50:43", "url": "https://files.pythonhosted.org/packages/99/d7/7f369bc866bce568415d9dcf91a7af0ec9ff164ab9b4850117d563ff5406/auto_init-0.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "343227cee45a56207292d047ea332d21", "sha256": "94db6303059dfac96054f758be00f090b5e7c47d8434487efc685c92cd0d104b" }, "downloads": -1, "filename": "auto-init-0.0.5.tar.gz", "has_sig": false, "md5_digest": "343227cee45a56207292d047ea332d21", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 6147, "upload_time": "2018-10-21T07:50:44", "url": "https://files.pythonhosted.org/packages/47/66/ad95cd3d3cff1c7d716737ce7c193937361bcd35868314e0cd8579626f53/auto-init-0.0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fdb6f5f076545b78fb88e0a0b5bca055", "sha256": "d2468a32d1cd5aea84dc740893e5187ee7a8829d971ec7a08b6a0ca923f2a14e" }, "downloads": -1, "filename": "auto_init-0.0.5-py3-none-any.whl", "has_sig": false, "md5_digest": "fdb6f5f076545b78fb88e0a0b5bca055", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 6154, "upload_time": "2018-10-21T07:50:43", "url": "https://files.pythonhosted.org/packages/99/d7/7f369bc866bce568415d9dcf91a7af0ec9ff164ab9b4850117d563ff5406/auto_init-0.0.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "343227cee45a56207292d047ea332d21", "sha256": "94db6303059dfac96054f758be00f090b5e7c47d8434487efc685c92cd0d104b" }, "downloads": -1, "filename": "auto-init-0.0.5.tar.gz", "has_sig": false, "md5_digest": "343227cee45a56207292d047ea332d21", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 6147, "upload_time": "2018-10-21T07:50:44", "url": "https://files.pythonhosted.org/packages/47/66/ad95cd3d3cff1c7d716737ce7c193937361bcd35868314e0cd8579626f53/auto-init-0.0.5.tar.gz" } ] }