Python web development: profitable for business, convenient for developers. KT.team experience

24.4.2020
Python web development: profitable for business, convenient for developers. KT.team experience

Content

Python's capabilities are extensive: from web development to the development of machine learning, facial recognition and text recognition systems. Let's talk about Python for business and look at kt.team cases.

1. Business benefits of Python development

2. The disadvantages of Python

3. Business problems solved by Python development

4. Case study: developing an international hackathon platform in Python

5. Where else Python is used

5 минут

In this article, you will learn more about our experience with Python: what products we write in this programming language, why we choose it for these tasks, and how development customers benefit from it.

The following will help us to understand this issue:

  • Egor, Senior Software Engineer;
  • Anton, team leader, company partner;
  • Anton, project manager, executive director, company partner.

Business benefits of Python development

Accelerated MVP development

With the development of flexible approaches and philosophy Agile development cycles are getting shorter. Software engineers don't need to write projects “on the table” for years, checking a thousand page terms of reference. Development begins with the creation of an MVP. The priority is to launch a minimum viable version of the product in one to two months and get feedback from real users (you can read more about MVP development in our blog article:”MVP, or how not to get into endless development”).

Python is great for rapid MVP development. The secret to speed lies in a syntax that is as close as possible to natural English.

A large number of free libraries and frameworks, as well as minimalist microframeworks like Flask, affect speed. They are designed for different needs, have a large and friendly community, and attract with their simplicity and flexibility in their syntactic structures.

The caveat: this high speed is maintained when the project complexity is relatively low (small and medium E-commerce, CRM, simple integrations).

If development is carried out for enterprise projects, then all work takes approximately the same time, regardless of the technology stack used. Writing in Java, PHP or Python doesn't matter, as the total number of hours won't vary significantly.

At the same time, time can be allocated differently to different types of work. With some stack, it will take more time to refactor, another stack will take more time for MVP, with a third stack it will take more time to test, etc. For example, to work quickly in Python, you must first consider the architecture and properly prepare the environment. Moreover, you can't judge the complexity of the job by the number of lines of code and the speed of writing it. The minimum amount of code means its high quality, and in order for a developer to be able to put the task into three lines, he must carefully consider how to do it, what part of the program to place the code in, etc.

Easy integration with other technologies and software

Today, any development product requires a large number of integrations: with various information systems of the company itself and its counterparties, with banking and marketing IS, and many others.

Python is convenient for integrations and can manage various software components, including those developed in another language. It is universal for all platforms.

This was one of the reasons why we chose Python to create a print service API on one of our current projects. It interacts perfectly with the Linux CUPS print server — from Python it is easy to access the OS kernel to perform the necessary operations.

Scalability and ability to add new features

This advantage does not come by itself; it requires a well-thought-out project architecture and clean code. It can be said that Python, with its simple and clear syntactic structures, is easier to write easily scalable code than in most other languages.

This was important for us when we were choosing a stack for managing print services. With Python, we didn't have to make changes to the main print service module when changing parts of it.

The disadvantages of Python

Most of Python's features are visible only on the developer side and create difficulties for them, not for customers and users of the product.

Code execution speed

Perhaps the most sensitive topic for pythonists is the speed of code execution. Python is considered to be a rather slow programming language: this is due to the peculiarities of the language's interpreter structure and its dynamic nature. To improve performance, developers either rewrite an “inhibitory” piece of code in C or Cython (the translator of Python code to C), or use PyPy, an alternative interpreter of the Python programming language (its name stands for Python, written in Python).

Developers often say that you can write anything in Python, even Python itself.

Basically, this is normal in today's practice: the Rust compiler is also written in Rust, and the Golang compiler in Golang.

PyPy updates are slightly behind updates to the main version of the Python interpreter. For example, the current version of Python is 3.8, and PyPy is closer to version 3.5 with some features from 3.6.

The following acceleration principles can be identified when developing in Python:

  • Python has a lot of libraries; you need to choose the one that is suitable and proven in solving similar problems, because sometimes they are already written in C and have high performance in solving their tasks;
  • to speed up a small problematic part of the code, you can rewrite it to Cython (this is a translator, an “intermediate layer” for Python in C/C++);
  • To speed up large parts of Python code, using PyPy helps if the code is not sensitive to the language version (Enterprise Django projects often start on PyPy).

PyPy has a cool JIT compilation technology (just-in-time) compilation).

The functions that are in the program will be compiled into machine code on the fly, speeding up the program and then using it. At the same time, you don't need to rewrite the code, you just need to keep in mind the downgrade.

Single-line anonymous functions and pipelines

