Packaging Python Projects using setuptools

By ayed_amira , on 04/17/2020 , updated on 09/10/2020 , 4 comments - 5 minutes to read

Packaging Python Projects using setuptools : In this tutorial we will explain how to create a package of a python project using the setuptools library. We will see how to add the files and the structure that will allow us to create this package. Without further ado, let’s get to the heart of the matter! 🙂

Project name

First of all, we need to define a name for ourz python project. This project we will call it amira_data. I advise you to read the python documentation on modules and packages if you are a beginner on the subject. In the rest of the tutorial, we will use this amira_data project for all our explanations. You can directly rename it for your case if you wish ! 🙂

Create the project locally

To create the amira_data project locally, simply create the following file structure :


For the rest of the tutorial it will be necessary to be at the root of the project. The following shell command will have to be done:

cd tutorial

The __init.py__ file is required to import the directory as a package. It can be empty.

Generate the package files

We will first create files to prepare the packaging. Here is the architecture of the package :


Creation of the python file

The python file will be useful for the setuptools building script. It gives setuptools information about the package you want to create. Open the file in a text editor to edit it. I will show you an example of how to use setuptools that I will detail later.

import setuptools

with open("", "r") as fh:
    long_description =

    author="A AMIRA",
    description="example package",
        "Programming Language :: Python :: 3",
        "Operating System :: OS Independent",

As we can see, the setup() function can take several arguments :

  • Name: Name of the distribution of the package. It must contain only letters, numbers and the characters and _ . It must not also exist on the website.
  • Version: The version of the package. I invite you to consult the PEP 440 documentation for the choice of version numbers.
  • Author: Allows to identify the author of the created package. Author_email is the author’s email address.
  • Description: A patented description of the package
  • long_description: A more detailed description of the package. Here we get the content of the file that we will detail later in the tutorial.
  • long_description_content_type: Indicates the type of markup used in the long description.
  • url: Url of the package’s web home page
  • packages: Lists all the packages used in this project. The find_packages() function allows us to do it directly, it avoids omissions.
  • classifiers: Gives some additional metadata about our package. For a complete list of available classifiers, you can consult this link :
  • python_requires:

There are many unused options for this example package. For more details, please consult the official documentation :


Provides a description of what the package does :

This package allows you to understand how to create a python package

Creating LICENCE.txt

It is very important that each package created is a license. This allows future users of this package to understand the conditions under which they can use this package.

Generating distribution archives

This step consists in generating archives which are downloaded in the index package and which can be installed by pip :

We need to have the latest versions of setuptools and wheel :

python -m pip install --user --upgrade setuptools wheel

Then, execute the following command in the directory where the file is present :

python sdist bdist_wheel

This command generates two files :


Uploading the distribution archives

The first step is to create an account on Test PyPI which is a separate instance of the package index for testing. Go to and follow the steps for creating the account

The second step is to create a token to access the API. Go to:

Once your account is created and your token is created, just execute these two shell commands :

python -m pip install --user --upgrade twine
python -m twine upload --repository-url dist/*

The first command installs Twine. The second command downloads all the archives to the dist folder. You will be prompted to enter your account information (username and password). For the username use __token__ and for the password use the value of the token previously created.

The amira-data-aa package should now be visible on TestPypi at this address:

You can now install your package using the pip command:

python3 -m pip install --index-url --no-deps amira-data-aa

And finally you can use this package in your python program like this:

import amira-data-aa


You now know how to create a python package thanks to setuptools. I hope you have learned a lot. Feel free to send me feedback if you have any blocking points on this subject, I would be happy to answer them! 🙂

If you want to learn more about python, you can read this book (As an Amazon Partner, I make a profit on qualifying purchases) :

Back to the Python section


I'm a data scientist. Passionate about new technologies and programming I created this website mainly for people who want to learn more about data science and programming :)


On 04/17/2020 at 13 h 39 min, Pkv games said:

Thanks for sharing your thoughts about id master pro. Regards

Your reply will be revised by the site if needed.

On 04/17/2020 at 14 h 38 min, 먹튀 said:

Wonderful work! That is the type of info that are meant to be
shared across the web. Disgrace on the search engines for not positioning this post higher!
Come on over and seek advice from my website
. Thanks =)

Your reply will be revised by the site if needed.

On 04/17/2020 at 17 h 44 min, said:

Good post. I'm going through many of these issues as well..

Your reply will be revised by the site if needed.

On 04/22/2020 at 3 h 40 min, Narwhale io said:

Hurrah! In the end I got a webpage from where I be
able to in fact take helpful facts concerning my study and knowledge.

Your reply will be revised by the site if needed.

Leave a comment

Your comment will be revised by the site if needed.