What is Flask in Python? Beginner Guide with Hello World App (2026)
Aug 04, 2026 4 Min Read 3334 Views
(Last Updated)
If you’re learning Python and want to build something you can actually see in a browser, Flask is usually where that journey starts. It’s a micro web framework, which means it hands you the essentials and lets you decide the rest.
You won’t find a built-in database layer or admin panel here. What you get instead is control, and a framework that stays out of your way while you learn.
Table of contents
- TL;DR Summary
- What is Flask in Python?
- Flask Hello World: Your First Flask App
- Flask vs Django vs FastAPI
- When to Use Flask vs Django: Decision Guide
- Flask for Beginners: Build Your First REST API in 30 Minutes
- Common Mistakes Beginners Make with Flask
- Conclusion
- FAQs
- What is Flask used for in Python?
- Is Flask good for beginners?
- Is Flask faster than Django?
- Should I learn Flask or FastAPI first?
- Can Flask handle large applications?
- Do I need to know HTML to use Flask?
TL;DR Summary
- Flask is a lightweight Python web framework used to build web apps and APIs quickly.
- It gives you routing, request handling, and templating, without forcing a fixed project structure.
- You can build and run a working Flask app in under 10 lines of code.
- Flask suits small projects, prototypes, and APIs. Django suits large, feature-heavy applications. FastAPI suits high-performance APIs with type checking.
- Companies like Netflix and Reddit use Flask in parts of their stack.
What is Flask in Python?

Flask is a lightweight web framework written in Python, built on two smaller libraries: Werkzeug, which handles the low-level web server communication, and Jinja2, which renders your HTML templates. Armin Ronacher created it in 2010.
Because Flask keeps its core small, you can read through most of its source and actually understand what’s happening. That matters a lot when you’re debugging your first app and don’t want to dig through layers of hidden framework magic.
Here’s what Flask gives you out of the box:
- A routing system to map URLs to Python functions
- Built-in request and response handling
- A development server with live debugging
- Jinja2 templating for dynamic HTML pages
Flask Hello World: Your First Flask App
You don’t need much to get Flask running. Install it, write a few lines, and start the server.
Step 1: Install Flask
pip install Flask
Step 2: Create app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)
Step 3: Run it
python app.py
Open your browser and go to http://127.0.0.1:5000. You should see your “Hello, World!” message on the page.
A quick breakdown of what each part does:
Flask(__name__)creates your application instance@app.route('/')maps the home page URL to the function below itreturn 'Hello, World!'sends that text back as the responseapp.run(debug=True)starts the server and reloads automatically when you edit code
That’s the entire loop you’ll repeat for every Flask project: define a route, write a function, return a response.
Flask vs Django vs FastAPI

Choosing a framework is usually the first real decision you’ll make as a beginner. Here’s how the three compare on the factors that actually affect your project.
| Factor | Flask | Django | FastAPI |
|---|---|---|---|
| Size | Micro framework, minimal core | Full stack, batteries included | Lightweight, API focused |
| Speed | Moderate, around 2,000 to 3,000 requests/sec | Moderate, slower on large apps | High, around 15,000 to 20,000 requests/sec |
| Best use case | Small apps, prototypes, microservices | Large apps needing built-in admin, auth, ORM | APIs needing speed and type validation |
| Learning curve | Gentle | Steeper, more concepts upfront | Moderate, needs comfort with type hints |
| Built-in ORM | No | Yes | No |
| Async support | Limited | Improving, not default | Native |
When to Use Flask vs Django: Decision Guide
Both frameworks solve the same basic problem, but they solve it differently. Use this as a quick filter before you start coding.
- Choose Flask if you want full control over your project structure and plan to add only the pieces you need.
- Choose Django if your app needs user authentication, an admin dashboard, and a database layer without setting each one up yourself.
- Choose Flask for a small team or solo project where speed of learning matters more than built-in features.
- Choose Django for a large application, like an e-commerce platform, where consistency across a big codebase matters.
- Choose Flask if you’re still learning web development and want to understand how each piece connects.
Neither is objectively better. Flask trades built-in features for flexibility. Django trades some flexibility for a faster path to a full-featured app.
Flask for Beginners: Build Your First REST API in 30 Minutes
Once you’re comfortable with Hello World, the natural next step is a small REST API. Here’s a simple one that returns a list of books.
from flask import Flask, jsonify, request
app = Flask(__name__)
books = [
{"id": 1, "title": "Atomic Habits"},
{"id": 2, "title": "Deep Work"}
]
@app.route('/books', methods=['GET'])
def get_books():
return jsonify(books)
@app.route('/books', methods=['POST'])
def add_book():
new_book = request.get_json()
books.append(new_book)
return jsonify(new_book), 201
if __name__ == '__main__':
app.run(debug=True)
What’s happening here:
GET /booksreturns your full list as JSONPOST /booksreads the incoming JSON body and adds it to the listjsonify()converts your Python data into a proper JSON response
Run this file the same way as before, then test it with a tool like Postman or curl. In half an hour, you’ve gone from a single “Hello, World!” route to a working, testable API endpoint. This is exactly why Flask is a common first choice for beginners building REST APIs.
Common Mistakes Beginners Make with Flask

