Python Web Development: Cost-Effective for Business, Convenient for Developers. KT.Team Experience

How Python helps speed up development, automate processes, work with data, and launch modern web applications.

  • Benefits of Python development for business
  • Accelerated MVP development
  • Easy integration with other technologies and software
  • Scalability and the ability to add new features

In this article, you will learn more about our experience with Python: what products we build in this programming language, why we choose it for these tasks, and what benefits our development clients get from it. We will be helped by: - Egor, Senior Software Engineer; - Anton, Team Lead, Partner; - Anton, Project Manager, Executive Director, Partner.

Benefits of Python development for business

Accelerated MVP development. With the growth of agile approaches and the philosophy Agile development cycles are getting shorter and shorter. Software engineers do not need to spend years building projects in isolation while referring to a thousand-page specification. Development begins with creating an MVP.

The priority is to launch a minimum viable product within one or two months and get feedback from real users (you can read more about MVP development in our blog article: "MVP, or how to avoid endless developmentFor fast MVP development, Python is an excellent choice. Its speed comes from a syntax that is as close as possible to natural English.

Speed is influenced by the large number of open-source libraries and frameworks, as well as minimalist microframeworks such as Flask. They are designed for different needs, have a large and friendly community, and attract developers with the simplicity and flexibility of their syntax. One caveat: this high speed is maintained only when the project is relatively simple (small and medium e-commerce, CRM, and straightforward integrations).

If development is for enterprise projects, then all work takes roughly the same amount of time regardless of the technology stack. It does not matter whether you write in Java, PHP, or Python, because the total number of hours will not differ significantly. At the same time, the time can be distributed differently across types of work. One stack may require more time for refactoring, another for the MVP, and a third for testing, and so on.

For example, to work quickly in Python, you need to think through the architecture in advance and prepare the environment properly. Also, you cannot judge the complexity of the work by the number of lines of code or how fast it is written. A minimal amount of code means high quality, and for a developer to fit a task into three lines, they must carefully think through how to do it, where in the program to place the code, and so on.

Discuss your challenge with an architect

Easy integration with other technologies and software. Today, any software product requires many integrations: with various information systems used by the company and its partners, with banking and marketing systems, and many others. Python is well suited for integrations and can control different software components, including those written in another language. It is versatile across all platforms.

This was one of the reasons why we chose Python specifically to build the print service API in one of our current projects. It works very well with the Linux CUPS print server, and from Python it is easy to access the OS kernel to perform the required operations. Scalability and the ability to add new features. This advantage does not happen on its own; it requires a well-thought-out project architecture and clean code.

It can be said that with Python and its simple, clear syntax constructs, it is easier to write code that scales well than in most other languages. This was important to us when we chose a stack for managing print services. With Python, we did not have to change the main print service module when its parts changed.

Disadvantages of Python

Most Python-specific features are visible only to developers and create difficulties for them, not for clients or product users. Code execution speed is probably the most painful topic for Python developers. Python is considered a fairly slow programming language, which is due to the structure of its interpreter and its dynamic nature.

To improve performance, developers either rewrite the slow part of the code in C or Cython, a Python-to-C translator, or use PyPy, an alternative Python interpreter whose name stands for Python written in Python. Developers often say that you can write anything in Python, even Python itself. In principle, this is normal in today's practice: the Rust compiler is also written in Rust, and the Golang compiler in Golang.

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

The following principles can be used to speed up Python development: - Python has many libraries, so you need to choose one that is suitable and proven for solving similar tasks, since some of them are already written in C and perform very well; - to speed up a small problematic part of the code, you can rewrite it in Cython, a translator and intermediary layer for Python in

C/C++); - to speed up large parts of code written in Python, PyPy can help if the code is not sensitive to the language version (enterprise-level Django projects often start on PyPy).

PyPy is powerful because of JIT compilation (just-in-time compilation). Functions in the program are compiled into machine code on the fly, speeding up the program for future use. You do not need to rewrite the code, you just need to keep the version downgrade in mind. One-line anonymous functions and pipelines. In Python, anonymous functions, or lambda functions, are single-line.

