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.
Related
I've made a small python script to scrap the web. I would like to make a nice and simple web interface where the user can enter data to search for and have the result displayed as a list.
I understand that there's many different ways to do that but don't know which one would be the best in my case.
I would like something :
Really simple and light
Running locally with the less dependencies possible.
So far I've thinking about :
A NodeJS server displaying content and executing the script
A web framework in Python (web.py, Flask, Django..?)
A local webserver (XAMPP) and cgi
Please note that I don't know much about web in python but I'm a bit used to NodeJS.
What would you recommend ?
Thanks, Victor
Personally I prefer gevent, bottle or Flask, and some front end framework like bootstrap or framework7.
Gevent easily makes it asynchronous and has websockets built right in, and bottle is the easiest (and fastest) way to build a web app or api.
Socket.io ist Very easy to send Data between Websites and scripts.
The Website Connect with the Socket.io Server and Inside the Server the Python Script can be executed
I've been trying websocket-client and socketio-client with no luck so far. The broad picture of what I want to accomplish is this:
Currently, I have a Flask Rest API that has both a web front-end and a command line interface, and it handles several different sets of file uploads/downloads. Both communicate with the server using HTTP requests, the web one from JQuery AJAX and the CLI uses python requests. I would like to switch to using sockets so that database changes from one client appear on all of them. I have been able to get Flask-SocketIO working between my JQuery and Flask server, but I'm struggling with getting any client libraries working from the CLI portion. Is there an easy to use python library for sockets similar to requests I should be using for this transition, or am I going in a totally wrong direction with making this switch?
Another option, unsure of the viability, would be to try and keep both the REST API for the CLI and have sockets for the web interface. Sounds very messy though.
After doing a lot of searching and messing around with various libraries, the one that was easiest to get up and running connecting a command line tool with a Flask-SocketIO webapp was socketIO-client.
This repository came in handy for the issues where I was struggling to understand how to correctly use the waits to receive info on the client side.
Once I've finished the project in a few weeks, I will come back and add more details so people finding this in the future can have an easier time getting this set up.
I am wondering how to go about implementing a web application with Python.
For example, the html pages would link to python code that would give it increased functionality and allow it to write to a database.
Kind of like how Reddit does it.
If you're looking for server side programming with databases and html templates etc, I think Django is great, along with Pyramid. However, I use Flask ( http://flask.pocoo.org/ ) for this since it is easy to use, learn and deploy even though it may not have as much support as the before mentioned 2 framework since it's just a microframework, using the Jinja2 templating engine, including a development test server with it's own debugger.
On the other hand, if you're going for client-side programming (i.e. in browser implementation ) You can look up .NET Ironpython or even Brython which uses python like javascript.
You might want to check out mod_wsgi or mod_python.
What Is mod_wsgi?
The aim of mod_wsgi is to implement a simple to use
Apache module which can host any Python application which supports the
Python WSGI interface. The module would be suitable for use in hosting
high performance production web sites, as well as your average self
managed personal sites running on web hosting services.
-
Current State of Mod_Python
Currently mod_python is not under active development. This does not
mean that it is "dead" as some people have claimed. It smiply means
that the code and the project are mature enough when very little is
required to maintain it.
This is a good article from the Python website:
http://docs.python.org/howto/webservers.html
Plain CGI is a good starting point to learn about server side scripting, but it is an outdated technology and gets difficult to maintain after certain level of complexity. I would think it is no longer used in industrial-grade web server anymore. Plus you have to setup a web server and then install some module to interpret python script (like Apache with mod_python) just to get started.
I had some experience with Django (https://www.djangoproject.com/) and found it fairly easy to get started with since they come with development test server. All you need to have is a Python interpreter + Django and you can get up-and-running quickly and worry about the deployment setup later. They have pretty good documentation for beginner as well.
We have never used Python for a web site without a framework. In our case that is Django. In other words, we do not use Python for our web sites the way Perl can be used, just having Apache run a Perl script.
The recommendations you have received about Django are sound. If you go the Django route, Graham Dumpleton and the modwsgi Google group were very helpful to me. I could
not have gotten mod_wsgi deployed on Red Hat Enterprise 5 64-bit without Graham's help.
Whether you choose Django or "straight" Python, you will need to become familiar with mod_wsgi.
Good luck in quantum time, which means by now, I hope this all worked out for you.
I am a PHP developer and am I want to use python for a project. What is the most common and simplest way to run python script on a server like apache or lighttpd? I am having trouble understanding how server languages that are not PHP or ASP run on servers.
In Python we have something called WSGI. But I believe this is too much for you right now. Grab a Python web framework, like Django. It comes with a web server and with good documentation on how to deploy it later. Play with it and things will start to clear up.
The longer version is that Python is a general purpose language - it's not designed for the web like PHP is. So you need a bit of work the get it to do web stuff and we already have some good frameworks for that (Django is the easiest to start with, so that is why I'm recommending it to you).
In general you should understand how the web works. It uses HTTP as a protocol for communication, which is build on top of the TCP stack, so a web application is just a server, that uses sockets (PHP has them as well as Python) and understands HTTP. Python comes with one build in - the SimpleHTTPServer, but it is not very good for production uses (it's great for development, though). This is why there are things like mod_wsgi (Python specific), FastCGI (general purpouse). Those things are basically ways for a real, production grade, web server (Apache, nginx) to talk to our python app and feed it the HTTP they get.
You can install gunicorn a Pure Python WSGI HTTP Server for UNIX. http://gunicorn.org/.
Typically, Apache is used with mod_python. See this mod_python tutorial
I'm a complete novice in this area, so please excuse my ignorance.
I have three questions:
What's the best (fastest, easiest, headache-free) way of hosting a python program online?
I'm currently looking at Google App Engine and Web Frameworks for Python, but all the options are a bit overwhelming.
Which gui/viz libraries will transfer to a web app environment without problems?
I'm willing to sacrifice some performance for the sake of simplicity.
(Google App Engine can't do C libraries, so this is causing a dilemma.)
Where can I learn more about running a program locally vs. having a program continuously run on a server and taking requests from multiple users?
Currently I have a working Python program that only uses standard Python libraries. It currently uses around 2.7gb of ram, but as I increase my dataset, I'm predicting it will use closer to 6gb. I can run it on my personal machine, and everything is just peachy. I'd like to continue developing on the front end on my home machine and implement the web app later.
Here is a relevant, previous post of mine.
Depending on your knowledge with server administration, you should consider a dedicated server. I was doing running some custom Python modules with Numpy, Scipy, Pandas, etc. on some data on a shared server with Godaddy. One program I wrote took 120 seconds to complete. Recently we switched to a dedicated server and it now takes 2 seconds. The shared environment used CGI to run Python and I installed mod_python on the dedicated server.
Using a dedicated server allows COMPLETE control (including root access) to the server which allows the compilation and/or installation of anything. It is a bit pricy but if you're making money with your stuff it might be worth it.
Another option would be to use something like http://www.dyndns.com/ where you can host a domain on your own machine.
So with that said, perhaps some answers:
It depends on your requirements. ~4gb of RAM might require a dedicated server. What you are asking is not necessarily an easy task so don't be afraid to get your hands dirty.
Not sure what you mean here.
A server is just a computer that responds to requests. On the dedicated server (I keep mentioning) you are operating in a Unix (or Windows) environment just like you would locally. You use SOFTWARE (e.g. Apache web server) to serve client requests. My vote is mod_python.
It's a greater headache than a dedicated server, but it should be much closer to your needs to go with an Amazon EC2 instance.
http://aws.amazon.com/ec2/#instance
Their extra large instance should be more than large enough for what you need to do, and you only turn the instance on when you need it so you don't have the massive bill that you get with a dedicated server that's the same size.
There are some nice javascript based visualization toolkits out there, so you can model your application to return raw (json) data and render that on the client.
I can mention d3.js http://mbostock.github.com/d3/ and the JavaScript InfoVis Toolkit http://thejit.org/