Python

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

Python-Lambda: The Essential Library for AWS Cloud Functions

Deploy AWS Lambda functions with ease with the help of a single Python library

In our series about building AWS APIs, we've covered a lot of ground around learning the AWS ecosystem. Now that we're all feeling a bit more comfortable, it may be time to let everybody in on the world's worst-kept secret: Almost nobody builds architecture by interacting with the AWS UI directly. There are plenty examples of how this is done,

Read

Create a REST API Endpoint Using AWS Lambda

Use Python and MySQL to Build an Endpoint

Now that you know your way around API Gateway, you have the power to create vast collections of endpoints. If only we could get those endpoints to actually receive and return some stuff.

We'll create a GET function which will solve the common task of retrieving data from a database. The sequence will look something like:

  • Connect to the database
Read

Create Google Cloud Functions Running Python 3.7

GCP scores another victory by trivializing serverless functions

The more I explore Google Cloud's endless catalog of cloud services, the more I really like Google Cloud. This is why before moving forward, I'd like to be transparent that this blog has become little more than thinly veiled Google propaganda, where I will henceforth bombard you with persuasive and subtle messaging to sell your soul to Google. Let's be

Google Cloud Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Oct 18
Read

Structuring your Flask App Like a Responsible Adult

Leverage Blueprints, Flask-Assets, and the Application Factory.

When we first started developing in Flask, most of us took the 5 lines of code in the quick-start guide and ran with it. Compared to every other web framework, getting a "Hello world" to flash on screen without being hassled with database configurations, template preferences, or reverse proxy setups felt a lot like robbing a bank.

At some point

Flask Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Oct 15
Read

Extract Nested Data From Complex JSON

Steal our code and never manually walk through JSON objects again

We're all data people here, so you already know the scenario: it happens perhaps once a day, perhaps 5, or even more. There's an API you're working with, and it's great. It contains all the information you're looking for, but there's just one problem: the complexity of nested JSON objects is endless, and suddenly the job you love needs to

Python Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Oct 10
Read

Reading and Writing to CSVs in Python

Playing with tabular data the native Python way.

Tables. Cells. Two-dimensional data. We here at Hackers & Slackers know how to talk dirty, but there's one word we'll be missing from our vocabulary today: Pandas.Before the remaining audience closes their browser windows in fury, hear me out. We love Pandas; so much so that tend to recklessly gunsling this 30mb library to perform simple tasks. This isn't

Python Todd Birchard avatarTodd Birchard Todd Birchard avatar
toddJan 15
Sep 27
Read

Using Random Forests for Feature Selection with Categorical Features

Python helper functions for adding feature importance, and displaying them as a single variable.

Notebook here.  Helper functions here.

One of the best features of Random Forests is that it has built-in Feature Selection.  Explicability is one of the things we often lose when we go from traditional statistics to Machine Learning, but Random Forests lets us actually get some insight into our dataset instead of just having to treat our model as a

Code Snippet Corner Matthew Alhonte avatarMatthew Alhonte Matthew Alhonte avatar
mattJan 15
Sep 24
Read

Flask Routing & Sessions: A Subtle Symphony

With great flexibility comes great responsibility

It isn't often you find somebody sad or miserable enough to detail the inner workings of web framework features, such as sessions or routing. This is understandably so; we use frameworks because presumably hate dealing with these things from scratch. This is especially so when it comes to Flask, which only released version 1.0 a few months ago, introducing

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

Tuning Random Forests Hyperparameters with Binary Search Part III: min_samples_leaf

Tune the min_samples_leaf parameter in for a Random Forests classifier in scikit-learn in Python

Part 1 (n_estimators) here
Part 2 (max_depth) here
Notebook here

Another parameter, another set of quirks!

min_samples_leaf is sort of similar to max_depth.  It helps us avoid overfitting.  It's also non-obvious what you should use as your upper and lower limits to search between.  Let's do what we did last week - build a forest

Code Snippet Corner Matthew Alhonte avatarMatthew Alhonte Matthew Alhonte avatar
mattJan 15
Sep 17
Read