In Python, anonymous functions (lambda functions, unnamed functions) are single-line functions. Developers sometimes don't have enough multi-line lambdas, but they will never appear, as this would be contrary to Python's ideology.

Pipelines are the sequential execution of functions with the subsequent transfer of data from the previous one.

In Python, you have to write a sequence something like this.

a = func1 ()

a = func2 (a)

a = func3 (a)

result = func4 (a)


In some other programming language (say Elixir) this would look easier.

result = func1 () |>

func2 () |>

func3 () |>

func4 ()


This does not affect code performance, but it causes some inconvenience to developers, making it difficult to comply with the functional programming methodology.

Business problems solved by Python development

Typical development tasks that are successfully solved in Python:

  • corporate website (catalog, online store);
  • systems for corporate training and hackathons;
  • image recognition systems (photos, images, faces);
  • document recognition systems (OCR, machine vision);
  • managing printing services with complex routes;
  • asynchronous modules for existing systems (transport modules, payment gateways).

Today, one of the trends in Python development is its use for writing microservices. The microservices in which Python is most often used in development are:

  • for machine learning (yes, both R and Scala have such capabilities, but Python is considered the common standard for a large community in this regard);
  • for processing request & response objects, Python 3.6 and higher does an excellent job with such tasks, since these versions successfully implement asynchronous input/output operations.

When updating online stores based on CMS systems developed quite a long time ago (as, for example, Magento, more than 12 years ago), a mixed approach is also used. For some services, it's easier to leave Magento, while for others it's easier to move to Saleor (a CMS written in Python). The issue of migrating from Magento to Saleor often arises for small Internet projects that want a quick upgrade.

Let's take a look at our recent Python development case. Creating a platform for online training or for a hackathon is a typical task that Python is great for.

Case study: developing an international hackathon platform in Python

Our task was to develop a platform for a major international hackathon on machine learning (more than 10,000 participants, a highload product).

The logic should have taken into account the following conditions for participants:

  • everyone is given the same task, the deadline for which is limited;
  • everyone must register online;
  • you can create your own team, join someone else's or participate alone;
  • the verification of the correctness of answers should be automatic.

Through this platform, members submit their responses. The system validates each participant's answers, compares them with the ideal solution, while verifying that a large number of conditions are met. Each decision is assessed, on the basis of which a list of leaders is formed. At the end of the hackathon, the system automatically determines the winners.

To solve this problem, we used SPA (abbreviated from English. single page application — a single-page app.) (Vue.js + Nuxt.js) + Django (this is a Python framework). SPA communicates with the backend via the API.


Why choose Python?

We like this solution for its flexibility: unlike a cumbersome architecture with tens of thousands of lines of code, here you can flexibly manage all entities without worrying about code overlap.

All entities can be created and described very quickly and instantly accessed through the API.

As a result, we were able to develop a platform ready for high loads with the necessary functionality for the hackathon. The system supports a specific set of rules. There is an admin panel with displaying results, uploading statistics and other data.

Where else Python is used

You could say that Python is “all the rage” right now (though fans of Go or Dart might argue), and many developers are happy to write in it.

Let's talk about an interesting example of how our colleagues from the frontend tried to write in Python.

We recently received a customer whose backend is written in PHP. The goal was to convert it to Django. To connect back and front, front-end developers learned Python syntax in two days, Django documentation in day three, fell in love with Python on day four and now don't want to go back to frontend. They really regret that Python is only suitable for backend development.

Not only developers, but also representatives of related professions use Python for their tasks.

System administrators can automate processes using Python along with Bash. For example, in complex designs, if you need to create scripts on servers that will poll parts of the system, check whether everything is in order (conduct a health check).

Business analysts often come to Python by studying the data analysis stack (pandas, Matplotlib, Jupyter). This is a specific solution for complex aggregations that allows you to create advanced dashboards, calculate and visualize many important indicators.

findings

Python is ideal for projects in the field of CV & ML (computer vision and machine learning, Russian computer vision and machine learning), analytics, development of corporate websites and corporate training systems.

It is good for creating small microservices and projects with a short life cycle, when customers need to quickly launch an MVP and test hypotheses.

Yes, there are many uses of this universal language, but there are also cases where it is better to use a different stack. For example, Magento (PHP) may be preferable to developing high-load online stores.

You need to choose whether to use Python on your project or not after a joint discussion between developers and customers, based on an analysis of product features and business tasks.

Table of contents
Другие статьи

Смотреть все

Why do we need an analytical culture?

17/6/2020

Подробнее

How a B2B portal relieves marketing and management headaches: 9 examples

27/9/2019

Подробнее

How the PIM system helps develop sales to pharmaceutical companies

2/10/2023

Подробнее

Смотреть все

We use cookies to provide the best site experience

Ok