Not every idea needs the big rig. Sometimes you want the smallest possible Python server — and that's Flask.
There's a Python function that does the one thing you need — checks a price, formats a report, answers a webhook. It runs fine on your machine. But "runs on my machine" isn't a URL. You don't need React. You don't need a database. You need one address that, when something hits it, runs your function and hands back the answer.
"I had a little Python script that worked. I asked how to 'put it online' and the answer was a whole Next.js app, a frontend, a build step. That's a cathedral for a garden shed. I just wanted the script to answer when something called it."
"Right — wrong-sized tool. When the job is 'one Python function, behind one URL,' you reach for Flask: a few lines turns your script into a tiny web server. No frontend, no heavy framework. The big rig is for when you're building an app, not answering one request."
Flask is a tiny Python library that turns a function into a web endpoint. You map a URL path to a Python function; when a request comes in for that path, Flask runs the function and sends back whatever it returns. That's the whole idea. A handful of lines gets you a working server — which is exactly why it's the on-ramp: it's the simplest way to put Python behind a URL.
the home jobYou have a Python function that does one thing. Flask gives it an address so anything — a browser, another program — can call it.
"ping me when…"Stripe, GitHub, a form — they POST (a way of sending data to a URL) when something happens. Flask is a clean way to catch that and react.
just the dataReturn JSON (a simple text format for data that programs exchange) for another program to use. No pages, no UI — just an endpoint that answers.
When NOT to reach for it: if you're building a real web app — pages people navigate, a polished UI, login, a deploy-ready setup out of the box — that's Next.js, not Flask. Flask is deliberately bare: it doesn't come with a frontend. One more thing to file away: Flask's built-in server (what flask run starts) is a development server. It's perfect for building and testing on your machine; for real traffic you put a production server (like gunicorn) in front later — a routine swap.
@app.route("/") actually do?Below your import, you write @app.route("/") on the line above a function. Before the reveal — what is that line for?
pip; comments start with #; the server starts separately. @app.route(...) is doing something more specific — it's connecting a path to a function.@app.route("/") is a route: it tells Flask "when a request comes in for /, run the function on the next line and send back whatever it returns." Change "/" to "/price" and you've made a different URL. Routes are how one Flask app can answer several addresses.This is a complete, working Flask app — nothing left out. Reveal it, then watch it run.
Five real lines of logic. import Flask, make an app, attach the / route to a function, return some text, run. Now the terminal side — two commands. pip install flask to fetch the library (run this inside the virtual environment from the venv lesson — that's exactly what it's for), then start it:
flask run and python app.py both start the exact same dev server — they're two doors to one thing. flask run finds your app automatically, while python app.py uses the app.run() line at the bottom. Either way you get a local address: http://127.0.0.1:5000 — that's 127.0.0.1 (your own computer) on port 5000 (a numbered door on your computer). Open it in a browser and your function answers. That's a Python script, behind a URL. (On a Mac, if port 5000 is busy — AirPlay uses it — run flask run --port 5001.)
Same rule as always: answer it right, or the module isn't done.
Match the tool to the job, not the job to the tool. Flask is the smallest way to put Python behind a URL — reach for it when that's all you actually need.
A real, runnable app.py — the complete minimal Flask server with a home route and a tiny JSON API route, commented so you can see exactly what each line does — plus a requirements.txt so anyone (or any machine) can install it with one command. Drop it in a folder, pip install -r requirements.txt, flask run, and you have Python behind a URL.