Latest articles

Subscribe via RSS

  • In this article I will show you how to deploy a FastAPI app as a function in Azure. Prerequisites are that you have an Azure account and have the Azure CLI installed (see here). Setup Azure First you need to login to your Azure account: It should show your subscriptions and you select the one you want to use. Create a resource group Like this: A resource group is a container that holds related resources for an Azure solution (of course use your own names throughout this guide). It comes back with the details of the resource group you just…


  • OpenStreetMap (OSM) is known for being an open source project that allows people to browse the world map and to plan routes. However it is more than that. Among others it provides a read-only API that allows users to query for very diverse map data: Overpass API Data structure of OSM To understand the structure of the queries, we first need to understand how OSM saves its data. OSM uses basic data structures: node, way, and relation. Each element can have multiple tags, which consist of a key-value pair and they help specify the features of each element. Nodes also…


  • “KeyError: ‘GOOGLE_APPLICATION_CREDENTIALS‘” It was way too early in the morning for this error. See if you can spot the problem. I hadn’t had my coffee before trying to debug the code I’d written the night before, so it will probably take you less time than it did me. app.py: file_handling.py: See the problem? This was just the discussion of a recent Pybites article. When app.py imported initialize_constants from file_handling, the Python interpreter ran and looked for GOOGLE_APPLICATION_CREDENTIALS from the environment path, but load_dotenv hadn’t added them to the environment path from the .env file yet. Typically, configuration variables, secret keys,…


  • A few examples that will save the day probably* 95% of time. *I don’t have the actual data but seriously, I bet you’ll find those tips useful more often than not! Introduction This article was originally posted on Medium. I use f-strings every day. The irony is I also every day end up searching the Web to find the correct format to use. Until one day I thought a better use of my time would be to create a cheat sheet of the most common formatting cases — AKA this article. It covers the following: It’s important to note that the f-strings were first…


  • Virtual environments are vital if you’re developing Python apps or just writing some Python scripts. They allow you to isolate different app requirements to prevent conflicts and keep your global OS environment clean. This is super important for many reasons. The most obvious one is requirements isolation. Let’s say that you’re working on two different projects: Although you can install both Python 3.6 and Python 3.10 globally on your OS, you may have to manually set the default version which may end up breaking some packages in your OS that expect the other version. As for other packages, “requests” in…


  • In this article I use the metric system, where 1 meter = 3.28 feet. I also talk about highways. Here I use the definition in British English, where highway refers to any path with a public right of access. We are all familiar with the existence of route planners like google maps or OpenStreetMaps (OSM), that allows us to get the shortest path between two points in space. With OSM and it’s read-only API Overpass we can get very detailed information about a chosen region, including streets roads and ways, but also information like if a street is illuminated, if…


  • Welcome to Hell Cue the theme song from The Fresh Prince of Bel Air. This is a story that turns out well. But my code got stuck in import hell. I tried to teach my students all about pytest. Instead, for two days, I was sent on a debugging quest. I teach middle school students how to code in python. I reckoned it was time to talk about the datetime module. Students generally love projects that they can connect back to themselves. So I thought a great way to introduce datetime was to have python calculate how many days the…


  • Introduction Two weeks ago I wrote an article about ABCs and interface enforcement. Shortly after I learned that you can do this as well with protocols. Python 3.8 introduced quite a groundbreaking feature that further advanced the language’s capabilities in type checking: the typing.Protocol which allows Python developers to define and enforce interface contracts in their code. Unlike traditional dynamic typing, which Python is well-known for, typing.Protocol brings a layer of static type checking that allows for more explicit, readable, and robust code by defining expected behaviors and structures. This feature not only enhances code quality and developer productivity but…