Part 1 in a series of what I learned building a web app with Python and AWS
I recently began building my first full-stack web application: Herbly TeaMinder. The purpose is to help users make a great cup of loose-leaf tea by providing recommendations and tracking tea steeps.
Products like this are already on the market, for example MyTeaPal and Steeped. My intent with this project is to learn to make a scalable app. I used technologies like Python Flask framework, SQLAlchemy, PostgreSQL, and Amazon Web Services (AWS).
While I’ve been a Python user for over five years, this is my first foray into building an app from scratch. This series of posts documents my key learnings from this project.
Install Necessary Tools
The first thing you need to build a Python application with AWS is to get your tools together. GitHub and AWS have nice web interfaces. But command-line interface (CLI) speeds up your work. The very first step is to get familiar with Windows or Linux terminals like Bash or Powershell.
Then you will need to download Python itself. The Python website is a good place to start. There are also alternative providers like Anaconda. 1
Make sure Python and associated scripts, particularly pip, are on your executable path. This is done using the PATH environment variable. On Linux, set this variable to contain needed utilities in the $HOME/.bashrc script. This is automagically loaded when your terminal starts.
On Windows you can use the command-line, Windows Subsystem for Linux (WSL), or Windows Key → Control Panel → Edit the System Environment Variables.
I recommend a version control system (VCS). I chose GitHub for simplicity. Some alternatives include GitLab and Subversion.2
You also want an interactive development interface (IDE). Both PyCharm and Visual Studio Code are great for beginners. I like WindSurf for its native AI generation capabilities with Codeium.3
You can start developing on your home computer. But you will need to deploy your application to a production environment. This requires getting your own secure infrastructure or hooking into a cloud provider.
For this I chose Amazon Web Services with Elastic Beanstalk. To access this, you need to create an AWS account and set up for development. More on this in a future post.4
Virtual Environments Please Our Robot Overlords
Q: Why did the Python go to the doctor?
A: Because it was feeling a little snake-y after a bad byte!
Let’s set AI generated coding jokes aside. Creating virtual environments for your Python development projects is quite beneficial. Virtual environments isolate the dependencies of each project you work on. This prevents errors should they interfere with each other. Read more at W3Resources.5
Start by creating a folder for your Python project. I recommend first to create the repository in your VCS, in my case GitHub. Then I cloned the repository onto my local drive in E:\Git\herbly-teaminder.
Then navigate to your directory and run “python -m venv <name>”. The name can be anything memorable like “myenv” or “venv.” Next activate your environment. Use “venv\Scripts\activate” on Windows or “source venv/bin/activate” on Linux and Mac. It’s OK if these commands take a minute or two to run.
It’s best practice to store your project’s dependencies in the requirements.txt file. I have development only dependencies stored in requirements-dev.txt. Install dependencies using “pip install -r <file>”. Uninstall using “pip uninstall -r <file>”. Write your existing dependencies to file using “pip freeze > requirements.txt”.
You can exit your virtual environment when you’re done with it. Use the “deactivate” command.
Dependencies Demystified
So what dependencies do we need to run a web app? Take a look at my project’s requirements.txt. Here are some key highlights:
- Flask is a web framework that allows us to build and run a web application. My build includes:
- Flask-Limiter for rate-limiting requests to prevent server overload
- Flask-Talisman for security headers
- Flask-SQLAlchemy for relational database management
- Flask-Login for user authnetication
- Flask-Migrate for database migration
- boto3 and botocore for AWS integration
- gunicorn for the production web server
psycopg2-binary
for PostgreSQL supportpytest
for testing andmoto
for AWS mocking- A few utilities including:
python-dotenv
for environment variable managementemail-validator
for email validationpylint
for code quality checks
- The requirements-dev.txt also include a couple development utilities:
awsebcli
for AWS Elastic Beanstalk deployment managementflask-testing
for Flask application testing utilities
Thanks for reading homies. Stay tuned for the next post where I plan to dive into the nuts and bolts of a Flask application.
Stay hungry, stay foolish.