Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.10 & Socket.IO with Python 3

I'm trying to find some "django-socketio" repo to use in my project. I using django 1.10 and python3. I really searched but I do not found working examples with python3.

My poor workaround

  • I started node project and put socket.io inside route
  • In my django view I send returning data to node route with my django session
  • I manage session coming from django inside my node and emit inside route to client.

This work but I can't believe this is a good solution.. Anyone have other ideas? Or working examples with python3 and socketio?

Thanks!

like image 755
Guilherme IA Avatar asked May 04 '17 13:05

Guilherme IA


People also ask

Is Django 1.11 still supported?

See the How to upgrade Django to a newer version guide if you're updating an existing project. Django 1.11 is designated as a long-term support release. It will receive security updates for at least three years after its release.

How do I use Django version?

Simply type python -m django --version or type pip freeze to see all the versions of installed modules including Django.

Is Django 4 backwards compatible?

This is the fourth “bugfix” release in the Django 1.1 series, improving the stability and performance of the Django 1.1 codebase. With one exception, Django 1.1. 4 maintains backwards compatibility with Django 1.1.


1 Answers

If you want to use Websockets and Django you should consider https://github.com/django/channels. The alternative in Python would be using python tornado http://www.tornadoweb.org/en/stable/ or aiohttp (Python3.4+) http://aiohttp.readthedocs.io/en/stable/. Many of the implementations of Django with asynchronousity through gevent are outdated, experimental or abandoned, I found this https://github.com/jrief/django-websocket-redis but it uses Redis so no reason to not going back to django-channels.

In my opinion, as Socket.io is a layer over Websockets you will not find any project that supports fully the Socket.io spec as a ws server in Python as it is a native Node.js not officially ported to Python project, at least the latest one you are probably using, if you really need Socket.io features stick to Node.js and create a simple REST API in Django to load the backend data asynchronously from Nodejs (the REST django API will always be synchronous by nature), this is the best shot you would likely have.

like image 106
danius Avatar answered Sep 20 '22 15:09

danius