Developers sometimes miss multiline lambdas, but they will never appear because that would go against Python's philosophy. Pipelines are the sequential execution of functions with subsequent transfer of data from the previous step. In Python, the sequence has to be written roughly like this. _a = func1() a = func2(a) a = func3(a) result = func4(a)___ In some other programming language, say Elixir, this would look simpler.

_result = func1()>
func2()>
func3()>

func4()___ This does not affect code performance, but it causes some inconvenience for developers by making it harder to follow functional programming methodology.

Business tasks solved by Python development

Typical development tasks that are successfully solved with Python: - corporate website (catalog, online store); - systems for corporate training and hackathon management; - image recognition systems (photos, images, faces); - document recognition systems (OCR, machine vision); - management of print services with complex routing; - asynchronous modules for existing systems (transport modules, payment gateways).

One of the current trends in Python development is using it to build microservices.

Microservices where Python is most often used: - for machine learning (yes, R and Scala also have such capabilities, but Python is widely regarded by the large community as the standard for this area); - for handling request and response objects - Python 3.6 and later handles such tasks very well, since these versions successfully implement asynchronous input/output operations.

A mixed approach is also used when updating online stores built on CMS platforms that were developed a long time ago, such as Magento, more than 12 years ago.

For some services, it is easier to keep Magento, while for others it makes sense to move to Saleor, a CMS built in Python.

The question of migrating from Magento to Saleor comes up quite often for small online projects that want a quick modernization.

Let’s look at one of our recent Python development cases.

Building a platform for online learning or a hackathon is a typical task that Python is very well suited for.

Case study: building an international hackathon platform with Python

Our task was to develop a platform for a large international machine learning hackathon (more than 10,000 participants, a high-load product). The logic had to account for the following conditions for participants: - everyone receives the same task, with a limited completion time; - everyone must register online; - participants can create their own team, join another team, or compete individually; - answer validation must be automatic. Participants submit their answers through this platform.

The system validates each participant's answers, compares them with the ideal solution, and checks compliance with a large number of conditions.

Each solution is scored, and the leaderboard is then generated from those scores.

At the end of the hackathon, the system automatically determines the winners.

To solve this task, we used an SPA (short

from the English single page application, meaning a single-page application.) (Vue.js + Nuxt.js) + Django (a Python framework). The SPA communicates with the backend via the API.

Why Python?

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

  2. All entities can be created and described very quickly, and data can be accessed instantly through the API. As a result, we were able to develop a load-ready platform with the functionality needed to run a hackathon.

  3. The system follows a defined set of rules.

  4. There is an admin panel with result display, statistics export, and other data.

Where else is Python used

  1. You could say that Python is currently in fashion, although fans of Go or Dart might disagree, and many developers enjoy writing in it.

  2. We will share an interesting example of how our frontend colleagues tried writing in Python.

  3. Recently, a client came to us whose project's backend is written in PHP.

  4. The task was to rebuild it on Django.

  5. To connect the back end and front end, frontend developers learned Python syntax in two days, Django documentation on the third day, and by the fourth day they had fallen in love with Python and now do not want to return to frontend work.

  6. They really regret that Python is suitable only for backend development.

  7. Not only developers, but also professionals from related fields use Python for their tasks.

  8. System administrators can automate processes using Python together with Bash. For example, in complex setups, if they need scripts on servers that will query parts of the system and check whether everything is fine by performing a health check. Business analysts often move to Python after learning the data analysis stack (pandas, Matplotlib, Jupyter).

  9. This is a specialized solution for complex aggregations that makes it possible to build advanced dashboards and calculate and visualize many important metrics.

Conclusions

Python is ideal for projects in CV & ML (computer vision and machine learning), analytics, corporate websites, and corporate training systems. It is well suited for building small microservices and short-lived projects when a client needs to launch an MVP quickly and test hypotheses. Yes, this versatile language has many use cases, but there are also cases where another stack is a better choice.

For example, Magento (PHP) may be preferable for developing high-load online stores. Whether Python should be used in your project should be decided after a joint discussion between developers and clients, based on an analysis of the product characteristics and business goals.

Discuss your challenge with an architect

Discuss the article: Web development with Python: profitable...

Send via: