Uploading python packages to be used by anyone with python

Advaith S
3 min readFeb 1, 2022
http://pypi.org

So let's see how to upload a python package for anyone to use in the world

First let's look at what is a package, why you would want to upload a python package and then how to do it…

What:

What is a python package? A python package is some python code that is uploaded in a server which will not be in your system when you install python but you can install it with a command line tool call pip which stands for Preferred Installer Program and is used by all python programmers because it it is easier to code and creates lesser clutter

Installing a package-

pip install <package_name>

Why:

Why would you want to make a package? The answer depends on you, if you will be needing the package code frequently then you can install it in your local machine. But if you are working with a team, then it would make more sense to upload the package so that anyone can use it

How:

Now we come to, how you can upload a python package for anyone with python to use it. For that to happen you have to add the package to a website called PyPi

To do that follow these steps:

1-Fix you project directory

It is very important to have a specific project directory or else it will cause many errors…’’’speaking from experience’’’

the Readme file is not compulsory, but inside the main folder have another folder with the module name insitd which keep your main python file and an __init__.py file, make sure your main python file is not the same name as the module, and inside the file add your code inside a function… But i would prefer adding it inside a class with a dunder init function like so..

Code-

now in the __init__.py file do-

change .module to your main file name without .py and change Hello to your class or function name

Setup.py-

in the main directory make a file called setup.py and add the following code-

change the version to your required version.

change description and in long description change to string or write a readme file and leave the code as it is

in the setup function change the name, author, email, and in install_requires variable add the extra variables required in the module

change the keywords and change the value in classifiers

now open your terminal in the main directory and run the command

$ python3 setup.py sdist bdist_wheel

and then you will have a couple new files or folders in the directory

then run

$ python3 -m twine upload dist/*

but before that make an account in pypi.org then add the username and password in terminal and the package will upload

Done!! your module is uploaded in pypi and now anyone can use it

For any issues ask me in my module blch’s github repo!

--

--