{ "info": { "author": "Matthaus Woolard", "author_email": "matthaus.woolard@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "==============================\nDjango Channels Rest Framework\n==============================\n\nDjango Channels Rest Framework provides a DRF like interface for building channels-v2 websocket consumers.\n\n\nThis project can be used alongside HyperMediaChannels_ and ChannelsMultiplexer_ to create a Hyper Media Style api over websockets. However Django Channels Rest Framework is also a free standing framwork with the goal of providing an api that is familiar to DRF users. \n\n.. _HyperMediaChannels: https://github.com/hishnash/hypermediachannels\n.. _ChannelsMultiplexer: https://github.com/hishnash/channelsmultiplexer\n\n.. image:: https://travis-ci.org/hishnash/djangochannelsrestframework.svg?branch=master\n :target: https://travis-ci.org/hishnash/djangochannelsrestframework\n\nThanks to\n---------\n\n\nDCRF is based of a fork of `Channels Api `_ and of course inspired by `Django Rest Framework `_.\n\n\nInstall\n-------\n\n.. code-block:: bash\n\n pip install djangochannelsrestframework\n\n\nHow to Use\n==========\n\n\n\nObserving a Model instance\n--------------------------\n\nConsumer that accepts subscribtions to an instance.\n\n.. code-block:: python\n\n class TestConsumer(ObserverModelInstanceMixin, GenericAsyncAPIConsumer):\n queryset = get_user_model().objects.all()\n serializer_class = UserSerializer\n\nthis exposes the `retrieve` and `subscribe_instance` actions to that instance.\n\nto subscribe send:\n\n\n.. code-block:: python\n\n {\n \"action\": \"subscribe_instance\",\n \"pk\": 42, # the id of the instance you are subscribing to\n \"request_id\": 4 # this id will be used for all resultent updates.\n }\n\n\nActions will be sent down out from the server:\n\n.. code-block:: python\n\n\t{\n\t\t\"action\": \"update\",\n\t\t\"errors\": [],\n\t\t\"response_status\": 200,\n\t\t\"request_id\": 4,\n\t\t\"data\": {'email': '42@example.com', 'id': 42, 'username': 'thenewname'},\n\t}\n\nAdding Custom actions\n---------------------\n\n\n.. code-block:: python\n\n class UserConsumer(GenericAsyncAPIConsumer):\n queryset = get_user_model().objects.all()\n serializer_class = UserSerializer\n\n @action()\n async def send_email(self, pk=None, to=None, **kwargs):\n user = await database_sync_to_async(self.get_object)(pk=pk)\n # ... do some stuff\n # remember to wrap all db actions in `database_sync_to_async`\n return {}, 200 # return the contenct and the response code.\n\n @action() # if the method is not async it is already wrapped in `database_sync_to_async`\n def publish(self, pk=None, **kwargs):\n user = self.get_object(pk=pk)\n\t # ...\n\t return {'pk': pk}, 200\n\nYou can also use any of:\n\n* ``CreateModelMixin``\n* ``ListModelMixin``\n* ``RetrieveModelMixin``\n* ``UpdateModelMixin``\n* ``PatchModelMixin``\n* ``DeleteModelMixin``\n\njust as you would in DRF.\n\n.. code-block:: python\n\n from djangochannelsrestframework.generics import GenericAsyncAPIConsumer\n from djangochannelsrestframework.mixins import (\n RetrieveModelMixin,\n UpdateModelMixin\n )\n\n class UserConsumer(RetrieveModelMixin, UpdateModelMixin, GenericAsyncAPIConsumer):\n queryset = get_user_model().objects.all()\n serializer_class = UserSerializer\n\n\nConsumers that are not bound to Models\n--------------------------------------\n\n\nYou can also create consumers that are not at all related to any models.\n\n.. code-block:: python\n\n from djangochannelsrestframework.decorators import action\n from djangochannelsrestframework.consumers import AsyncAPIConsumer\n\n class MyConsumer(AsyncAPIConsumer):\n\n @action()\n async def an_async_action(self, some=None, **kwargs):\n # do something async\n\t return {'response with': 'some message'}, 200\n\n @action()\n def a_sync_action(self, pk=None, **kwargs):\n # do something sync\n\t return {'response with': 'some message'}, 200\n\nUsing your normal views over a websocket connection\n---------------------------------------------------\n\n.. code-block:: python\n\n from djangochannelsrestframework.consumers import view_as_consumer\n\n application = ProtocolTypeRouter({\n \"websocket\": AuthMiddlewareStack(\n URLRouter([\n\t url(r\"^front(end)/$\", view_as_consumer(YourDjangoView)),\n\t ])\n ),\n })\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/hishnash/djangochannelsrestframework", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "djangochannelsrestframework", "package_url": "https://pypi.org/project/djangochannelsrestframework/", "platform": "", "project_url": "https://pypi.org/project/djangochannelsrestframework/", "project_urls": { "Homepage": "https://github.com/hishnash/djangochannelsrestframework" }, "release_url": "https://pypi.org/project/djangochannelsrestframework/0.0.3/", "requires_dist": [ "Django (>=1.11)", "channels (>=2.1.1)", "djangorestframework (>=3.0)", "pytest (~=3.7.1); extra == 'tests'", "pytest-django (~=3.4.1); extra == 'tests'", "pytest-asyncio (~=0.9); extra == 'tests'", "coverage (~=4.4); extra == 'tests'" ], "requires_python": "", "summary": "RESTful API for WebSockets using django channels.", "version": "0.0.3" }, "last_serial": 4183252, "releases": { "0.0.2": [ { "comment_text": "", "digests": { "md5": "aeacf2fd15c700c49ddc10c5c236ef45", "sha256": "69e929034073e41a42e69dfed7d04b6032d1dafc9769edb8003841ef587bab96" }, "downloads": -1, "filename": "djangochannelsrestframework-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "aeacf2fd15c700c49ddc10c5c236ef45", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 17100, "upload_time": "2018-05-08T08:50:40", "url": "https://files.pythonhosted.org/packages/6e/e0/b0adcaab9bbacf18cc3616995a67f6f68782b782baf7e23ed52eb395264d/djangochannelsrestframework-0.0.2-py2.py3-none-any.whl" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "cd751fbbdcb67b78186addd52af62c44", "sha256": "3205d807cbb516ffbf33cf88e907f9b0ce11883dfc2ec355018272ef7f7cf687" }, "downloads": -1, "filename": "djangochannelsrestframework-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "cd751fbbdcb67b78186addd52af62c44", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14975, "upload_time": "2018-08-18T14:35:33", "url": "https://files.pythonhosted.org/packages/13/ef/0af881781a5ab9da3486c3ee55a1e177b190b793ee55fbd7e36b9cbb3d2a/djangochannelsrestframework-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "25063f35f41d09671c2dce47f64d00f3", "sha256": "db218c3a1c410ac8bb84bc19fd50c49394693eb8bad34232afdb7ddd06433b69" }, "downloads": -1, "filename": "djangochannelsrestframework-0.0.3.tar.gz", "has_sig": false, "md5_digest": "25063f35f41d09671c2dce47f64d00f3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13291, "upload_time": "2018-08-18T14:35:35", "url": "https://files.pythonhosted.org/packages/c7/8c/f7bdeb04bffeda5a8b5cd355b349a6b4425be2396bf9587d319d24ac543f/djangochannelsrestframework-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "cd751fbbdcb67b78186addd52af62c44", "sha256": "3205d807cbb516ffbf33cf88e907f9b0ce11883dfc2ec355018272ef7f7cf687" }, "downloads": -1, "filename": "djangochannelsrestframework-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "cd751fbbdcb67b78186addd52af62c44", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 14975, "upload_time": "2018-08-18T14:35:33", "url": "https://files.pythonhosted.org/packages/13/ef/0af881781a5ab9da3486c3ee55a1e177b190b793ee55fbd7e36b9cbb3d2a/djangochannelsrestframework-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "25063f35f41d09671c2dce47f64d00f3", "sha256": "db218c3a1c410ac8bb84bc19fd50c49394693eb8bad34232afdb7ddd06433b69" }, "downloads": -1, "filename": "djangochannelsrestframework-0.0.3.tar.gz", "has_sig": false, "md5_digest": "25063f35f41d09671c2dce47f64d00f3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13291, "upload_time": "2018-08-18T14:35:35", "url": "https://files.pythonhosted.org/packages/c7/8c/f7bdeb04bffeda5a8b5cd355b349a6b4425be2396bf9587d319d24ac543f/djangochannelsrestframework-0.0.3.tar.gz" } ] }