MSBLOGS: April 2017

Pages

Friday, April 21, 2017

Overview of Python Web development framework

I have evaluated few frameworks for python and based on that I am trying to compare the three popular web-development frameworks; Django, Pyramid and Flask"

With python we can do a lot with just a few lines of Python code. However, if we are thinking of building a complex full-fetched web application in Python from scratch, we might be doing it wrong.
There are already some great Python frameworks present in the modern-day that we can use for web development. They are fast, refined and backed by thousands of developers.
Here, we are explaining why Python frameworks are a great choice for web development — where to start with them and how. Also, we are introducing to Python libraries and helper tools that will help we throughout the web development process.

Framework?

A web framework is nothing but a collection of packages and modules that allows easier development of websites. It handles all low-level communication within the system and hides it from we to make no issues for performing common tasks for the development.
The line where it draws the line between which to hide and which to not, depends on the individual framework itself (more on this later).

Choosing Python web framework?

we can always create a web application from scratch, but there are various reasons we would not want to. Below are the top five reasons why we should choose Python framework over our own.

Used and trusted by many large companies

Popular Python frameworks like Pyramid and Django are used by companies like Bitbucket, Pinterest, Instagram and Dropbox in their web application development. So, it is safe to say these frameworks are able to handle almost everything we throw at them.

Hides complicated low-level details

As stated above, web frameworks are meant to hide and handle all low-level details so that we as a developer, do not have to dig deep into how everything works when we are developing a web-enabled application.

Saves our valuable time

The frameworks have been built investing thousands of developer and testing hours. Building on top of it saves our valuable time. Especially, when we are developing a simple prototype of a website or are closer to a deadline, using web frameworks can turn out to be a life safer.

Security

One of the most important advantages of using a web framework as opposed to building something on our own is handling the security of our website. Since web frameworks have been used and backed by thousands, it inherently handles security, preventing any misuse of the web application.

Efficient and scalable system

Good frameworks are built ensuring scalability from the very beginning of the development process. So, whenever we are planning to scale our website by adding a new component or using a new database, web frameworks are more likely to scale better than what we come up with when building from scratch.
Fun fact: Disqus, a popular blog comment hosting service, has more than eight billion page views and 45K request per second through Python framework Django.

Which framework to choose?

There are tons of Python web frameworks, and every framework has their own strengths and weaknesses. Thus, it is necessary to evaluate our project requirements and pick one the best one from the collection.

Below are the three most popular web frameworks in Python.

Django

Django is the most popular Python web framework and is aimed mostly at larger applications.  It takes a “batteries-included” approach and contains everything needed for web development bundled with the framework itself. So, we do not have to handle things like database administration, templating, routing, authentication and so on. With fairly less code, we can create great applications with Django.
If we are building a mid-high ranged web applicants and are quite comfortable with Python, we should go for Django.

Pyramid

The Pyramid is the most flexible Python web framework and just like Django, it is aimed at mid-high scale applications.
If we think Django brings too much bloat to our web application, use Pyramid. It does not force we to use a single solution for a task, but rather gives we a pluggable system to plug-in according to our project requirements.
we do have the basic web development capabilities like routing and authentication, but that is about it. So, if we want to connect to a database for storage, we ought to do that werself using external libraries.

Flask

Flask is the newest among the others. Unlike Pyramid and Django, Flask is a micro-framework and is best suited for small-scale applications.
Even if it is new, Flask has integrated great features of other frameworks. It includes features like unit testing and built-in development server that enable us to create reliable and efficient web applications.

For a learner pyramid or flask will be best as it start with simple projects and as you progress you can keep intrgrating different plug in like chemeleon, jinga mako etc. The django framework involves everything even if you want to make two page project. But for larger application its the best. Flask is also suitable for small projects and its still growing..

Things to know when we start with Python frameworks

Learn Python and HTML
Before we start with the frameworks, it is the best to learn Python from the ground up. When we are comfortable with the language and its power, we will have a strong understanding of the fundamentals required for our project.
Equally important knowledge to have is the knowledge of HTML and JS. Modern web development is just not possible without them.

Follow getting started guide carefully and grasp their basic architectural knowledge

Since frameworks like Django are based on MVC and Flask uses Jinja2 templating engine, it is always better to how these architectures actually work.

Create simple applications

When starting out, do not rush into creating full-fledged heavy web applications. Start with something simple like a todo list.
This teaches we how CRUD functionalities and basic HTTP requests are handled by the framework. Also, we will have a good grasp on how to get started with the framework itself.
This advice is equally applicable to advanced programmers.

Learn to debug

Exceptions and bugs are programmer’s best friends. Learn to configure and use the debugging capabilities of the frameworks. Understanding the exceptions and how a code behaves in certain cases will take we a long way.
Use IDE’s like PyCharm that makes our life a lot easier with its smart intellisense, debugging capabilities and code optimisation tips.

Integrate third-party modules

The whole point of using a web framework is not to repeat what others have already achieved better, and focusing on the output instead.
Most of the utilities we need for database connection (SQLAlchemy), scientific computations (SciPy) and web scraping (BeautifulSoup) are already implemented and used by many, do not waste time recreating the wheel. web framework powers itself with the use of external libraries. With them, our development project can catch serious speed.
However, before we go for external integration, it is better to familiarise werself with Python’s core modules first. Python’s utility functions and object methods support an array of features.
Manipulations like string encoding, filtering and mapping can be achieved through Python’s internal tools itself.
Python with its powerful web framework catalogue is a great choice for web development and will bring we up to speed with today’s modern needs.
Whichever framework we choose, there is no doubt that there is a great advantage in using a web framework than building a web application from scratch. we can also consider that investing our time in learning and using Python web framework, in turn, can save our time, money and production effort.