{ "info": { "author": "Vladimir Denisov", "author_email": "UNKNOWN", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development", "Topic :: System :: Networking" ], "description": "# Centrifuge-python (work in progress)\n\nThis is a websocket client for [Centrifugo](https://github.com/centrifugal/centrifugo) server on top of Python asyncio library.\n\nUsage example:\n\n```python\nimport time\nimport json\nimport asyncio\nfrom cent import generate_token\nfrom centrifuge import Client, Credentials\n\n\ndef run(loop):\n\n # Generate credentials.\n # In production this must only be done on backend side and you should\n # never show secret to client!\n user = \"3000\"\n timestamp = str(int(time.time()))\n info = json.dumps({\"first_name\": \"Python\", \"last_name\": \"Client\"})\n token = generate_token(\"secret\", user, timestamp, info=info)\n\n address = \"ws://localhost:8000/connection/websocket\"\n credentials = Credentials(user, timestamp, info, token)\n client = Client(address, credentials)\n\n yield from client.connect()\n\n @asyncio.coroutine\n def message_handler(**kwargs):\n print(\"Message:\", kwargs)\n\n @asyncio.coroutine\n def join_handler(**kwargs):\n print(\"Join:\", kwargs)\n\n @asyncio.coroutine\n def leave_handler(**kwargs):\n print(\"Leave:\", kwargs)\n\n yield from client.subscribe(\n \"public:chat\",\n on_message=message_handler,\n on_join=join_handler,\n on_leave=leave_handler\n )\n\n\nif __name__ == '__main__':\n loop = asyncio.get_event_loop()\n asyncio.ensure_future(run(loop))\n try:\n loop.run_forever()\n except KeyboardInterrupt:\n print(\"interrupted\")\n finally:\n loop.close()\n```\n\nOr with Python 3.5 async/await syntax:\n\n```python\nimport time\nimport json\nimport asyncio\nfrom centrifuge import Client, Credentials\nfrom cent import generate_token\n\n\nasync def run():\n\n # Generate credentials.\n # In production this must only be done on backend side and you should\n # never show secret to client!\n user = \"3000\"\n timestamp = str(int(time.time()))\n info = json.dumps({\"first_name\": \"Python\", \"last_name\": \"Client\"})\n token = generate_token(\"secret\", user, timestamp, info=info)\n\n credentials = Credentials(user, timestamp, info, token)\n address = \"ws://localhost:8000/connection/websocket\"\n\n async def connect_handler(**kwargs):\n print(\"Connected\", kwargs)\n\n async def disconnect_handler(**kwargs):\n print(\"Disconnected:\", kwargs)\n\n async def connect_error_handler(**kwargs):\n print(\"Error:\", kwargs)\n\n client = Client(\n address, credentials,\n on_connect=connect_handler,\n on_disconnect=disconnect_handler,\n on_error=connect_error_handler\n )\n\n await client.connect()\n\n async def message_handler(**kwargs):\n print(\"Message:\", kwargs)\n\n async def join_handler(**kwargs):\n print(\"Join:\", kwargs)\n\n async def leave_handler(**kwargs):\n print(\"Leave:\", kwargs)\n\n async def error_handler(**kwargs):\n print(\"Sub error:\", kwargs)\n\n await client.subscribe(\n \"public:chat\",\n on_message=message_handler,\n on_join=join_handler,\n on_leave=leave_handler,\n on_error=error_handler\n )\n\n\nif __name__ == '__main__':\n loop = asyncio.get_event_loop()\n asyncio.ensure_future(run())\n try:\n loop.run_forever()\n except KeyboardInterrupt:\n print(\"interrupted\")\n finally:\n loop.close()\n```\n\n### TODO\n\n* [connection refresh](https://fzambia.gitbooks.io/centrifugal/content/server/connection_check.html) support\n* functional tests\n* more detailed API description", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/centrifugal/centrifuge-python", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/centrifugal/centrifuge-python", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "centrifuge-python", "package_url": "https://pypi.org/project/centrifuge-python/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/centrifuge-python/", "project_urls": { "Download": "https://github.com/centrifugal/centrifuge-python", "Homepage": "https://github.com/centrifugal/centrifuge-python" }, "release_url": "https://pypi.org/project/centrifuge-python/0.1/", "requires_dist": null, "requires_python": null, "summary": "Websocket client for Centrifugo on top of asyncio library", "version": "0.1" }, "last_serial": 2578281, "releases": { "0.1": [] }, "urls": [] }