Building Your Own Python Web Framework

  • Updated March 2nd, 2021
  • v2.0.0
Jahongir Rahmonov Jahongir Rahmonov

Learn how to build your own Python web framework!


"Don't reinvent the wheel" is a common programming mantra we hear nearly every day. But what if you want to learn more about the wheel? What if you want to learn how to make the damn wheel itself so you can make the next iteration better, faster, or stronger? It's often a great idea to reinvent the wheel, especially when it comes to learning -- which is exactly what this course is all about!

In this course, you'll learn how to develop your own Python web framework to see how things work beneath the surface of Flask, Django, and the other Python-based web frameworks. You'll also learn how to build your own Object Relational Mapper (ORM), much like the Django ORM and SQLAlchemy.

Most importantly, you, as a developer, will be building something for other developers, which might be a little different from what you do at your day job and thus you'll learn a lot.

What will you learn?

Select a Part

In part 1, you'll learn how to write your own web framework using Python, just like Django and Flask. After the main functionality is in place, you'll create a test client and, from that point on, you'll follow basic Test-driven Development (TDD). Once the framework is complete, you'll package it up and upload it to PyPI (the Python Package Index). You'll then develop a small web application with the framework you just built and deploy it to Heroku.

Learning Objectives

  1. Explain what WSGI is and why it's needed
  2. Build a basic web framework and run it with Gunicorn, a WSGI-compatible server
  3. Develop the core request handlers, routes, and templates
  4. Implement class-based route handlers
  5. Test your framework with unit tests and practice test-driven development
  6. Build a test client to test the API without having to spin up the server
  7. Implement custom exception handlers to ensure 404 (Not Found) and 500 (Internal Server Error) errors are handled gracefully
  8. Develop solutions for managing static files and middleware in the framework
  9. Control allowed methods for your request handlers
  10. Create a custom response class to make response creation easy
  11. Create a Python package and upload it to PyPI
  12. Develop a web application using the framework you built and deploy it to Heroku

In part 2, you'll build an Object Relational Mapper (ORM) just like the Django ORM and SQLAlchemy. You'll then upload a new version of your framework to PyPy, rewrite the web application you built in the previous part to use your new ORM, and finally upload the new version to Heroku.

Learning Objectives

  1. Build your own Object Relational Mapper (ORM)
  2. Rewrite your web application using the ORM
  3. Upload a new version of your project to PyPy
  4. Update your production code on Heroku

What do you need to know?

This course is targeted at advanced-beginners -- someone with at least 6 months of web development experience. Before beginning, along with having strong working knowledge of Python 3, you should have some familiarity with the following topics:

Internet and Web Fundamentals

You should have a solid understanding of the following Internet and web fundamentals:

  1. IP addresses, URL structures, and DNS
  2. Web browsers and web servers
  3. HTTP requests and responses

Review the following videos for more info:

  1. The Kids Guide to the Internet
  2. What is the Internet?
  3. The Internet: IP Addresses & DNS
  4. The Internet: HTTP & HTML

Web Framework

It helps to have a bit of experience working with a web framework like Flask, Django, Rails, and/or Express, just to name a few.

Meet the Author

Jahongir Rahmonov

Jahongir Rahmonov

Jahongir is a software developer, avid reader, blogger, and speaker. He likes to write Python, Django, Angular, and sometimes something non-technical.

What developers are saying

The TestDriven.io courses are some of the best courses I've ever done for any language, any platform, any price range... just some of the most thorough and well-sourced courses around.

Just a word of thanks for doing such a great job with these training courses. The thorough, entire-lifecycle approach -- from implementation through test, coverage, quality, CI/CD, and all the rest -- is what separates these courses from other training material that I've completed. I'll be able to walk away from here with knowledge and skills that I can apply immediately at work -- and for that I'm grateful. It's a rare gift in an environment where so much 'training' is really just lightweight treatment that doesn't begin to scratch the surface of real, end-to-end software development. Really well done!

The TestDriven.io courses are worth 10 times what I paid for them.

I'm writing to thank you for all the tutorials and the work you've put out there. I'm new to DevOps and I found TestDriven.io while looking for Django and DevOps related topics. One of the best collections of tutorials and guides I've seen -- very well-written, clear, and concise. You have saved me so much time and energy. Thanks from the bottom of my heart.

I am very much into buying and purchasing any course by you and your team. I've never felt like a better programmer ready to show my coding chops to the world.

Frequently Asked Questions

What tools and technologies are used in this course?

This course covers a variety of tools and technologies:

  1. Python
  2. WSGI
  3. Gunicorn
  4. pytest
  5. SQLite
  6. PyPI
  7. Heroku

What support does TestDriven.io offer?

Since the courses mimic real-world development, support is provided via Stack Overflow. Helpful users, including the developers of the courses, read and respond to messages on Stack Overflow. If you get stuck and you can't find an answer via Stack Overflow, feel free to reach out via email directly. Just be sure to detail what you've tried. For more, review Support and Consulting.

How long does it take to complete the course?

It's dependent on your current skill level. On average, it takes approximately 8 hours to complete.