Sprint 1: Deciding on a Python framework - SD-Group-11/ml-frontend GitHub Wiki

Client’s request: “A Python back-end, with a beautiful front-end”

Upon the client request to use Python for the back-end, research had to be done in order to make an informed decision on:

  • If Python alone can be used to create a good-looking front-end GUI.
  • Alternative framework approaches if it cannot.
  • The best platform and framework for the app (e.g desktop app vs. web app).

We will investigate three options for the type of Python framework that will be used to develop this project. These are GUI frameworks for desktop applications, hybrid frameworks for desktop applications with web technologies, and lastly, web frameworks for web-based applications.

Python desktop GUI frameworks: PyQt vs Tkinter

There are an abundance of Python frameworks for creating Graphical User Interfaces for desktop applications, a number of which are cross-platform frameworks. The most popular ones being Kivy, PyQT, Tkinter, WxPython, PyGUI, and PySide. The two that we will consider for the to-be-developed application are PyQt and Tkinter.

PyQt

PyQT is one of the favoured cross-platform Python bindings implementing the Qt library for the Qt application development framework. Currently, PyQT is available for Unix/Linux, Windows, Mac OS X and Sharp Zaurus. It combines the best of Python and Qt and it up to the programmer to decide whether to create a program by coding or using Qt Designer to create visual dialogs. It is available in both, commercial as well as GPL license. Although some features may not be available in the free version, if your application is open source, then you can use it under the free license.

Advantages:

  • Coding flexibility – GUI programming with Qt is designed around the concept of signals and slots for establishing communication amongst objects. That permits flexibility when dealing with GUI events and results in a smoother codebase.
  • More than a framework – Qt uses a wide array of native platform APIs for the purpose of networking, database creation, and many more. It offers primary access to them via a unique API.
  • Various UI components – Qt offers several widgets, such as buttons or menus, all designed with a basic appearance across all supported platforms.
  • Various learning resources – because PyQt is one of the most used UI frameworks for Python, you can get easy access to a wide array of documentation.
  • Easy to learn.

Disadvantages:

  • Doesn’t create nearly as beautiful production front-ends compared to other languages
  • Lack of Python-specific documentation for classes in PyQt5
  • It requires a lot of time for understanding all the details of PyQt, meaning it is a quite steep learning curve

Tkinter

Tkinter is commonly bundled with Python, using Tk and is Python’s standard GUI framework. It is popular for its simplicity and graphical user interface. It is open source and available under the Python License. It has an abundance of resources, both codes and reference books, and since the community is mature and remains active, there are many users who can help.

Advantages:

  • Available out-of-charge for commercial usage.
  • It is featured in the underlying Python library.
  • Creating executables for Tkinter apps is more accessible since Tkinter is included in Python, and, as a consequence, it comes with no other dependencies.
  • Simple to understand and master, as Tkinter is a limited library with a simple API, being the primary choice for creating fast GUIs for Python scripts.

Disadvantages:

  • Doesn’t create nearly as beautiful production front-ends compared to other languages
  • Tkinter does not include advanced widgets.
  • It has no similar tool as Qt Designer for Tkinter.
  • It doesn't have a native look and feel

PyQT or Tkinter?

Choice: Neither

The main reason for seriously considering using these Python frameworks is in order to reduce unnecessary complexity, using any of these Python frameworks would allow us to code in one language, thus saving time in having to learn multiple languages as well as reducing complexity since we would not have to integrate Python with another language. However, due to the client’s request for a good-looking front-end, using Python GUI frameworks is not a suitable choice.

Thus we move to an alternative which can provide better looking GUI front-ends, while still remaining on a desktop platform.

Python desktop frameworks with web technologies: Eel vs. Electron

These frameworks are used to build desktop applications that are integrated with web technologies like HTML, CSS, and Javascript in order to give their GUIs the aesthetic appeal seen in many web applications. The two that we will consider for the to-be-developed application are Eel and Electron.

Eel

Eel is a little Python library for making simple Electron-like offline HTML/JS GUI apps, with full access to Python capabilities and libraries. Eel allows you to create a desktop application which gets rendered in a browser, allowing you to connect Python as your back-end to a beautiful front-end created with HTML/CSS and JS with full capabilities of both. Eel has the advantage of being light-weight but comes with the cost of not being as capable as Electron for larger applications.

Electron

If you can build a website, you can build a desktop app. Electron is a framework for creating native applications with web technologies like JavaScript, HTML, and CSS. It takes care of the hard parts so you can focus on the core of your application.

Electron is used in popular applications such as Visual Studio Code and Discord and more.

Electron has the advantage of not needing a browser to be installed on the device in order to run.

Eel or Electron?

