One day during my wife’s first pregnancy, it dawned on me that a lot of people would be interested to know when the baby was born. I began counting all the family members and friends who would want some notification about the baby’s arrival and realized I’d be making more phone calls than I would prefer. Sure, I could shove everyone into one big group text message, but then I run the risk of missing someone who might care while also subjecting myself to a seemingly endless cacophony of notification beeps.

To solve our endless beeping problem, we need a way to allow others to quickly learn about the birth of the child while notifying anyone who might care. We accomplish this using Python, Flask, and Twilio. With Twilio we can text or call anyone we like without the burden of doing so ourselves: all it takes is around 150 lines of Python.

What We’re Building

We want to take a list of phone numbers and have them each receive a call with a message of our choosing. WeI could guess at what numbers should be in that list, but it would be better if we did not have to manually enter numbers into a database. Since the purpose of this is to notify people about the birth of a child, it can not happen at a set time, so the application also needs to have a way to be triggered at a time of our choosing.

The application allows users to call a phone number and register their numbers to receive a call. When a specific text message is sent to that number, it uses Twilio to call each number in the list and read off a hard-coded message to the person, notifying him or her of the birth. This is functional and simple and will solve the problem for us nicely. A well-placed social media post containing the phone number for the application will then allow you to gather the phone numbers of everyone who might care about your child’s birth.

The Code

The project is written in Python and uses Flask. If you would like to skip the explanation you can see everything in its home on Github.

A SQLite database is sufficient for data storage. Flask-SQLAlchemy is a great extension that I highly recommend, but it is overkill for such a simple project, so let’s use Python’s built-in sqlite3 module instead.

Your Dev Environment

Flask is a micro web framework, and as such we do not need too much to get an application up and running. Let’s set up our project.

It is good practice when developing Python projects to use a virtual environment. Using your Python version of choice (preferably 3), install virtualenv if you haven’t already via pip ( pip install virtualenv ), then run virtualenv .venv in your project directory. Activate your virtual environment with source .venv/bin/activate on Linux or .venvScriptsactivate on Windows.

Next you need to install your dependencies in your virtual environment. This project will make use of the flask , twilio , and requests libraries. Install them via pip: pip install flask twilio requests . If you would like to use the exact versions of each library that I did, you can use my requirements.txt file). Save it to disk then run pip install -r requirements.txt . It should be noted that I used twilio version 5.6.0, which uses the TwilioRestClient you see in the code, rather than more recent versions (6+) using Client .