Python is one of the world’s most popular programming languages. Millions of developers worldwide use Python to do everything from writing basic scripts to building entire applications.
In this post, we’ll break down common use cases for Python and look at several ways you can take your Python usage from good to great.
Python’s most common use cases touch all sorts of programming disciplines. Python is a powerful language for data processing, using the Pandas library.
Python is a terrific web development platform , frequently leveraging the Django framework. Many colleges utilize Python for their introductory computer science classes every semester.
Finally, Python is one prong of the multi-language approach to machine learning first popularized by Tensorflow.
How to Start Working With Python
Python runs pretty well on about any operating system, and it likely has an installer for your operating system. If you’re getting started with Python, you’ll definitely want to familiarize yourself with the pip package manager and a virtual environment manager.
Also, while it’s possible to write Python using nothing but a text editor, I don’t recommend it. Instead, I suggest investing in a dedicated code editor like Visual Studio Code or a dedicated, fully featured development environment, PyCharm.
One feature of Python not immediately apparent is the syntax is white space sensitive. This means how you indent code blocks matters. Having an editor to automatically manage this is a big boost.
Big-Picture Python Problems
Python’s popularity is a double-edged sword. It’s excellent at doing several things, which means people choose it to solve all types of problems.
In this post, we’ll talk about a few of the thorny problems many Python applications run into regularly. This list isn’t exhaustive because we don’t have room to cover everything here. Also, many Python “problems” are general programming problems. They would be a problem if you chose Python or any of a dozen other languages.
I don’t want to discourage someone from using Python with this list. It’s one of my favorite languages. But, like any other language, it’s good to understand the pros and cons.
Coordinating Python Microservices
Python is a powerful language, and it’s easy to read, making it a popular choice for small, dedicated services within larger applications.
For reasons we’ll explore later in the post, Python is sometimes difficult to scale. This means teams adopt Python to power a microservice architecture run on top of individual containers.
Coordinating between these containers creates a whole set of challenges for developers. Often, each slice of the application will run in a container having only one job, but a single customer request might pass through multiple services. So, when something goes wrong, it isn’t easy to figure out where.
In truth, logging activity in microservices is a challenge for many languages. Python isn’t unique here. But it’s a prevalent problem for Python developers because Python is an excellent language for building microservices.
For many of the same reasons we discussed, Python is a popular choice for serverless applications. Again, Python is a popular choice because it’s supported nearly everywhere, and it’s easy to read, write, and maintain.
Serverless takes the “microservice” idea to the most extreme logical outcome. Instead of representing a single set of operations inside a dedicated container, serverless code often represents an activity at the lowest possible level. In a serverless environment, you think about your code not as a service but as an individual set of functions. There are a bunch of reasons why you might want to do this—both to help code organization and because it’s often cheaper than running dedicated servers.
But for complicated applications, a single request might pass through dozens of functions. In a traditional environment, an error in one function call toward the bottom of the stack will throw an error including a full-stack call.
In a serverless universe, each serverless function is entirely independent, meaning a failure in one function might result from a logical bug six functions up the chain. Figuring out where something went wrong is highly challenging when you have a tiny slice of the picture.
Python is an interpreted language. This is a benefit for a good amount of Python code. You can write a script on a Mac, deploy it to a Linux box, and trivially adapt it to run on Windows. You’ll notice minimal differences among the three major platforms.
Python’s developers also leverage the interpreted nature to adopt a simple, straightforward, easy-to-read syntax. Unfortunately, some of these choices made in the name of simplicity have negatively affected certain types of programs. An example is the Python global interpreter lock. This lock makes it difficult to leverage things like multiple hardware CPU threads to perform programming instructions in parallel.
When Python first grew in popularity, it was uncommon to regularly leverage parallelized instructions in most computing contexts. Today, it’s less true; many common computing problems are served by thinking about how the CPU can process data in parallel.
Python has a whole bevy of tools to help solve these problems. In truth, we could devote an entirely different post to the issues posed by parallel processing in Python. But the most common solution is adopting a multi-process approach over a multi-threaded approach. This is a little like our serverless example from earlier. When you approach a new problem to solve in a multi-process approach, you create an entirely new Python instance and pass some parameters to a new, dedicated script.
Like our previous example, this means tracking the path a single bit of data takes as it passes through the system is a real struggle.
How Does Papertrail Help?
All of these capital-B Big Python problems share a similar theme. They’re all problems where a minor problem turns into a big one because it’s hard to trace data through an application.
Python is one of the most popular tools for processing big chunks of data on the market today. Handling so much data means complexity in applications and how you troubleshoot those applications. This is where Papertrail comes in.
Papertrail is an application built to make it easy to trace data as it flows through an application. Anyone who’s supported a complicated application knows it’s easy to log reams of data in only a few seconds. The problem isn’t logging the data; it’s figuring out how to get information out of the data you logged.
When it comes to complicated Python applications, this problem is at the forefront. Because of Python’s unique scaling constraints, logs tend to get jumbled into one big mess. Papertrail helps you pull out the strings so you can trace data as it passes along a single thread throughout your application. When something goes wrong, it’s easy to figure out where the problem cropped up and where it originated.
Papertrail Unlocks Your Python
If you’re building or maintaining a complicated Python application, Papertrail is a perfect fit. There’s a free, no-risk plan, and it’s easy to boot up. Python as a language is great by itself. Like I said, it’s one of my favorite languages. But it’s better when you can sand off the rough edges through the judicious use of powerful tools.
This post was written by Eric Boersma. Eric is a software developer and development manager who’s done everything from IT security in pharmaceuticals to writing intelligence software for the US government to building international development teams for non-profits. He loves to talk about the things he’s learned along the way, and he enjoys listening to and learning from others as well.