uvwsgi: a Python WSGI server

I’ve been playing with Flask and WSGI in general for a few nights… at some point I started playing with pyuv and http-parser and before I realized I had a really basic WSGI server to play with: uvwsgi.

It’s not meant for production usage (yet) but should be really simple to understand, it’s less than 400 lines of code!

Here is a list of things I’d like to implement, in no particular order:

  • Multi-process support using socket sharing
  • Multi-process support using a single acceptor and a pool of worked which get connections dispatched round-robin
  • Update http-parser to the latest and greatest version
  • Automatically restart server if modules changed
  • Tests

You can install it from the cheese shop or get the code on GitHub.

Patches are welcome, of course 🙂

:wq

 

Serving a WSGI app, WebSockets and static files with Twisted

Long time no post! Lets solve that now shall we?

A few days ago I started playing a bit with Flask, since I’m considering it as the framework to build some API server. I have no web development experience, and Flask looks like a great project so I went with that.

I started with a tiny little hello world, and then I wanted to add some websockets and some CSS. Oh the trouble. When I started looking for how to combine a Flask app with WebSockets I found references to gevent-socketio for the most part, but I somewhat wanted to use Twisted this time, so I kept looking. Soon enough I found AutoBahn, a great WebSocket implementation for Twisted, which can be combined with a WSGI app, brilliant! After seeing how AutoBahn manages to add the websocket route to the WSGI app, adding support for static files was kind of trivial.

Here is the result of my experiments, a really simple web app which consists of a Flask WSGI app, a WebSocket server and some static files, all served by the same process running Twisted. You may not want to do this in a production environment, but hey, I’m just playing here 🙂

[gist]https://gist.github.com/saghul/5961882[/gist]

Since Gist does not currently allow folders, make sure you keep this layout after downloading the files:

├── app.py
├── settings.py
└── templates
    ├── assets
    │   └── style.css
    └── index.html

We’ll use the twistd command line tool to launch out application, since it can take care of logging, running as a daemon, etc. To run it in the foreground:

twistd -n -l - -y app.py

This will launch the application in non-daemon mode and log to standard output.

Hope this helps someone, all feedback is more than welcome 🙂

:wq