Justin Duke

Django vs. Flask

A great, thorough writeup on Django vs. Flask has been floating around the past few days. It’s a great technical breakdown, and I agree with the conclusion:

There’s an informal perception that Batteries included may mean a growing list of ill-maintained API’s that get hooked into every request. In the case of Django, everything works across the board. When an internal Django API changes, Django’s testsuites to break and the appropriate changes are made. So stuff integrates. This is something that’s harder to do when there’s a lot of packages from different authors who have to wait for fixes to be released in Flask’s ecosystem.

However, it also glosses over what is probably the strongest weapon in Django’s arsenal: Django Rest Framework. At this point, I essentially consider DRF a first-party package: it is so completely essential to my Python web development toolbox I can’t imagine working without it.

Having such a powerful, extensible approach to REST (and everything that entails: serialization, permissions, filtering…) is invaluable. Flask is great for toy projects, but for a modern application DRF is unreplaceable, and thus so is Django.

(Another important thing that Django does: it forces a certain level of structure and organization to your application. I used to think this was either unnecessarily or actively harmful: now, having seen my fair share of eldritch Python codebases, I know better.)


Extracting an image from an RSS feed in Python

I have a bit of a social media automation thing set up for Barback, in which I tweet articles from some of my favorite cocktail and liquor blogs. I’m pretty new to the whole social media shtick, but a lot of places recommend adding images and other media to increase engagement, so I set out looking for a way to grab images from the RSS feeds where I get articles.
Read more →

Crawling Tumblr with multiprocessing

Your mission, should you choose to accept it Let’s say you want to crawl Tumblr. I’m choosing Tumblr here because it’s a relatively interesting example: unlike Twitter, which is super transparent about its social graph, or Facebook, whose social graph is fairly dense across geographic spectra 1, there’s not that much known about the Tumblr social graph. Plus, getting follower and following lists programmatically is impossible for anyone besides yourself, barring OAuth (which doesn’t exactly jive with the whole crawling thing).
Read more →

Python inline shenanigans

You are likely already aware of most of Python’s inline greatness, like ternaries: value = x if a > 10 else y And comprehensions: names = [e.name for e in employees] capitals = {city.state : city.name for city in capital_cities} But there are a few more obscure (though none-the-less super-useful) ones that people don’t seem to know about. Watch the magic unfold! The power of if Do you have annoyingly redundant code that looks like this, checking to see if a value exists and assigning a fallback if necessary?
Read more →

Basic linear regressions in Python

Linear regressions are a great tool for any level of data exploration: chances are, if you’re looking to investigate the relationship between two variables, somewhere along the line you’re going to want to conjure a regression. So how do you accomplish that in Python? First, let’s grab some test data from John Burkardt at FSU: specifically, some toy housing data which contains – amongst other things – the area of the site in thousands of square feet and the final selling price.
Read more →

How to send emails through Python and GMail

(I apologize in advance for the robotic tone of this blog post.) This is a quick blog post about sending emails through Python’s builtin SMTP library, using GMail as your email server. It’s not complicated, I promise. This is how you you log into GMail in Python: import smtplib # The below code never changes, though obviously those variables need values. session = smtplib.SMTP('smtp.gmail.com', 587) session.ehlo() session.starttls() session.login(GMAIL_USERNAME, GMAIL_PASSWORD) This is how you send an email in Python:
Read more →


We’ve all been there - working on a one-off script or personal project where you deal with lots of tuples: maybe points on a coordinate grid or time-series data, or anything imported from a csv. You do the lazy thing and keep track of everything in a list of tuples, shrugging off that object-oriented nagging in the back of your head. Python, as always, has a solution for your troubles, hidden in a rarely-accessed collections submodule.
Read more →

A gentle introduction to itertools

itertools is pretty much the coolest thing ever. Despite a vaguely technical name and a decreased emphasis in most introductory Python materials, it’s the kind of builtin package that makes list comprehensions much less of a syntactical mess. The biggest barrier to using itertools is that there are, well, a lot of methods that tend to all do similar things. With that in mind, this post is a showcase of some of the more basic — yet completely rad — things you can do with these methods.
Read more →
© 2017 Justin Duke • All rights reserved • I hope you have a nice day.