How to create a python package and publish to PyPI. The Python Package Index (PyPI) is a repository of python packages contributed by open-source python community to help others.
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.
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
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’]
Guide to Python Programming Language
Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?
When I decided to publish a Python package for the first time, I had difficulties finding resources for the beginner. So, here it is- the basics to publishing a Python Package in PyPi and getting your work out there.
Python Hello World Program - Your first step towards Python world. Learn how to create the Hello World Python program in PyCharm.
Python Programming Tutorials For Beginners