Jesper Noehr

Pythonista, RESTafarian, Binary Poet & Proud Bucketeer

Piston and Oberon

with 2 comments

I just wanted to do a quick write-up on a couple of things, because:

  1. I wanted to announce two upcoming projects of mine, and
  2. Getting a new post out there

Piston

Piston’s a django-app I’m writing for Bitbucket. It serves as sort of a “mini-framework” on top of Django for creating RESTful APIs. Well, actually it doesn’t tie you to be RESTful at all, as its url mapping facility hooks directly into Django.

A while back, jacobian wrote an article, “REST worst practices”, outlining some of the things a good implementation would need. I’m happy to say that Piston’s elegantly waltzing its way through the list, checking off his points one by one.

We don’t tie a resource to a model (although you easily can), we have plug-able authentication (with new handlers being a breeze to add), configurable output formats (in form of “emitters”, a simple dict-to-x facility, comes with emitters for JSON, YAML and XML), proper use of HTTP (status codes, headers) and CRUD semantics, and best of all, it ties right in to your Django application.

Anyway, I wrote it for Bitbucket, but it definitely merits an open source release and its own project. It’s behind closed doors right now, but nearing completion. Once we feel it’s good to release, we’ll do a release together with David Larlet, the author of Semantic Django (who else?)

Oberon

Oberon’s also something we use on Bitbucket. It’s a queue-based “application platform” based on Twisted. Vague, huh?

No, we use it for the service integration facility of Bitbucket. Oberon itself is just a daemon, serving as a message-passing facility between the client and what I call “brokers”. A broker is a piece of Python code that must satisfy two things:

  1. It must contain a class that subclasses “BaseBroker”, and
  2. That class must have a “handle” method receiving a single argument, “payload”

What this allows you to do is pretty nifty. You can load up a few of these brokers, and then using the client API, you can send messages to Oberon, and it’ll take it from there.

For example, we have a couple of brokers, like Twitter, which extracts the information it wants from the payload and uses a Twitter client library to post messages. There’s a Basecamp broker, and the most popular one thus far is the “Issue” broker, which parses commit messages and acts on them. Stuff like “great, all done, fixes #42″ will close up issue 42, and “hm, needs more work, references #37″ will add a comment to issue 37.

Best of all, and my favorite feature is ‘oberonc’, the command line client. It’s pretty basic but it has useful commands like ’stats’, ‘brokers’ and best of all: ‘reload’ — yep, that’s right, you can reload brokers on the fly without disrupting service. It works really well too, due to the way we’ve designed the application. It also means you can load up new brokers that have never been loaded before, so it makes it really interesting to upgrade running systems.

None is this stuff is tied into Bitbucket, so it has a vast variety of uses. It runs on top of ‘twistd’ as well so it should be pretty stable and scalable (it uses stuff like epoll.)

Anyway, Oberon’s also getting its own open source release, together with all the brokers we’ve written for the service integration we’re using on the live system. Those should serve as good examples.

I’ll post about both here, when they’re out.

Written by jespern

January 23rd, 2009 at 10:51 am

Posted in django, python

2 Responses to 'Piston and Oberon'

Subscribe to comments with RSS or TrackBack to 'Piston and Oberon'.

  1. As a matter of interest, have you looked into wapi that via http://fi.am ? I remember reading about all of the different things that it could do as he was developing it and it looked quite promising as well.

    Al

    30 Apr 09 at 1:26 am

  2. @Al,

    I have looked at ‘wapi’, but I couldn’t find any documentation on it, and it seems a lot bigger than what I would need.

    I settled on writing Piston because it was an interesting project, with incentive to Do It Right ™. django-rest-interface was lacking and it’s construction of API was just not a fit for me.

    Once fi.am writes up some documentation and gets a release of wapi out, I’ll check it out again, but so far, it’s barrier to entry is way too high.

    jespern

    2 May 09 at 3:30 pm

Leave a Reply