Python

Snippets of Python code, mostly in Flask.

Encoding / Decoding JSON objects in Python

Encoding / Decoding JSON objects in Python

A summary of how to serialize and deserialize from Python data structures into JSON-compatible strings, which is especially useful when working with API requests and responses.

Mar 12, 2019
Bit Manipulation Part 2 - Bitwise operators in Python

Bit Manipulation Part 2 - Bitwise operators in Python

A primer on bitwise operators in Python - left and right shifting, bitwise and / or / exclusive or, and complements.

Jan 18, 2019
Bit Manipulation Part 1 - Understanding binary numbers in Python

Bit Manipulation Part 1 - Understanding binary numbers in Python

An easy introduction to binary numbers, which will lead to a follow-up article on bit manipulation in Python.

Nov 13, 2018
Primer to Python multiprocessing, multithreading, and asyncio

Primer to Python multiprocessing, multithreading, and asyncio

Basic overview of parallel / concurrent programming, including comparisons between multiprocessing, multithreading, and asyncio (coroutines) in Python.

Oct 24, 2018
Method delegation in Python vs composition or inheritance

Method delegation in Python vs composition or inheritance

Using Python, a short example on how to delegate specified methods to another object, as compared to composition and inheritance.

Jul 11, 2018
Using Python enums in SQLAlchemy models

Using Python enums in SQLAlchemy models

How to use enums in your models to enforce value consistency.

May 16, 2018
Python command-line scripts with argparse

Python command-line scripts with argparse

A template file for using conditional arguments when running Python scripts from the command line.

Feb 15, 2018
SQLAlchemy merge, flush, commit, refresh: Key Differences Explained

SQLAlchemy merge, flush, commit, refresh: Key Differences Explained

I've always struggled to remember between these very similar methods in the SQLALchemy ORM - so I took some time out to research these and write it down.

Nov 2, 2017
Code Review Checklist - the most important things to look for

Code Review Checklist - the most important things to look for

A few notes on the code review process, and the steps I go through when reviewing.

Sep 21, 2017
SQLAlchemy Many to Many Relationships: An Example in Flask

SQLAlchemy Many to Many Relationships: An Example in Flask

Building model definitions for many-to-many relationships via a secondary table.

Jul 28, 2017
Bash script to relink alembic migrations

Bash script to relink alembic migrations

Sick of `alembic merge heads` slowing down your builds? Here's a short bash script I wrote to rename your migration files and update its down revision.

Jun 12, 2017
Using model callbacks in SQLAlchemy to generate slugs

Using model callbacks in SQLAlchemy to generate slugs

Dive into SQLAlchemy's little known `event.listen` method to automatically generate slugs when saving a model instance.

Feb 8, 2017
Overriding default Jinja attributes in Python view templates

Overriding default Jinja attributes in Python view templates

How to use the `do` Jinja extension to modify an existing dictionary in your view template.

Jan 30, 2017
Custom Jinja template filters in Flask

Custom Jinja template filters in Flask

A short snippet for creating a template filter, to present datetime objects in Jinja templates.

Oct 31, 2016
JSON field type in SQLAlchemy (Flask / Python)

JSON field type in SQLAlchemy (Flask / Python)

Want to store JSON-serialized data in your database? But sick of calling `json.loads()` and `json.dumps()` when dealing with this data in your Flask app? Read on!

Sep 9, 2016
Resolving alembic merge branch conflicts

Resolving alembic merge branch conflicts

How to fix alembic's "Multiple head revisions are present for given argument 'head'" error.

May 23, 2016
Using Python's Watchdog to monitor changes to a directory

Using Python's Watchdog to monitor changes to a directory

A small Python script to take action whenever a new file is uploaded to a directory or its contents change.

Feb 23, 2016
Data Pipelines - Airflow vs Pinball vs Luigi

Data Pipelines - Airflow vs Pinball vs Luigi

Review of 3 common Python-based data pipeline / workflow frameworks from AirBnb, Pinterest, and Spotify.

Jan 13, 2016
Line-by-line code profiling in Python

Line-by-line code profiling in Python

How to find slow sections in your Python code.

Oct 2, 2015
Made with JoyBird