{ "info": { "author": "Taoufik Abbassid", "author_email": "abacidtaoufik@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# \u2b50 Nejma \u2b50\n\n\nNejma \u2b50 allows you to manage multiple realtime connections and send messages to groups or a user multiple tabs...\n\n\nTake a look at this example `nejma-chat`, a simple chat application built using `nejma` and `starlette`.\n\n\n## Installation\n\n```shell\n$ pip install nejma\n```\n\n## Getting started \n\nHere's an example of using `nejma` with websockets.\n\nFirst import Channel and channel_layer from nejma\n\n```python\nfrom nejma import Channel, channel_layer\n```\n\nCreate a channel on connect\n\n```python\nasync def on_connect(self, websocket, **kwargs):\n await super().on_connect(websocket, **kwargs)\n\n self.channel = Channel(send=websocket.send)\n\n```\n\nAdd groups, channels or send messages \n\n```python\n async def on_receive(self, websocket, data):\n \t# Adds a channel to a giving group\n self.channel_layer.add(group, self.channel)\n\n # Removes a channel from a given group\n self.channel_layer.remove(group, self.channel)\n\n # Removes a channel from all the groups\n self.channel_layer.remove_channel(self.channel)\n\n # Reset all the groups\n self.channel_layer.flush()\n\n await self.channel_layer.group_send(group, \"Welcome !\")\n```\n\nFinnaly, remove the channel once the connection is closed \n\n```python\n async def on_disconnect(self, websocket, close_code):\n self.channel_layer.remove_channel(self.channel)\n```\n\n\n### Starlette\n---\n\nTo use `nejma` with `starlette`, simply import the WebSocketEndpoint from nejma\n\n```python\nfrom channels.ext.starlette import WebSocketEndpoint\n\n@app.websocket_route(\"/ws\")\nclass Chat(WebSocketEndpoint):\n encoding = \"json\"\n\n async def on_receive(self, websocket, data):\n room_id = data['room_id']\n message = data['message']\n username = data['username']\n\n if message.strip():\n group = f\"group_{room_id}\"\n\n self.channel_layer.add(group, self.channel)\n\n payload = {\n \"username\": username,\n \"message\": message,\n \"room_id\": room_id\n }\n await self.channel_layer.group_send(group, payload)\n```\n\n## Docs\n\nThe `ChannelLayer` class provided by `nejma` exposes the following methods :\n\n`add(group, channel)`\n\nAdds a channel to a giving group.\n\n```python\n\tself.channel_layer.add(group, self.channel)\n```\n\n`remove(group, channel)`\nRemoves a channel from a given group\n```python\nself.channel_layer.remove(group, self.channel)\n```\n\n`remove_channel(channel)`\nRemoves a channel from all the groups\n```python\nself.channel_layer.remove_channel(self.channel)\n```\n\n`flush()`\nReset all the groups\n```python\nself.channel_layer.flush()\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/taoufik07/nejma", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "nejma", "package_url": "https://pypi.org/project/nejma/", "platform": "", "project_url": "https://pypi.org/project/nejma/", "project_urls": { "Homepage": "https://github.com/taoufik07/nejma" }, "release_url": "https://pypi.org/project/nejma/0.1.0/", "requires_dist": null, "requires_python": ">=3.6", "summary": "Talk realtime with groups", "version": "0.1.0" }, "last_serial": 4805623, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "aa7e23f8cbd53ae3cb4daf53f8e72fce", "sha256": "4553ad7fd79282325ba5f0ccc8ac980809dc32bbea420a7c1a37ef0c34161c9e" }, "downloads": -1, "filename": "nejma-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "aa7e23f8cbd53ae3cb4daf53f8e72fce", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5108, "upload_time": "2019-02-11T11:56:51", "url": "https://files.pythonhosted.org/packages/4c/a5/044bdc4d0fe562ef76c915c4d745b8913a88348847702c86a8a43bbeabe0/nejma-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "70927e1e378257b68f3d242a0ad4bdd5", "sha256": "21700901af1eac11ff04854c3cefb8ef1f7d6abd831c89347a1a326bb1deac9b" }, "downloads": -1, "filename": "nejma-0.1.0.tar.gz", "has_sig": false, "md5_digest": "70927e1e378257b68f3d242a0ad4bdd5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3274, "upload_time": "2019-02-11T11:56:53", "url": "https://files.pythonhosted.org/packages/bf/85/c0a72b6c944b6349968575dd0fdcd602047ca105f171872156a4068febae/nejma-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "aa7e23f8cbd53ae3cb4daf53f8e72fce", "sha256": "4553ad7fd79282325ba5f0ccc8ac980809dc32bbea420a7c1a37ef0c34161c9e" }, "downloads": -1, "filename": "nejma-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "aa7e23f8cbd53ae3cb4daf53f8e72fce", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 5108, "upload_time": "2019-02-11T11:56:51", "url": "https://files.pythonhosted.org/packages/4c/a5/044bdc4d0fe562ef76c915c4d745b8913a88348847702c86a8a43bbeabe0/nejma-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "70927e1e378257b68f3d242a0ad4bdd5", "sha256": "21700901af1eac11ff04854c3cefb8ef1f7d6abd831c89347a1a326bb1deac9b" }, "downloads": -1, "filename": "nejma-0.1.0.tar.gz", "has_sig": false, "md5_digest": "70927e1e378257b68f3d242a0ad4bdd5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 3274, "upload_time": "2019-02-11T11:56:53", "url": "https://files.pythonhosted.org/packages/bf/85/c0a72b6c944b6349968575dd0fdcd602047ca105f171872156a4068febae/nejma-0.1.0.tar.gz" } ] }