- Naming the file flask.py: This clashes with the Flask package itself and throws confusing import errors. Stick to app.py or main.py.
- Forgetting debug mode in development: Without
debug=True, you lose the auto-reload and the in-browser error traceback that make fixing bugs faster. - Skipping virtual environments: Installing Flask globally can cause version conflicts across projects. Create a virtual environment for each project instead.
- Not returning JSON in APIs: Returning plain Python dictionaries without
jsonify()can cause inconsistent responses. Always wrap API output injsonify(). - Hardcoding the port: Assuming port 5000 is always free causes errors on some systems, especially macOS. Use
flask run -p 8000when needed.
To keep things engaging, here are a couple of lesser-known facts about Flask that might surprise you:
Flask Started as a Joke: Flask was originally created by Armin Ronacher in 2010 as an April Fools’ Day joke. Despite its playful beginnings, it quickly gained serious attention for its simplicity and clean design, eventually becoming one of the most widely used Python web frameworks.
The Name “Flask” Has a Meaning: Flask is named after the group of “Paladins” characters from the Monty Python sketch The Crimson Permanent Assurance. This reflects the framework’s lightweight, flexible nature and its roots in developer-friendly design.
These facts highlight how Flask evolved from a fun experiment into a powerful, production-ready framework trusted by developers worldwide.
Master Python the right way with HCL GUVI’s Python Course, where complex concepts like decorators are broken down through real-world examples and hands-on practice. Perfect for beginners and intermediate learners, it helps you write cleaner, reusable, and production-ready Python code with confidence.
Conclusion
Flask gives you a straightforward way to understand how web applications actually work, without hiding the details behind heavy configuration. You’ve seen how to install it, run your first app, and build a small REST API, all within a single session.
If your next project is small or you want tight control over your stack, Flask is a solid starting point. If it grows into something with heavy authentication or admin needs, you’ll know when it’s time to look at Django.
FAQs
What is Flask used for in Python?
Flask is used to build web applications and REST APIs. It handles routing, requests, and responses while letting you choose your own tools for everything else.
Is Flask good for beginners?
Yes. Flask has a gentle learning curve and lets you build a working app in a few lines of code, which makes core web concepts easier to grasp.
Is Flask faster than Django?
Flask is lighter and often faster for small apps since it has less overhead. For large, complex applications, the difference depends more on how the app is built than the framework itself.
Should I learn Flask or FastAPI first?
Flask is easier for absolute beginners since it doesn’t require type hints or async syntax upfront. FastAPI is worth learning once you’re comfortable with basic Python typing.
Can Flask handle large applications?
Yes, with the right extensions and structure. Companies like Netflix and Reddit use Flask in parts of their systems, though very large apps often pair it with additional tools.
Do I need to know HTML to use Flask?
Basic HTML helps if you’re rendering pages with Jinja2 templates. If you’re only building an API that returns JSON, you can skip HTML entirely.



Did you enjoy this article?