The core logic rests in a Python project, which is ready, and I am creating the UI using Django framework. The Python project uses ZMQ for messaging.
Is it wise to connect Django to ZMQ (from the Python project) to send and receive values? I am dealing with MultiAgent systems, and the core project is all about controlling few hardware devices in buildings.
Yes, it's in fact, a recognized pattern for solutions like you're working on.
I gathered for you some links that show diferent approaches:
Task queuing in Django with ZeroMQ
Long Running Taks in Web App/Django
This it's about RabbitMQ, but since RabbitMQ is a MOM (Message Oriented Middleware) too it might worth take a look this article: Django and asynchronous jobs
You might find interesting this package/application too: Django-ztask
I hope you find the ansewr you're looking for.
Related
I have a running CLI application in Python that uses threads to execute some workers. Now I am writing a GUI using electron for this application. For simple requests/responses I am using gRPC to communicate between the Python application and the GUI.
I am, however, struggling to find a proper publishing mechanism to push data to the GUI: gRPCs integrated streaming won't work since it uses generators; as already mentioned my longer, blocking tasks are executed using threads (subclasses of threading.Thread). Also I'd like to emit certain events (e.g., the progress) from within those threads.
Then I've found the Flasks SocketIO implementation, which is, however, a blocking execution and thus not really suited for what I have in mind - I'd have to again execute two processes (Flask and my CLI application)...
Another package I've found is websockets but I can't get my head around how I could implement this producer() function that they mention in the patterns.
My last idea would be to deploy a broker-based message system like Redis or simply fall back to the brokerless zmq, which is a bit of a hassle to setup for the GUI application.
So the simple question:
Is there any easy framework that allows to create a server-"task" in a Python that I can pass messages to publish to?
For anyone struggling with concurrency in python:
No, there isn't any simple framework. IMHO pythons' concurrency handling is a bit of a mess (compared to other languages like golang, where concurrency is built in). There's multiple major packages implementing this, one of them asyncio, but most of them are incompatible. I've ended up using a similar solution like proposed in this question.
I am developing my web app with Python 2.7 + Bottle. Everything is great and python is an amazing language coming from ASP.NET. I am building a web application that needs to use real-time client/server communication and socket.io for node.js comes to mind.
I wanted to know how can I implement socket.io-like using Python + bottle. I've read this article on bottle, but I can't still seem to understand how it works - what I need to install, and how all works out (code examples?).
I really need that for my next web application but need help in understanding what I need to put in my project in order for it to work. I have no problem working with 'preview' codes which aren't stable release yet. I'm developing on Windows platform. Thanks.
I also want to know if its scalabe. whether I can use redis in the back so all calls will be sync when running my website on several servers, so when one client send data, all the other clients connected to the other servers will get it to.
maybe websocket can help you,many modern browser support this protocol,but bottle.py don't support it now,you can get some idea from tornado.websocket and some answer here
cause every connection can be saved,so i guess it can run on several servers,but i never implement.
since bottle is micro framework,you should do something by yourself.
I have just started learning Django and my main aim is to build a company intranet website where I can do system administration things like backups, restore, etc.
I have found various Django tutorials about general web sites, but I could not find any tutorials / links where some have thought about doing system administration things via a web interface.
How can I use models / views and integrate with Python functions?
If all you want is to do administration tasks then I suggest using webmin. If you just want to do this to learn Django/Python then feel free to use the functionality of webmin as a guide. Think about all the steps involved in taking backups, moving files around and other administration tasks. This should help you understand the problem better and break it into manageable chunks.
Remember that Django is really just Python underneath, and it can be a vastly powerful tool. Try looking at some of your Python scripts that you use for systems administration. Maybe you can adapt those as a web interface.
Ansible does what you describe.
As Devin M says, Django is 'just Python' in the backend (that is, the functions your views call), so if you really wanted to, you could use a library like Fabric to invoke system administration actions without needing your web server to have direct access to the infrastructure.
You can use Python (Django) + SSH for doing all the system administration tasks. At my place, we built a web custom computer monitoring system with a system administration capability.
All you need is basically setting up a password-less SSH connection for each server. We chose to use the SSH key method. All system administration tasks were executed using SSH, for example ssh user#server1 'sh backupall.sh'. All that was left was creating a Python (Django) application which executes all these SSH commands.
I need to develop a web application with the following requirements:
Desktop like UI on the client side
Application deployment
Scalability (i.e. distributing the service on multiple servers)
What I thought of so far (as I love Python but haven't done much web development yet):
Django
Fabric (think I've read somewhere it's suited for this)
What I'm missing is:
How to create rich clients (probably need some javascript libraries for that)?
How to distribute the service?
For RIA you need to use some client technology in your templates.
See at Dojo or ExtJs.
ExtJs docs have example of Web Desktop app, but this library is not free for commercial project. I like more Dojo, and it is free.
Rich Internet Application: Javascript to do stuff asynchronously (AJAX). If you want a desktop-like interface on the web, it seems currently CoffeeScript is the way to go. It's a language that compiles into Javascript and adapted for rich interfaces.
Deployment: fabric (I think it's used to deploy Python apps).
Distribution: you deploy the code to one server.If you need to scale it up, you just need some additional servers (of course if you have specific usages like very high load on a database, you'll also need to add more database servers etc. But you get the idea).
using web browser as your client platform?
I need to develp a real production webservice with python that will be used by another client application (with another progamming language ) .
I mean in real production webservice that this webserivce is will be used on critical environment that failure of the webserivce could cause major problems.
could someone provide /suggest which library to use in order to build such webservice with python ?
I know that python has the built in simpleXMLRPCServer but i don't know its quality and if its apropriate for real production usage .
Python has been used to develop production grade web services. There are numerous framework to do that. (Django, Twisted etc).
You expect certain quality attributes from production grade servers like availability, scalability etc. For mission critical applications, availability becomes important. Your application architecture and development may influence these attributes more than the frameworks that you may use to develop them with. You can plan to provide extensive fault tolerance, redundant systems and various other strategies to improve availability.
This applies to building application with Python framework too.
Twisted is a very good framework to develop networking and web applications. There are other frameworks available in Python too, for example : Tornado etc
You can go through certain twisted docs and also the following blog posts that can help understanding twisted better.
Twisted in 60 seconds series
A very good twisted introduction
I have been exploring twisted basics and have posted a few notes at my blog
Twisted docs:
http://twistedmatrix.com/documents/10.1.0/web/howto/xmlrpc.html
Python: deferToThread XMLRPC Server - Twisted - Cherrypy?
http://nullege.com/codes/search/SimpleXMLRPCServer.SimpleXMLRPCDispatcher/all/1
http://code.activestate.com/recipes/526625-twisted-xml-rpc-server-with-basic-http-authenticat/
http://www.artima.com/weblogs/viewpost.jsp?thread=156396
Some projects along this line:
http://freshmeat.net/projects/python-xmlrpc-server-w-ssl-authentication
Django:
https://launchpad.net/django-xmlrpc
http://djangosnippets.org/snippets/2078/
http://www.drdobbs.com/184405364
http://www.davidfischer.name/2009/06/django-with-jsonrpc-and-xmlrpc/
Others:
http://www.f4ntasmic.com/2009/03/simple-xmlrpc-server.html
I hope this helps. :)