Posted on 2012-08-18 14:01:42

Weblog in Python and Google App Engine

A friend of mine rhetorically posed a question: How Difficult would it be to start a blog from scratch?

Well, it won't really be from scratch. Nothing nowadays start from scratch. If kids of the 80s were the last to listen to cassette records and the first play with dvds, programmers of the 80s were the last to ever really write things from scratch, unless you are writing in PURE-C today. If you are like me, you call yourself a programmer even though you can't start a project if noone has yet written a convenience API or library. It's embarrassing to look at it that way, but it's the truth.

Besides, we aren't alone. Without those who wrote PHP, what will Matt Mullenweg use for Wordpress? And for python users, like me, I feel we stand on the shoulders of giants.

Some Personal History with Bloggin

I've had a personal website for more than a decade now. The first was hosted in geocities, Silicon Valley, 6823. I had hacks for Command & Conquer: Red Alert when game hacks weren't common yet. My redalert pack offered batmobiles that replaced the mammoth tank. I was in first year highschool. Such a long time ago! And the site was in pure html, showcasing a host of animated gifs.

And then, I, too, had a stint with flash based websites. And then came a time of moving from one free url provider to another. With, I had my friends write articles for me so I could post them online. Both friends wrote about love, typical topics for teenagers.

That was my first website that used CSS.

I tried maintaining blogs with iWeb, wordpress and blogspot. Of the three the one that offered the easiest experience formatting the page was iWeb. The one with most customizability was of course wordpress.

And today, or maybe this month, I take the next evolutionary step for my blog.

Lessons I've Learned

It's been more than a decade. I've learned some. I've made mistakes. The blog, my blog, has been changing along with me. And though I think my skills are far from exemplary, it's important to note the lessons you learn from each iteration so you don't have to repeat the same mistakes you had in the past. So here's what I think:

How Fast Can You Start Your Post is Important

You won't be online everytime an idea for a post presents itself. Neither will you have paper napkins or scratch papers available 24/7. If you are online, chances of having a tab open to the posting page of your blog, conveniently waiting for you to start typing, is small. Except if you are that resolute. Still, that's ridiculous!

The best place to write your posts is where ever you find yourself in when inspiration comes. In my case, that'll be from the shell. I hope in your case, it's not facebook.

CSS is Important, But...

CSS is important, and great, but CSS won't know how big your images should be or which class to use for it. For that, your blog needs to have a bit of "smart" written into it. A little artificial intelligence, if you will.

Markup Language is Painful

If you know HTML you know what I mean by how painful it is. Writing your posts should be painless. If you can just avoid all markup tags and write your posts in plain text, it would be fine and dandy. But you can't. At some point you'll have to add an image or a link or embed some youtube video. iWeb allowed for writing in rich text, but the minute you want to move to another system, you'll have to strip all the formatting and then you're back in square one.

Hence, I Knew My Blog Should Be...

Purely Python

One of the reasons I could barely move in my wordpress site was my lack of experience writing PHP. I wrote one plugin for WordPress. I was happy with it, well not really really happy. But it was okay. I thought it would be a first step among many. But Python is my language of choice and having the blog engine written in python can be a huge relief.


Shell Compatible

This is really important. I couldn't care less if there's no admin page on my blog. What's important is I could send my posts through shell. Whether I use XMLRPC or have my articles embedded in requests doesn't really matter. I don't think there are limits in any anyway. I just need to have posting available on my shell so I could write my articles in the comfort of VIM and post using my commandline tool.


I've seen my mood shift countless times in a year. That means I had to switch wordpress themes just as many times. The only theme that survived some length of time was the clean white theme I designed for my blog last. Clean white themes are classic. It won't matter how you feel, they'll be as clean and pretty as the first time you lay your eyes on them.


If it's clean white, it could feel flat. To make up for that, I'd have the page change as much as it should. Things that are important, like images and videos would automatically be formatted with proper sizes and all. But upon one click, they'll pop out and get full focus. I have floatbox to thank for that.

Smart Image Caching

The way I see things, you could either steal one of two things. Bandwidth or images. If you have posts with images linked from other websites, it's true you aren't stealing their images, you are however using up their bandwidth. To prevent that, I wrote a mini python server that caches and serves cached versions of all the images linked in my blog. When it makes caches of the image, it also makes versions of them of different sizes, depending on how I have it configured. I have thumbnailed, cropped, and letterboxed versions of all my images, aside from the raw version. Then depending on how the blog is asking for the image, it'll serve the correct image version.

Use Markdown

Markdown is the opposite of Markup. It allows you to avoid writing html tags and using rich text editors to write your posts. Instead you write using plain text. And then you use special syntax, special syntax that feels natural, that markdown uses to figure out which are the images, which are the links, which are the headers, the italicized text and etc etc..


I would say, the entire process wasn't so difficult. To write blog engines, you don't have to be a rocket scientist. My standards for the code aren't so high anyway. Especially since I have no intention to share my code. Although that could come later. I could write a version that people could develop on top of.

The difficult steps I had to take was converting my old posts into markdown versions. There was a slew of issues involving characters that weren't unicode friendly. I had to account for those and all the html tags I had no choice but to include in my old blog--some of which wordpress probably included voluntarily.

Aside from that, it was a breeze to write. And it's something I'd encourage every python programmer maintaining a website to do on their own, if they'd like to. Right now, I look at my blog, and there is not one part in the blog that I did not intend to have. Everything is as exactly the way I want it to be.


A few days after having the blog out and ready, I realized I missed the counters I used to have with wordpress. It took me less than a day to write the same functionility in this python version. Plus, I'm using the location services google is providing.

Technologies I'm Using

I told you before, we stand on the shoulders of giants. This blog won't be available if not for the hard work of those who wrote before us. Here's a list of packages who's technologies I made heavy use of. Thank you for making them free!

  • python
  • google app engine
  • markdown
  • jinja2

Technologies I had to reimplement

Aside from the blog, I had to rewrite a few technologies that were conveniently ready in PHP/wordpress. It's not so bad. Just these three.

  • image caching
  • pingback/trackbacks
  • tagging system

All in all, it was a pleasant experience.

2012-10-04 04:41:46.791250

Now I see what you meant you abandoned wordpress :)

2012-10-08 16:06:43.310110

yes, sir.