The Python Package Index (PyPI) is a repository of python packages contributed by open-source python community to help others. What’s the purpose of creating packages? Without them, we would have to rely on sharing the code by copy/paste which is not efficient. A package can have pieces of code that grab data from an API, do some manipulations on inputs etc. Let’s see an example of python package I created to convert text to braille and steps to publish to PyPI.

Step 1: Set up the folder structure

Create a folder structure in the format shown below. The main package folder name should be same as your package name. The folder that contains your code can be named anything. Here I have kept the name same as the main package folder.

.
└── pybraille (main package folder)
    └── pybraille (folder that contains your code)
        └── your code here

Step 2: Add your code

Place all the class or script files in the folder that contains your code and add a init.py file. The init.py file should contain the import statements to expose only the required classes and functions you want the user to access. from pybraille.main import convertText, convertFile

**Also, you can add a list named all in the init.py file containing the module names. This allows the user to import all the module names mentioned in all variable when **from package import * is encountered.

__all__ = [‘convertText’, ‘convertFile’]

#pip #python-packages #python-programming #pypi #python

How to create a python package and publish to PyPI
1.20 GEEK