Python

The language, the legend, the liberator. Includes Python hacks, tips, snippets and tutorials.

Psycopg2: Postgres & Python the Old Fashioned Way

Managing Postgres Database connections in Python with Psycopg2

Last time we met, we joyfully shared a little tirade about missing out on functionality provided to us by libraries such as SQLAlchemy, and the advantages of interacting with databases where ORMs are involved. I stand by that sentiment, but I’ll now directly contradict myself by sharing some tips on using vanilla Psycopg2 to interact with databases.

We never

Postgres Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Jan 15
Read

Pythonic Database Management with SQLAlchemy

The iconic Python library for handling any conceivable database interaction.

Something we've taken for granted thus far on Hackers and Slackers is a library most data professionals have accepted as an undisputed standard: SQLAlchemy.

In the past, we've covered database connection management and querying using libraries such as PyMySQL and Psycopg2, both of which do an excellent job of interacting with databases just as we'd expect them to. The nature

Read

Poetically Packaging Your Python Project

Manage your projects with Poetry to handle dependencies, envs, packaging, etc

It wasn't long ago that we Hackers were singing the praises of Pipenv: Python's seemingly superior dependency manager at the time. While we hold much love in hearts, sometimes there is love to go around. We just so happen to be fair weather fans, which reminds me: what has Pipenv done for me lately?

As you've probably guessed (considering its

Python Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Jan 08
Read

Using Redis to Store Information in Python Applications

A temporary data store for everything from session variables to chat queues

We're hacking into the new year strong over here at Hackers and Slackers, and we've got plenty of new gifts to play with in the process. Nevermind how Santa manages to fit physically non-existent SaaS products under the Christmas tree. We ask for abstract enterprise software every year, and this time we happened to get a little red box.

If

NoSQL Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Jan 05
Read

Tableau's REST API: Turning Tableau into an ETL Pipeline GUI

Organizing a heist on Tableau Server to reclaim workbook data

There's nothing I love more than exposing expensive enterprise software.

It may not seem obvious, but most SaaS products have an underlying core goal: shackle businesses to depend on proprietary, closed-source, costly software. When you pair a surplus of money with a reluctance to work, you've arrived at Corporate America: a prime victim yearning to marry itself to any vendor

Tableau Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Dec 29
Read

Globally Accessible Variables in Flask: Demystifying the 'Application Context'

Breaking down the nuances of the ‘app context’ in Flask's Application Factory

A 'skill' that's always fascinated me is just how long some engineers can make it in their career while carrying glaringly obvious gaps in their knowledge of the systems they use every day. To my surprise, I've turned corners where I myself have been that engineer all along, and there's perhaps no better example of this then the time I've

Flask Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Dec 19
Read

Geocoding Raw Datasets for Mapbox

Make sense of unstructured data with enough precision to put it on a map.

This wouldn't be a proper data blog unless we spend a vast majority of our time talking about cleaning data. Chances are if you're pursuing analysis that's groundbreaking (or worthwhile), we're probably starting with some ugly, untapped information. It turns out Mapbox has an API specifically for this purpose: the Mapbox Geocoding API.

Geocoding is a blanket term for turning

Data Vis Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Dec 18
Read

Geographic Data Visualization with Mapbox

Visualizing Geodata with Mapbox's API and Tools

There's a trend among those using Jupyter Notebooks (or equivalent) which leads me to believe humanity is coming to an important realization: Google Maps, as an API is expensive.

Regardless if Google maps is embedded as a consumer-facing widget, or part of a routine data-pipeline, a single surge of high-traffic can leave enterprises with price tags in the hundreds of

Data Vis Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Dec 11
Read

The Many Faces and Filetypes of Python Configs

Cleverly (or uncleverly) configure your Python project using .ini, .yaml, or .env files.

As we cling harder and harder to Dockerfiles, Kubernetes, or any modern preconfigured app environment, our dependency on billable boilerplate grows. Whether or not that is a problem is a conversation in itself. The longer I keep my projects self-hosted, the more  I'm consumed by the open-ended approaches people take to manage their project configuration variables.

Full disclosure here: this

Python Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Nov 29
Read

Scraping Data on the Web with BeautifulSoup

The honest act of systematically stealing data without permission

There are plenty of reliable and open sources of data on the web. Datasets are freely released to the public domain by the likes of Kaggle, Google Cloud, and of course local & federal government. Like most things free and open, however, following the rules to obtain public data can be a bit... boring. I'm not suggesting we go and

Python Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Nov 11
Read