So you want to learn to build websites with Python? Make sense! Python provides an unparalleled ease of use and readability so why not build websites with it? Luckily, you’ve come to the right place. I’m going to run you through all of the best frameworks available to new python developers right now so you can decide what’s best for you. Let’s get going!
Django is the most popular framework out there and for good reason. It’s blazingly fast, simple to use and has extensive, well-maintained documentation. Django is a full stack Python framework which meaning that it encompasses everything which might be needed when building complex web applications rather than you having to find libraries which work for you and work together well.
Django is an MVC framework (more or less, more on that here) meaning that the codebase is easy to keep structured and also uses an ORM to talk to the database so there’s (usually) no need to write ugly SQL if you don’t want to. Another side-effect of the ORM is that the queries read almost like English which is a huge plus for legibility.
If you’re after a general-purpose, battle-tested framework then you can’t go wrong with Django. It’s actively maintained with the most recent release being Django 4, and perfect for large applications as well as MVPs and proof of concepts.
Flask is a micro framework. “What does that mean?”, I hear you ask! Essentially, it’s designed to be the smallest possible framework piece which can be built upon and extended with libraries. Flask is not opinionated when it comes to how you build your app. You can use any database driver, form validation library, or templating library that your heart desires all through installing them as extensions to the base flask framework.
Whereas Django provides a scaffolding on which to build your application and has standards in how applications should be structured, flask allows you complete creative control over your architecture meaning that you can use any or no structure you want. Want to use MVC? Go for it! It just might be a bit more work than with Django.
Flask provides powerful tools for building web apps however you desire and will never tell you you’re doing it wrong. This is fantastic for when you know what you’re doing and know how you like your apps but I can definitely see potential for things either getting messy if you’re not careful or the freedom of choice being so intimidating that you never really settle on an architecture.
Masonite is to Python what Laravel is to PHP. Masonite is built using Laravel’s architecture and concepts as a base but with a little bit of ✨Python spice✨. If you’re coming from the world of PHP and Laravel like I did then you’ll find this framework a breeze to pick up. It boasts many of the same features as Django in that it’s MVC, provides and ORM and provides a project structure from the outset. However, they differ in that features which make Laravel such a pleasure to work with come baked into Masonite from the get go. These include the Service container for dependency injection, cron scheduling, and queue handling, which would all need to be pulled in as external libraries in Django. Also, in contrast to Flask it’s very opinionated and removes some of the decision fatigue it can take when setting up a new project from scratch and allows you to focus on the code.
Despite not being as established as Django in the Python world ( Django’s been around for almost 20 years now ) Masonite’s developers are active and constantly shipping new code to this passion project. The framework also has an active community who love to work with this sightly more obscure Python framework. As well as extensive documentation there is also the option to learn through video tutorials in the form of MasoniteCasts.
Bottle feels a lot like flask in its simplistic barebones approach. According to the website “It is distributed as a single file module and has no dependencies other than the Python Standard Library ” which makes it a great option if bloat is a concern of yours or you want to make your site as slimline as possible.
Despite my comparison to Flask, it does come with more functionality built in as well as an official library of ‘plugins’ which can be used to expand the framework if you want to.
So there you have it! Python web frameworks, in all their glory. You can build anything with them and PyHost is here to make your life after building easier than ever. We’ll be adding support for more frameworks in future so stay tuned. What’s your favourite framework? Let me know in the comments below! Please feel free to share this post with anyone you feel may benefit from it!