Everyone is more or less enthusiastic by the Google’s AppEngine initiative. But as you can imagine or know, it’s not that difficult to build similar web service using open source software.
AppEngine is very similar to web.py, and Aaron shows it building an application using web.py instead of Google’s webapp. I find webapp more javaish (response.out.write
) than pythonic (return
or print
).
// from: using webapp def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write(’Hello, webapp World!’)
And BigTable (on Wikipedia), a column-oriented database using the popular map/reduce to work in parallel and in a distributed way. CouchDB is a schema-less database also using a map/reduce algorithm to perform requests. CouchDB is different from BigTable; and Amazon’s SimpleDB appears to be a web service alternative to CouchDB (both are built with Erlang). With CouchDB you have the very hype map/reduce and revisions; and you can forget about all the SQL you already know (or GQL you’ll have to learn) in favor of JavaScript, nifty isn’t it?
So, a little introduction the CouchDB interface using Python. You may need to install it before (don’t miss the very helpful README file) and the Christopher Lenz’s Python interface.
from couchdb import client server = client.Server("http://localhost:5984/") db = server.create("test") # or db["test"] # if the database already exists.
So, we have a database. Le’ts put some data in it.
db.create({ "type": "Note", "content": "Hello World!" }) db.create({ "type": "Note", "content": "FizzBuzz" })
And query it:
notes = db.query(\ """function(doc){ map(null, doc) }""") for note in notes: print note.value["content"]
the map operation build the {key: value}
object you get. Any sorting operations are done on the key, for example: add the timestamp of when you created a note and use it as a key to have a date-sorted view. Views are an important concept of CouchDB. You have (afaik) to create them in order to perform sorting, ordering, slicing, … operations and they are optimized. Let’s create a view called notes
returning all document sorted by content
:
db["_design/notes"] = { "views": { "all": """function(doc) { if(doc.type === "Note") map(doc.content, doc); }""" } }
Now use it, selecting only one note (using count
):
notes = db.view(\ "_view/notes/all", \ count=1) for note in notes: print note.value["content"]
Find here (and the template) the CouchDB version of Aaron’s BigTable. The message is, you don’t need Google to create simple, straightforward web application. Of course, hosting your web.py/CouchDB application won’t be that cheap or easy but you won’t have to bother knowing how you’ll move your (users’) data out of AppEngine and not lose your users then.
Some people are already talking about creating their own AppEngine using CouchDB (via David). Are AppEngine and GQL worth reusing them? I don’t think AppEngine is either bad or evil, just that if you find the way applications are built cool, you can get that with open source bricks.
Is AppEngine a Facebook applications framework without Facebook? Outside of a social network (except if you consider that GMail is a social network) and with free hosting and bandwidth. Nothing is free. Facebook applications can live outside Facebook as some of them are like widgets/gadgets but can AppEngine applications live outside Google, if they want to?