user

Effective Python Package Management in 2024

Introduction

Crista Perlton

Crista Perlton


LATEST POSTS

How Licenses Work with Chocolately 22nd March, 2024

How to Handle npm Dependencies with Lock Files 16th January, 2024

Python

Effective Python Package Management in 2024

Posted on .

Python was ranked the second most popular coding language in a 2021 GitLab survey, raising from fourth place in 2014.

What is causing this upward trend?

Any Python developer will tell you it’s obvious: Python is a versatile language, has a widely diverse open-source community, and is easy to start.

Its ease of access, however, is a double-edged sword. It’s a good language for beginners, but it creates a huge knowledge gap between members of one team. How can Managers ensure a cross-trained group when standards aren’t required for good scripting?

We’ve curated a series of articles to address the many problems a diverse team of DevOps Engineers, Data Scientists, or anyone in a tech-related field will face when using Python in their operations.

How Exactly is Python Used?

Just as the internet of things is expanding to ordinary objects, Python language is being used in multiple fields thanks to its diverse functionality. It can run stats on returns in fintech, it can be scripted to run jobs in DevOps, and it can collect, scrape, and clean data for academic research – it can even help social media marketing teams analyze their KPIs.

Teams choose Python because it can create scripts, if not full applications. Strict standards don’t need to be applied to Python, unlike C# or Java, so skill level and language fluency are more open.

A user doesn’t have to be an expert to expertly use Python for their use case.

The versatility of the language explains why so many non-developers use it in their daily operations. Python is great for data processing, statistical analysis, finance, machine learning, deep learning, network automation, artificial intelligence, and so on.

Python Graphic User Interfaces

A.K.A. a Python GUI, is a great option for those not comfortable writing Python code.

Although it is a beginner-friendly language, it can still be difficult to learn for non-developers. Python needs to have accurate command-line arguments and any errors could lead to serious consequences.

Teams can avoid these learning gaps by introducing a GUI into their system. Teams with a Python GUI can safely and confidently:

  • run Python scripts independently
  • provide a job-specific interface to enforce limited input
  • limit who can do what with a Python script in that given situation
  • give immediate visual feedback (aka lets you know when you’ve forgotten a required form, for example)

Since they are meant to be intuitive and easy to use for anyone, it makes inaccessible technology accessible (especially for Linux).

Teams can create original GUIs through their own system or tools like Tkinter. We recommend creating Python scripts in Otter’s GUI-based development tool. Otter can run the scripts but also help with the learning curve of your company’s unique job processes.

Python Packages

Developers and non-developers alike can rely on the open-source community to jump-start their projects thanks to the hundreds of thousands of Python packages available online.

Some popular Python packages include:

  • pandas: a fast, powerful, flexible, and easy-to-use open-source data analysis and manipulation tool. It’s known as a fast, efficient, and easy-to-use tool for data analysis and manipulation.
  • NumPy: a Python library that provides a multidimensional array object, an assortment of routines for fast operations on arrays, and much more.
  • TensorFlow: an end-to-end open-source platform for machine learning. It has a comprehensive ecosystem of tools, libraries, and community resources that lets researchers and developers easily build and deploy ML-powered applications.

Developers can rely on these packages to cut down on production costs and avoid redundant work (why reinvent the wheel when it’s available and free on PyPi.org).

Just ensure you have a Package Approval Process before letting a team have free reign on open-source sites.

Python Package Managers

Python’s true power tool is the ecosystem of free and open-source libraries like Tensorflow, Netmiko, and Flask. These can be installed with a single command using a package manager.

Most Python users have a preferred manager. Some common ones are:

PyPI: The Package Index

Python’s own official third-party software repository. The Python Package Index (PyPI) is a repository of software that hosts an extensive collection of Python packages, development frameworks, tools, and libraries.

Pip: The Standard Package Manager

Pip is built into Python and can install packages from many different sources with PyPI.org as the primary and default package source used.

Virtual Environments & Virtualenv

In the Python world, a virtual environment is a folder containing packages and other dependencies that a Python project needs. The purpose of these environments is to keep projects separate and prevent dependency, version, and permission conflicts.

