DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Make your first Python Package and publish it to PyPi!

Posted on

Make your first Python Package and publish it to PyPi!

Hello there! This blog post is on how you can publish your first Python package.

PS: It is really easy!

What are Python packages?

A bunch of reusable code scripts can be called a package, it's something like this.

You've probably written some awesome code, which can be reused, and you want to share it with the world!

This tutorial is just for that! While GitHub is a great place to distribute code, Python Package index let's you directly import code without having to copy it into your directory!


  1. Basic Python knowledge.
  2. Linux or Macintosh OS, unfortunately publishing a package from Windows is quite hectic.
  3. A PYPI account
  4. A GitHub account

And we should be good to go!

Here I will be showing you how I published pysherlock:

Step 1: Make a new folder named after your package.

In my case it was pysherlock, In your folder make another folder with the same name as the parent folder.

This is where the code will go.

There will be two files in here:

  2. is to import all your functions from the file is where all your code will go.

Step 2: Write some code

For this tutorial let's write some basic code.

Assume that your package's name is 'pyword'(very creative I know)

def wordrep(word:str):
Enter fullscreen mode Exit fullscreen mode

So what this basically does is, when a string is passed as an argument it simply repeats the word entered. Also you might face an indentation error, which can easily be fixed.

Now to the file, remember to add the underscores before and after init.

from pyword.main import wordrep
Enter fullscreen mode Exit fullscreen mode

And boom your package is ready for publication, now for the formalities.

Step 3: Push to GitHub

Publish your code to GitHub by making a repo

Step 4: Other files config

This how your directory must look:


It might look complex but it's actually quite easy.

The file is a python file whiih basically tells the PYPI repo what your package is.

Let's get started with it

import setuptools

# Reads the content of your into a variable to be used in the setup below
with open("", "r", encoding="utf-8") as fh:
    long_description =

    name='pyword',                           # should match the package folder
    packages=['pyword'],                     # should match the package folder
    version='0.1',                                # important for updates
    license='MIT',                                  # should match your chosen license
    description='Baically repeats what you say.',
    long_description=long_description,              # loads your
    long_description_content_type="text/markdown",  # is of type 'markdown'
    author='your name',
    author_email='your email address',
    url='your github repo name', 
    project_urls = {                                # Optional
        "Headless Chrome": "your github repos issues page"
    install_requires=['requests','qrcode','wikipedia','beautifulsoup4'], #these are filler packages, you need to fill them with the packages your python package will require to function                 
    keywords=["screenshot", "pyautogui", "scrot", "raspberry pi"], #descriptive meta-data
    classifiers=[                                   #
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',

        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',

Enter fullscreen mode Exit fullscreen mode

Now to the file, this file is to be written by you, it's basically short documentation for your package.

Here's a really simple website I use for writing my readme files.
Make a read me

License.txt is again a file you must choose for your package, depending on what your package does you can choose a License and use it.

Use this link to know what License fits your package.
Open source initiative

Now to the setup.cfg file

description-file =
Enter fullscreen mode Exit fullscreen mode

That is all!

Now that all your files are ready let's publish it!

First in your Home directory create a file names .pypirc

It should contain the following info:

index-servers = 
username: your_username_from_pypi
password: your_password_from_pypi
Enter fullscreen mode Exit fullscreen mode

And save it, the "pypi" in line 3 should be placed after a single 'TAB' key press.

This basically enters the data required to push your package into the pypi repository.

Step 5: Final step, uploading to pypi

Now towards the final steps

pip install twine

After this is done, cd into the directory and type the following into your terminal.

python3 sdist
Enter fullscreen mode Exit fullscreen mode

This builds the distribution file required.
Do not tamper with this File.

After this is done type the following:

python3 -m twine upload dist/*
Enter fullscreen mode Exit fullscreen mode

And that's it!

There should be a link below saying where your package has been published.

Click on it and it will lead to your packages pypi page, install it and test it out!

Happy Coding and if any doubts don't forget to to comment and ask your doubts.

Also please do leave a like and follow me for more such tutorials and articles related to programming.

Top comments (3)

raywp profile image
Raymond Wangsa Putra

Interesting, simple, and easy to understand. Great job💯
Imo, in step 4, all the files and folder seems like to be on the same level (im using android), is there anyway you could fix the indentation? That would be nice.

vadimkolobanov profile image
Vadim Kolobanov

Thank you, an interesting topic, you are well done

cyber profile image
Sachit71 Author

Thanks means a lot!

🌚 Friends don't let friends browse without dark mode.

Just kidding, it's a personal preference. But you can change your theme, font, etc. in your settings.

The more you know. 🌈