An rsync-like utility for Amazon S3 and Google Storage

Every so often I find myself working on that odd job that requires syncing files with Amazon's S3. In the beginning, I tried some of the various S3 FUSE interfaces—hoping for something that would play nice with rsync—but FUSE's stability always left something to be desired and more often than not I'd be left with that one transfer that never would quite finish correctly.

Eventually I discovered boto and settled in to using a hacked together (but stable) Python/boto solution for these type of tasks—all the while wondering why nobody took the time to write a "real" rsync-like client for S3.

Well, this last time around I finally decided to stop whining and take matters into my own hands. After a couple of late nights fleshing out my original boto solution, I'm happy to announce what I'm calling "boto rsync"—an rsync like wrapper for boto's cloud storage interfaces (both S3 and Google Storage).

Please take a look at the project on github and let me know what you think: http://github.com/seedifferently/boto_rsync

more...

Python as a PHP replacement?

I recently sat down to coffee with a new acquaintance of mine who spends much of his time implementing F/OSS projects at non-profit organizations, and who had just stepped into a lead web developer position using PHP. After sharing pleasantries we began trading stories and talking about each of our "tools of the trade." When I mentioned that I used to do most of my web development in PHP, but have spent the past year or so trying to move as completely as possible to Python, his response was: "Huh, I have never really thought of Python as a PHP replacement."

Now, this guy hasn't exactly been living under a rock for the past 10 years—his resume was quite impressive and included projects in a number of different programming languages—but as you can imagine, I was rather surprised by his response and it made me wonder: Has the Python community really been that bad at promoting the strengths of Python for web development? Or, does the nirvana experienced by switching from a language like PHP to Python just make us so at peace with the world that we forget the hordes of developers still stuck with C-style syntax? Either way, it got me thinking about a few of the reasons why I decided to switch from PHP to Python; and why I not only see Python as an excellent PHP replacement, but am surprised it is such a "best-kept secret" for web development.

There are already ...

more...

Reorganizing data with list & dict comprehensions

While writing scripts, I frequently run into the issue of needing to re-arrange sets of data into a more "process friendly" format. A common issue I encounter is needing to turn a list (array) into a dictionary (associative array) or vice versa. More often than not, I find myself needing to be able to access list elements by a key, but since they aren't setup in a dictionary I have to pull out a looping technique to reorganize the data for this to be possible.

Take the following set of data for example:

[[1, 'John Smith', 'admin'],
 [2, 'Jane Doe', 'superuser'],
 [3, 'Sam Jones', 'user']]

What we have here is a few rows of user data. In this example, the data is in a Python list (which in PHP would be an array).

In PHP, this would look something like (using print_r):

Array (
    [0] => Array (
        [0] => 1
        [1] => John Smith
        [2] => admin
    )
    [1] => Array (
        [0] => 2
        [1] => Jane Doe
# (...etc...)

So, what if I found myself writing some code that needed to be able to access each record by its first value, which in this case would be the user_id?

Well, in PHP the easiest way to make this happen would be a good-old-fashioned foreach loop:

foreach ($row as $val) {
    $out[$val[0]] = $val;
}

Not very "sexy" for something I find myself having to more often than I would like, but it works nonetheless.

Now, here's where the beauty of Python kicks in. Python has a built-in feature ...

more...