I’ve been a Python developer for quite a few years now. And, although I’ve used other languages in the past, I identify myself as a Python guy. I love it – the language, the community, the frameworks. I could go on and on, but this article is not about that, it’s about Python development. Apparently, other people think Python is a great language as well, and a very popular one.

According to some sources, Python is one of the most used programming languages around the world and in different fields. The combination of being a high-level and general-purpose programming language, being object-oriented and open source led to this ascension over the years.

The key factor that contributed to Python’s rise is that it enables programmers to create concepts of GUI applications, websites, and even mobile apps by writing less code and more readable code. Developers can further take advantage of several Python frameworks to mitigate the time and effort required for building large and complex software applications.

Just a bit of history

Guido Van Rossum created the Python programming language in the 1980s at the National Research Institute for Mathematics and Computer Science in the Netherlands, with a first release in early ‘91. Its aim was to be a successor of the ABC programming language with exception handling and an interface to Amoeba OS. The BBC television program “Monty Python’s Flying Circus” was the inspiration for the name, not a particular species of snake.

Although it was first released in the ‘90, it only took off after the 2.0 version. This one was released on the 16th of October, 2000. This version brought unicode support. It improved garbage collector for memory management, functional programming, and generators.

Python 3.0

Python 3.0 was the next major release, released on the 3rd of December 2008. This one brought changes that were not compatible with earlier versions, the Python 2.x ones, without code re-write. The guiding principle of Python 3 was: “reduce feature duplication by removing old ways of doing things”. Right now most Python developers use versions 2.7 and 3, although Python 2.7 will reach end of life state by 2020. This means that future improvements and development of the core language will stop. So, developers are asked to move their projects to Python 3.

Python is here to stay and it definitely has a piece of the future pie. It’s in active development, with an open source community and open decisions approach. It’s versatile, OOP based, and functional. It’s easy to read and write, etc. Some of the biggest companies in the world use the Python programming language, such as Google, Yahoo!, Instagram, Facebook, Quora, Red Hat, Netflix, Amazon, D-Link, Dropbox, and thousands more; It covers fields such as web programming, Machine learning, Artificial Intelligence, networking, and clusters management, and even the games industry. But that’s enough bragging.

Python Frameworks

With an involved community and private companies contributing back to the community, Python has quite a few frameworks. They are so important nowadays. Some companies seek developers with experience with a certain framework rather than the language itself or its ecosystem.

From the sea of frameworks available, I will enumerate a few based on their usage:

  • Microcontrollers
    • MicroPython
    • PyMite
    • Various Interfaces
  • GUI
    • Qt / PyQt
    • tkinter
    • kivy
    • PyGTK
    • WxPython WxPython
  •  Web Development
    • Django
    • Flask
    • web2py
    • falcon
    • tornado
  • ORM
    • Django ORM
    • SQLAlchemy
    • Peewee
    • PonyORM
    • SQLObject

A major field where Python rules is web development. This should not come as a surprise as the job market for web development has grown considerably over the past decade and it’s still growing. One of its main characteristics is cross-platform and easy deployment to devices, actually your devices (servers).

Django

One of the most used Python web frameworks is Django. As their headline says, Django is “the web framework for perfectionists with deadlines.” What is really nice and makes developers get into Django, especially for a rapid development, is their batteries included statement. That means that, for communicating with the database, there’s already an ORM, The Django ORM. There is a templating engine to serve dynamically generated HTML pages and there is a routing engine that handles the web request of a certain URL path to your designated function.

Django 1.0 was released on the 3rd of September, 2008 and, at the time of writing, the current version is 1.11.

The simplest way to understand how a Django project works is to know that there are 3 main modules needed (optionally, as you can also write all in one file) – models.py, urls.py and views.py.

  • Models.py – is used to define the data models, which later Django uses to create migrations that you can apply to the DB to obtain a 1:1 correlation between the code and the DB structure.
  • Urls.py – uses pattern matching defined by the developer to match URL paths to views. Special functions return some data to the web requester.
  • Views.py – where the real processing happens. Here is the logic and base code to serve the actual data back to the requester.

Being a full featured web framework, it may not be well suited for, let’s say, a ping-pong server or as a health check service, which only returns a 200 OK response. For this kind of work, some lightweight frameworks are more suited, such as Flask or Falcon. As you can see, we can spin up a “Hello World” in 5 lines of code in Flask or a Falcon app in just a few lines.

Flask

The Flask framework is a goto for many developers who have smaller projects, or developers who have more domain specific problems that don’t require the full throttle of a web framework. Flask is more versatile and agnostic to the database connection (the chosen ORM library).

For example, it’s usable and versatile for a SmartHome application that is hosted in the client’s house on a PC big as a thumb. This web app would have authentication for the owner and different smart appliances would report to the server, where the user can log in and see a live status from anywhere.

Tornado

Being in the sphere of networking programming, Tornado is a Python package that offers a web framework and an asynchronous networking library for developers. Being an established library when it comes to developing networking application, currently version 4.5, Tornado is a reference in such projects.

The library can handle long-lived connections per user and scale to tens of thousands of open connections, which makes it ideal for long polling WebSockets. With the features that this library offers, it makes a perfect choice for situations when a project is built upon the Client-Server paradigm.

pytest

If quality assurance is a concern, and it should be, pytest is a great testing framework to use. It’s pretty popular in the community and has great feedback. The pytest framework makes it easy to write small tests, yet it scales to support complex functional testing for applications and libraries. Among the features that it brings to the table I’ll just name a few: detailed info on failing assert statements, auto-discovery of tests, modular fixtures, rich architecture, with modular plugins for specific use cases. Being a reference library, its code runs on Python 2.6+ and 3.3+.

Let’s say that a library or a framework needs testing, to ensure that it executes the same on different versions of a programming language. Usually, a version is system-wide, but that being said, you can’t have active multiple versions. So, in order to test the project under different versions, we need to manage the operating system’s programming language version manually, run the test and hope everything is ok. But what if we have system’s applications that rely on a specific version of a language?

tox

Fear not, as for Python projects, there is a beloved open-source project called tox, which handles exactly this situation and can run the tests suite under different versions of Python. Tox aims to automate and standardize testing in Python.

Being written with customization in mind, tox can be used to automatize different things besides running test suites, such as running linters to analyze the code, or to package it and upload it to a repository, available later for deploying.

As a Python Software developer/engineer, I was impressed by the community and the people involved in Python projects. The language itself is versatile and can bring your project to light in a minimal timeframe – these are just a few of the things that recommend Python as one of the first choices when you’re starting a project that is mainly web-based.

I hope this brief presentation to the Python programming language ecosystem was enlightening and interesting and I encourage you to take a look at the features and toolset that this language offers for your next project.

 

by Bogdan Barna