Choice: Neither

While Electron is the obvious choice if we were to create a desktop application because of its better documentation, support, and greater capability when compared to eel, it still falls more than a little short of web applications when it comes to making an application good looking enough to be considered “beautiful”.

Thus we move our discussion to the web platform, which along with being able to produce stunning frontend GUIs, has a host of other benefits when it comes to integrating web services into our application.

Python web frameworks: Django vs. Flask

What is a Python web framework?

A Python web framework is a package of generic and commonly used Python web development functionalities and patterns that makes it faster, and easier, for developers to build Python-based web applications or services that are reliable, and can be easily scaled and maintained. The framework provides a developer with a layer of abstraction away from low-level web-dev details making it easier to add complex functionality that would be difficult or time-consuming to implement from scratch. Frameworks that focus on the app’s user interface are referred to as being “front-end”, while those that deal with everything happening behind-the-scenes are referred to as being “back-end”. Frameworks that can accomplish both of these tasks and attempt to supply components for each layer in the stack, are referred to as “full-stack”. These are comparable to a one-stop shop for web development.

There are a number of web frameworks for Python such as Django, Flask, CherryPy, Pyramid, Grok, TurboGears, and Web2Py. The two that we will consider for the to-be-developed application are the most popular web frameworks for Python, Django and Flask.

Django

Django is a widely-used and venerable, robust, full-stack open-source framework that tries to automate some of the mundane tasks associated with web development. Its functionality can be further extended by the Django REST framework (DRF) to make RESTful APIs which can be consumed by a front-end javascript framework. Large projects such as Disqus and Instagram use Django.

Advantages of Django:

  • Batteries-included approach which provides many out of box features and reduces time to build complex applications, and deliver a final product faster. This makes it both versatile, and well suited for large-scale projects that require a lot of functionality.
  • Has a built-in Object Relational Mapping (ORM) system for relational databases that enables developers to perform common database tasks without having to write SQL queries.
  • DRF provides a straightforward method of mapping Django ORM models to API endpoints, as well as a web-browsable API to browse and execute all API endpoints.
  • Has a built-in template engine.
  • Comes with built-in complex tools for working with forms.
  • Comes with well configured, built-in bootstrapped admin for managing database content.
  • Has a built-in user model and an authentication system with permission levels and groups which is ready to use, and customizable.
  • Has built-in support for protection against XSS, CSRF, SQL injection, Clickjacking by default.
  • Ensures that developers follow best practices as everything has a template.

Disadvantages of Django:

  • Monolithic nature doesn’t allow for much flexibility beyond the provided out-of-box modules.
  • Database control is restricted to the Django ORM functionality. Furthermore, the Django ORM does not provide native support for non-relational databases like NoSQL.
  • DRF is based on Django ORM.
  • Not very flexible beyond the out-of-box modules, and packages like DRF, provided by Django.
  • A proper understanding of the framework is required to make use of it, resulting in a steep learning curve.
  • Due to its comprehensive out-of-the-box nature, it is not as light, nor as fast, as Flask.

Flask

Flask is a widely used, open-source microframework coming with minimalistic functionality that can be easily extended through a sprawling catalogue of supporting libraries. Large projects such as LinkedIn and Pinterest use Flask. Its functionality can be further extended by Flask-RESTful, an extension for Flask that provides additional support for building REST APIs which can be consumed by a front-end javascript framework.

Advantages of Flask:

  • Developers are free to use any plugins and libraries and build functionalities in a flexible and scalable way, providing them with control over the core of the application.
  • It has a much easier curve than Django, so that it is easier to launch into development.
  • Framework is minimalistic so that simple applications can be built quicker, using fewer lines of code than Django, while also providing the flexibility to expand these applications quickly through additional libraries.
  • Can support non-relational databases like NoSQL.
  • Has a built-in template engine, Jinja2.
  • Comes with built-in protection against XSS in Jinja2.
  • Can be extended through different libraries to provide functionality for an ORM, form handling, user model and authentication, security beyond XSS protection, and database admin.
  • More lightweight and generally faster than Django.

Disadvantages of Flask:

  • No built-in ORM, tools for forms, user model and authentication, or database admin.
  • Flask-Restful does not have a browsable API.
  • Does not enforce best practices.

Django or Flask?

Choice: Django

The steeper learning curve of Django may cause a bottleneck during early development; however, the benefits of its built-in functionalities would make middel-to-later-stage development, where more complex functionalities would be added to the application, faster. The to-be-developed application would require the use of relational databases, user profiles, good security practices, good coding practices (since this forms part of the assessment criteria), all of which Django and DRF can provide without having to extend functionality.

References:


⚠️ **GitHub.com Fallback** ⚠️