Author: Miguel Grinberg

It's Time For A Change: datetime.utcnow() Is Now Deprecated

Posted by
on under

I was going through the release notes of the new Python 3.12 version the other day, and one item caught my attention in the deprecations section:

datetime.datetime’s utcnow() and utcfromtimestamp() are deprecated and will be removed in a future version.

If you have followed my web development tutorials you must have seen me use utcnow() a lot, so I will clearly need to re-train myself to use an alternative, in preparation for the eventual removal of this function (likely a few years out, so no need to panic!).

In this short article I'll tell you more about why these functions are getting the axe, and what to replace them with.

Some More To Talk About Flask

Posted by
on under

A few days ago I published a harsh critique of the Flask's team practices with regards to releases, versioning and especially about their weak backwards compatibility track record. This generated a bit of a stir and lots of people, including members of the Flask core development itself, have voiced their opinions.

I'm going to start by admitting that even though I have received some support, there has been a lot of push back as well. I really have no problem with this, as I don't hide from criticism. In this follow up article I'm going to talk about the good and the bad takes that resulted from my blog post, but I especially want to dissect the opposing views.

We Have To Talk About Flask

Posted by
on under

Flask 3.0 was released on September 30th, 2023, along with a parallel 3.0 release of Werkzeug, its main dependency. That day, the Flask-Login extension, one of the most popular of all Flask extensions, stopped working due to a backwards incompatible change introduced in Werkzeug. It is October 19th when I'm writing this, and Flask-Login remains broken. As a result, any person using my Flask Mega-Tutorial will hit issues, because my tutorial uses Flask-Login. Not only that, every Flask tutorial that features Flask-Login, from every author, in every language, in written or video form, is going to fail for as long as this problem remains. Hard to believe, right? (Update: a fixed release of Flask-Login was published on October 30th)

If this was the first occurrence of something of this nature in the Flask community, I would hope it would serve as a lesson for the Flask maintainers to learn from and avoid in the future. Sadly, this happens pretty much every time there is a major release of Flask, and sometimes minor ones too. Why does this happen? How can it be avoided? In this article I'll try to make an assessment of the current situation and how it can be prevented going forward.

There is now an update to this post as well.

Building a Toy Programming Language in Python, Part 2

Posted by
on under

Welcome to the second part of my tutorial on creating a toy language I called my in Python. In the first part I showed how how to implement the lexer, parser and interpreter for a very simple version of the language that did only one thing: print numbers.

With the first phase of the project completed, and with a solid base to start building from, I'll show you how to extend the language in a few ways. The purpose of this is to demonstrate how to modify this language, so that you can then build your own extensions. If you need a reference for the code, this GitHub repository has the working code that you can try.

Building a Toy Programming Language in Python

Posted by
on under

I thought it would be fun to go outside of my comfort zone of web development topics and write about something completely different and new, something I have never written about before. So today, I'm going to show you how to implement a programming language!

The project will parse and execute programs written in a simple language I called my (I know it's a lame name, but hey, it is "my" language). The implementation is going to be in Python, without any external dependencies. The my language is simple enough to make this project reasonably short, but also complex enough to make it interesting. If you are only interested in the complete code, you can find it in this GitHub repository. If you want to learn, then read on!

In this first installment of this series, I'll show you how to build a very basic programming language that implements a print statement. Then in the second part I'll extend the language to support variables and mathematical expressions. The end goal is a programming language implementation that can execute programs such as this one:

a = 3
b = 4 + a * 2
print b + 1

Once you learn the techniques involved in bringing my to life, you will be able to extend the language in any way you like and make it yours too. Sounds interesting? Let's get started!

Goodbye, Twilio

Posted by
on under

As of this week and after almost four years, I'm not a Twilio employee anymore. I'm writing this while I work through a range of conflicting emotions, and try to adapt to new daily routines without Twilio in my life. Before you jump to conclusions let me clarify that I have not been laid off. The decision to leave the company was mine alone.

When I joined Twilio in 2019, this is how the company presented itself to the world, as seen through the famous billboard on the 101 freeway in San Francisco:


Twilio - Ask Your Developer

The three words in this billboard are possibly one of the best marketing campaigns of all times (I'm not the only one who thinks so). With such a simple message, Twilio established itself as a company for and by developers. Even though I never lived in San Francisco, I visited for work and pleasure countless times, and have always considered the Twilio billboard a welcoming landmark as I drove from the airport to the city. When I eventually joined Twilio, it was a dream come true for me.

OAuth Authentication with Flask in 2023

Posted by
on under

A long time ago I wrote a tutorial on how to add logins with a social network to your Flask application, using the OAuth protocol. It's been almost 9 years since I wrote that article, and believe it or not, the OAuth protocol continues to be well supported by all major players including Twitter, Facebook, Google, GitHub and many more.

But of course, 9 years is a very long time in tech. Even though not much has changed in terms of how this method of authentication works, some of the packages that I've used back then have had major upgrades, while others have become unmaintained, so an update is due.


Flask + OAuth 2.0 Demo

Create a MySQL Database using Docker

Posted by
on under

MySQL is an open-source relational database owned by Oracle Corporation. The instructions I'm going to share in this article demonstrate how to install and set up a MySQL server along with the popular phpMyAdmin management application. As a bonus, I will also show you how to set up Python to access your MySQL database.

This article is an excerpt from my book SQLAlchemy 2 In Practice, where I show how to work with relational databases using Python and the SQLAlchemy library.

What's New in SQLAlchemy 2.0?

Posted by
on under

You may have heard that a major version of SQLAlchemy, version 2.0, has been released in January 2023. Or maybe you missed the announcement and this is news to you. Either way, I thought you'd be curious to know what's new in it, if it is worth upgrading and how difficult the upgrade is.

As with previous software reviews, this is going to be an opinionated overview. I have been using the SQLAlchemy ORM in web projects for a long time, so in this article I will discuss the features that affect my own work, both in positive or negative ways. If instead you are interested to see a list of every change that went into this new release, then the official change log is the place to go.

The React Mega-Tutorial, Chapter 12: Production Builds

Posted by
on under

You have an application that you have been using in your own computer during development. How do you put this application in front of your users? In this chapter you are going to learn how to work with production builds of your application.