Book Image

Hands-On Enterprise Application Development with Python

By : Saurabh Badhwar
Book Image

Hands-On Enterprise Application Development with Python

By: Saurabh Badhwar

Overview of this book

Dynamically typed languages like Python are continuously improving. With the addition of exciting new features and a wide selection of modern libraries and frameworks, Python has emerged as an ideal language for developing enterprise applications. Hands-On Enterprise Application Development with Python will show you how to build effective applications that are stable, secure, and easily scalable. The book is a detailed guide to building an end-to-end enterprise-grade application in Python. You will learn how to effectively implement Python features and design patterns that will positively impact your application lifecycle. The book also covers advanced concurrency techniques that will help you build a RESTful application with an optimized frontend. Given that security and stability are the foundation for an enterprise application, you’ll be trained on effective testing, performance analysis, and security practices, and understand how to embed them in your codebase during the initial phase. You’ll also be guided in how to move on from a monolithic architecture to one that is service oriented, leveraging microservices and serverless deployment techniques. By the end of the book, you will have become proficient at building efficient enterprise applications in Python.
Table of Contents (24 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Index

Where Python shines


Every language has been developed to solve a certain type of problem that developers face while trying to build software for a specific domain. Python, being a dynamically typed, interpreted language, also has a set of use cases where it excels.

These use cases involve the automation of repetitive and boring tasks, quick prototyping of applications, and small applications focusing on accomplishing a specific goal, such as the installation of software, the setting up of a development environment, performing cleanup, and so on.

But is that all? Is Python good only for doing small tasks? The answer to this is no. Python as a language is much more powerful and can easily accomplish a large amount of increasingly complex tasks, such as running a website that scales to cope with millions of users using it in a very short span of time, processing large sets of incoming files, or training a machine learning model for an image-recognition system.

We are talking about achieving increasingly complex tasks using Python, but isn't Python slow compared to our traditional compile-time languages, such as C++, Java, and .NET? Well, that completely depends upon the context in which a person wants to use Python. If your aim is to run a Python program on an embedded device with only a limited amount of processing power, then yes, Python might be inadequate because of the sheer extra load that its interpreter will have on the processing environment. But if you are planning to use Python to run a web application on decently configured modern hardware, you might never experience any slowdowns while using Python. Rather, you might well feel a bit more productive while using it because of the sheer simplicity of its syntax and the ease of performing operations without writing hundreds of lines to achieve simple tasks.

So, let's see how Python fares in the enterprise environment.

The requirements of enterprise IT

Enterprise IT is complex, and an application that needs to be built for the enterprise will differ a lot from one that is built for a regular consumer. There are several factors that need to be kept in mind before developing an application for enterprise users. Let's take a look at what makes enterprise IT applications different from regular consumer offerings, as shown in the following list:

  • Business oriented:Unlike an application that is built to solve the problems of individual users, an enterprise application is built to meet the specific needs of an organization. This requires the application to conform to the business practices of the organization, their rules, and the workflow they use.
  • Robustness at scale: Most enterprises usually consist of thousands of employees who depend upon the internal applications to work and collaborate with each other. These kinds of use cases generate a large amount of data in various ways, and an application built for enterprise should be robust enough to handle thousands of users at the same time while also being able to crunch through a large amount of data that is distributed over a large network of nodes. During this time, the application should provide adequate mechanisms to deal with unexpected events that may happen for various reasons, such as attempts to breach security, the failure of nodes, power failure, and so on.
  • Long-term support: An enterprise application needs to provide long-term support because enterprises usually don't want to move to newer applications as frequently as a regular consumer does. This happens because most enterprise applications are developed to integrate with the workflow of the organizations, and frequently changing an application will not only increase ownership costs for the enterprise, but will also cause a major disruption in the workflow for the employees of the organization.
  • Ability to integrate: Most of the applications that are built for the enterprise won't be running as standalone applications. They will frequently need to interface with the other applications inside the organization. This gives rise to the need to provide a mechanism for easy integration of the application with others in the organization.

Python in the enterprise ecosystem

Python has been present in the enterprise ecosystem in quite a few forms; be it the automation of boring and repetitive tasks, being used as a glue between two layers of a product, or being used for building quick and easy-to-use clients for big server backends, the language has seen an increasing amount of adoption for various use cases. But what makes Python ready for the development of large enterprise applications? Let's take a look:

  • Ability to build quick prototypes: The syntax of Python is very simple, and a lot of things can be achieved with very few lines of code. This allows developers to quickly develop and iterate over the prototypes of an application. In addition to this, these prototypes do not always need to be thrown away, and if the development is properly planned, they can act as a good base to build the final application upon.

    With the ability to quickly prototype an application, an enterprise software developer can see exactly how the requirements align in the application and how the application is performing. With this information, the stakeholders of the application can more accurately define the path for the application development, thereby avoiding midcycle architectural changes because something didn't work out the way it was expected to.
  • A mature ecosystem: The mature ecosystem is one of the features of Python that deserve a lot of attention. The number of external libraries in Python has been growing at a rapid pace. For most of the tasks that need to be achieved in an application, such as two-factor authentication, testing code, running production web servers, integrating with message buses, and so on, you can easily look for a library with quite decent support.

    This proves to be of great help, since it reduces the amount of code duplication and increases the reusability of the components. With the help of tools such as pip, it is very easy to get the required library added to your project, and with the support of tools such as virtualenv, you can easily segregate a lot of different projects on the same system without creating a dependency mess.

    For example, if someone wants to build a simple web application, they can probably just use Flask, which is a microframework for developing web applications, and go ahead with the development of the web application without having to worry about the underlying complexities of dealing with the sockets, manipulating data on them. All they will require is a few lines of code to get a simple application up and running, as shown in the following code:

from flask import Flask
app = Flask(__name__)

@app.route('/', methods=["GET"])
def hello():
    return "Hello, this is a simple Flask application"

if name == '__main__':
    app.run(host='127.0.0.1', port=5000)

Now, as soon as someone calls the preceding script, they will have a flask HTTP application up and running. All that remains to be done here is to fire up a browser and navigate to http://localhost:5000. Then we will see Flask serving a web application without any sweat. All of this is made possible in under 10 lines of code.

With a lot of external libraries providing support for a lot of tasks, an enterprise developer can easily enable support for new features in the application without having to write everything from scratch, thereby reducing the chance of possible bugs and non-standardized interfaces creeping into the application. 

  • Community Support: The Python language is not owned by any particular corporate entity, and is completely supported by a huge community backing that decides the future of the standard. This ensures that the language will continue to see support for quite a long time, and won't become obsolete any time soon. This is of great importance to organizations, since they want long-term support for the applications they run.

Given all of the preceding benefits of Python, developer productivity will get a boost when using the language while also reducing the total cost of ownership for the software if decisions are made in a well-planned way. These decisions involve how the application architecture will be laid out and which external libraries to use or to develop in-house. So yes, Python is indeed now ready to be used in the mainstream world of enterprise application development.