Showing posts with label WSGI. Show all posts
Showing posts with label WSGI. Show all posts

Monday, May 27, 2013

Web Micro Framework Battle

WSGI Micro Framworks

這陣子一直在找適合的Micro Framwork玩第一次的Web Application.
最後選擇用Bottle, 原因是:

  • Single file module, no dependencies with other library.
  • Document

但是好不好用又是另一回事, 用了就知道..XD

以下是由WSGI.org列出的Micro Framwork:

  • bobo
    Bobo is a light-weight framework. Its goal is to be easy to use and remember.

  • Bottle
    Bottle is a fast and simple micro-framework for small web-applications. It offers request dispatching (Routes) with url parameter support, Templates, key/value Databases, a build-in HTTP Server and adapters for many third party WSGI/HTTP-server and template engines. All in a single file and with no dependencies other than the Python Standard Library.

  • Flask
    Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. It inherits its high WSGI usage and compliance from Werkzeug.

  • Pyramid
    Merger of the Pylons and repoze.bfg projects, Pyramid is a minimalist web framework aiming at composability and making developers paying only for what they use.

  • web.py
    Makes web apps. A small RESTful library.

Micro Framworks Battle

Rank Framwork Point
1 Bottle 7
2 pesto 6
3 itty 4
4 flask, cgi+wsgiref 3
5 werkzeug 2
6 web.py 1
7 cherrypy 0
8 bobo -7
9 aspen.io -5

Reference :
Web Micro Framework Battle 1
Web Micro Framework Battle 2

Tuesday, May 21, 2013

uWSGI & Nginx on Ubuntu

Install uWSGI

Configure uWSGI

$ sudo apt-get install python-dev python-pip  
$ sudo pip uwsgi  
################# uWSGI configuration #################  
pcre = False  
kernel = Linux  
malloc = libc  
execinfo = False  
ifaddrs = True  
ssl = True  
matheval = False  
zlib = True  
locking = pthread_mutex  
plugin_dir = .  
timer = timerfd  
yaml = True  
json = False  
filemonitor = inotify  
routing = False  
debug = False  
zeromq = False  
capabilities = False  
xml = expat  
event = epoll  
############## end of uWSGI configuration #############  
*** uWSGI is ready, launch it with /usr/local/bin/uwsgi ***  
Successfully installed uwsgi  
Cleaning up...  
$  

Test uWSGI

Create test file called hello.py:
def application(env, start_response):  
    start_response('200 OK', [('Content-Type','text/html')])  
    return "Hello WSGI!!"  
Run uWSGI:
uwsgi --http :8000 --wsgi-file hello.py  
Open browser connect on port 8000.
http://localhost:8000

Install Nginx

Configure nginx

$ sudo apt-get install nginx-full  
The configure file path : /etc/nginx/sites-enabled/default Add your site in nginx configure file.
    location /wsgi/ {
            uwsgi_pass 127.0.0.1:8001;
            include uwsgi_params;
    }  
Use localhost port 8001 for uwsgi protocol, and 80 port for nginx. Run uwsgi and start nginx.
$ uwsgi --socket :8001 --wsgi-file hello.py  
$ sudo service nginx start  
Test your web site:
http://your-ip/wsgi/  
or
http://localhost/wsgi/
Ref:
uWSGI Tutorial - Django and nginx
WSGI using uWSGI and nginx on Ubuntu 12.04 (Precise Pangolin)