About
RIP is a WSGI-based Web programming framework for busy Web developers who have to build and maintain numerous applications and services. RIP is for those who don't want a lot of magic because they have been burned before (or have learned from the mistakes of others - even better); who want consistency without lock-in; who want to save time, but only when they are not going to have to pay it back with interest; who want a framework to get out of the way instead of having to work around it. RIP is not about gimmics or gagets or buzzwords, rather it attempts to be a decently elegant way to create real software.
Download
Download the latest release from RIP's Cheese Shop Page. (Blessed are the cheesemakers!)
Browse RIP's public subversion repository.
Read and subscribe to RIP updates and info.
Tutorial
This is the obligatory quick wiki tutorial for Rest in Python.
Install RIP
If you don't have setuptools, get it:
Then install RIP
Alternately, you can just download the source from the Cheese Shop or Subversion and install in the usual way.
For this tutorial we use pysqlite. You may be able to easy_install this, but if you are using Debian, like me, you might need to apt-get it
Create a New Project
Creating a new project is as easy as this:
From here on out we will assume that you are located in your project's root directory, for brevity's sake, so:
Handle Dependencies
We will use SQLObject for persistance and markdown for wiki text.
If your project depends on a package which is available
via easy_install, all you have to do is
add it to your setup.py:
Also, SQLObject does not play nice with code reloading
unless it is reloaded too, so we will need to
add "sqlobject" to the reloading list in ripwiki/cfg.py
Run Your App
Lets go ahead and install our project in dev mode:
Run the app like this:
You can now go to http://localhost:9999/ripwiki/ to see your app.
If you want to watch the log from a terminal on *nix, just do this:
The Model
Create ripwiki/model.py and make it look like this:
Then just run it one time, which creates your database and inserts one test record:
Generate a Little Code
Now lets generate a mapping, controller and view to handle wiki pages:
Customize Your URL Mapping
Mappings were created for you but we want to catch
arbitrarily named wiki pages. Lets say that we are
going to consider any GET request for
/ripwiki/pages/* to be a wiki page view.
Get rid of the wikipage mapping that was generated and replace it with this:
Wiki Page Controller
We will need to add few lines to our controller so that it looks up the page in the database and converts the wikitext to HTML like this:
Wiki Page View
We will need to modify our view just slightly to display our page name and generated HTML like this:
Now go to http://localhost:9999/ripwiki/pages/TestPage
Wiki Page Edit
Lets generate some more code:
Now we want to catch GET and POST requests for everything
like /ripwiki/edits/{page_name} so we will change
our mapping file again, replacing the generated mapping
with this:
Our controller is handling GET and POST because it needs to try to look up the wikitext, if it exists, for GET or POST, and update the wikitext, if we are POSTing.
See how we caught the exeception if the page did not exist, in which case we create it?
Notice how we redirect to the HTML view of the page once it is updated?
Of course, none of this will work with out an HTML form to edit the data in. Here is our view:
Notice how the h3 heading is a link back to the HTML
view of this page. (In case you want bail out on editing.)
Enhance the Wiki Page
One cool thing about wikis is that when you try to go
to a page that is not there, it lets you create it. Just
do this (you will have to import SQLObjectNotFound)
Also we can turn the wiki page name into a link to the edit the page:
WikiWords
To replace WikiWords with links we will add this into our controller:
and use it to process our wikitext before we generate HTML
Send Them Home
If a user makes a request for /ripwiki/ with or without
a trailing slash we can just send them to ripwiki/pages/IndexPage.
Edit the welcome controller to redirect them.
Security
Tell the controller that it should only be accessed by "editors."
Then simply add the group and users to your config file:
Of course in real life you will want to look these users up and their roles in your own way. A simple example might look like this:
Production Deployment
First of all, install the program:
Use Apache with mod_scgi and flup. Configure apache as follow. Be sure to pick an available port and configure both apache and your application to use it.
(You may also want to have apache handle your static content.)
To run your app as an SCGI daemon:
You will need some way for keeping this process running. For instance, you might just use an init script.
More Information
Rest in Python brings together a number of specialized components. As a result, it is also a loose and light framework. With RIP you can combine these packages and/or other you may choose to construct the right WSGI middleware stack to handle each request. These packages have (I think) decent documentation and readable source code so your imagination is the only limit.
These may also be of interest:
Questions, comments, suggestions, bugs... : luke.arno@gmail.com