Problems with Python Packages

The downside to the huge availability of open-source Python packages can be boiled down to three main issues:

#1: License Agreements

Causally downloading a package from PyPI.org and integrating it into your project without checking its meta could have serious consequences.

Malicious packages or unacceptable licenses must be avoided while browsing open-source sites. If you or your team uses PyPI.org or third-party packages, consider including Python packages in your licensing policy.

Integrating Python packages into an organization’s existing third-party software policy allows developers to download from PyPI.org without constantly checking metadata because it’s already been done for them.

Adding packages to an existing licensing policy is easy: just ask for permission. A team lead or department head can set standards via a manual approval process or an automatic tool like ProGet and know they’re not at risk of legal trouble.

#2: Vulnerabilities

Did you hear about the malicious PyPI package that collects environment details and sends the info to an unknown web service?

A great way to prevent these possibly dangerous packages from making it through to production is by setting up a Package Approval Workflow and Connector Filters.

A package approval workflow is just like a code review but for open-source packages from PyPI. To use a package in a project, it’s reviewed by a trained “Approver.” Once reviewed and approved it’s made available to Python users, otherwise, it’s blocked from organizational use.

This ensures that a trained set of eyes get on every single PyPI package before it makes its way to Python coders or eventually production. The PyPI package is then put into a repository like ProGet so all Python users can easily access all the packages they need.

Connector filters can be introduced to any repository you have connected to PyPI and can filter out pre-approved or even pre-denied packages. This helps streamline your package approval workflow and gets your developers the packages they need quickly.

#3: Managing Python Dependencies

Python packages often depend on other packages known as dependencies. These dependencies can have their own dependencies, resulting in a complicated dependency tree.

If you’re building an application with Python and two packages require different versions of the same package, then Python will have a version conflict and your project may not build.

Fortunately, there are two easy ways to deal with complex dependencies:

Utilizing requirements.txt filesa package approval workflow, and ProGet’s Package Consumer will help ensure predictable builds and keep unwanted packages out of them.

In addition, incorporating automated Python testing in your CI/CD pipeline can enhance your development process. Automated testing catches potential issues immediately, and lightens the burden of manual testing.

Creating Python Packages

Many organizations choose to utilize third-party packages from PyPI, but many others create their own proprietary packages, never to be shared in the open-source community.

Making a Python package is like making a zip file with the metadata. There are multiple tools available to make a package like setuptools and then upload via twine, but ultimately it depends on the developer’s preferences.

We recommend using the following four best practices when creating Python packages. Since Python users are so diverse, setting these standards can help make the distribution of packages more efficient.

  1. Use One Repository & Wiki Per Library
  2. Keep Metadata Simple
  3. Use SemVer to help with Versioning and Dependency Tracking
  4. Use Wheels for Built Distribution

Integrating CI/CD into Your Python Development

The two aren’t often discussed together, but CI/CD principles and best practices can 100% apply to Python development.

Ever heard of a Python Pull and Pray? When you clone your application using git, install the dependencies with pip, and hope it all works out? This method causes a lot of problems: bloated deployment time; errors in the build; and no guarantee the app is the same server-to-server.

Enter CI/CD for Python: create a stable base, clone and commit frequently, and test rapidly. Integrate Docker with BuildMaster for advantages like faster and simpler deployments and consistency across different environments.

Setting up a Python CI/CD pipeline with Docker is easy and entirely customizable, allowing developers to optimize workflows and focus more on development tasks.

Optimizing Python for Your Projects

The huge potential of Python is reflected in the multiple industries it’s used in. Thanks to that, Python users are becoming more and more common, but that also means the knowledge gap is getting bigger and bigger.

In order to catch an entire team up to the organization’s speed, a manager could put hours into training, or they can set standards everyone can work in thanks to tools like ProGet and Otter.

Rely on Otter’s GUI-based server configuration to create reoccurring jobs or use ProGet to filter out unwanted packages and improve security.

This article was only the tip of the iceberg, consider reading out more in-depth blog posts about Vulnerability DetectionSemVer & CI/CD for PythonCreating Custom GUIs, and more.

Crista Perlton

Crista Perlton

Navigation