Build an RSS Reader

Set up a Python project with Rye

Free preview

Resources

Python packaging! We love it dearly. To get started quickly, I recommend using Rye. Use the link in the resources section to install Rye.

rye init flask-htmx-tailwind
cd flask-htmx-tailwind
rye pin 3.12

Caution

Just recently, a bug was introduced in Rye that means we shouldn't use project names with - in them. Please choose a name such as flaskhtmx until the bug is fixed!

With these three commands you create your project folder, set up your virtual environment, set your Python version (and install it if you don't have it already).

To install requirements, either add them to pyproject.toml, or use rye add:

rye add "flask[dotenv]" jinja-partials feedparser
rye sync

Create a Flask app

When we set up the Rye project, it created the following structure:

flask-htmx-tailwind
  | - pyproject.toml
  | - README.md
  | - .python_version
  | - .gitignore
  | - src/
      | - flask_htmx_tailwind/
            | - __init__.py

This structure is important, as Rye requires it when we install dependencies or if we wanted to build the application for distribution in PyPI.

Let's go into __init__.py and create a simple Flask app:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, World!"

Then to run your Flask app you just do (from the project root, i.e. not src or src/flask_htmx_tailwind:

rye run flask run

You can also activate the .venv and run flask run as usual.