Creating Python Packages
This site will inform you how to create your own Python Packages on Pypi.org . This is a global public site that is accessible to anyone around the world. It allows anyone to pip install <yourpackage>
Pre-requisite
You must perform the following pre-requistes.
Important
Create an account on Pypi.org
You must also generate a token. This token should start with pypi-. SAVE THIS TOKEN. You will need it to upload your package to Pypi.org
Install the following packages:
Python 3.12 or greater
pip install twine==6.2.0
pip install setuptools==80.9.0
Create local folder on your machine. You can choose proper name. For our example, we will create a folder called: pythonpackage
Inside pythonpackage create your package. For our example, we created studenttestpackage
Inside studenttestpackage create another folder with the SAME name: studenttestpackage
Important
You MUST choose your own unique python package name. You CAN NOT choose: studenttestpackage it is already an existing python package under a different username.
How to Create Your Own Python Packages
Tip
All files for this demo are located on Github
Follow these steps
Goto folder: c:/>pythonpackage/studenttestpackage
Download the Github files locally to your computer from here: studenttestpackage
Goto folder: c:/>pythonpackage/studenttestpackage/studenttestpackage
Download the Github files locally to your computer from here: studenttestpackage/studenttestpackage
In the file c:/>pythonpackage/studenttestpackage/setup.py
You MUST have the following:
name=’studenttestpackage’, (THIS MUST MATCH THE NAME OF YOUR PACKAGE)
packages=[‘studenttestpackage’], (THIS MUST MATCH THE NAME OF YOUR PACKAGE)
Goto folder: c:/>pythonpackage/studenttestpackage/studenttestpackage
In the file c:/>pythonpackage/studenttestpackage/studenttestpackage/__init__.py
This is the file that EXPORTS your python function that you write. In this example all functions are defined in file myfunctions.py
You MUST have the following:
In the file c:/>pythonpackage/studenttestpackage/studenttestpackage/myfunctions.py
This is the file where you define your functions.
The other files in c:/>pythonpackage/studenttestpackage/
requirements.txt (This is where you can define additional packages you need and Python will automatically download them so users of your package DO NOT have to)
license.txt (This is the file you can define any licensing for your package)
readme.md (This is the file where you write the documentation for your package. For example, how to use the functions in myfunctions.py
Uploading Your Package to Pypi
You are ready to upload your package. Follow these steps:
Goto folder: c:/>pythonpackage/studenttestpackage/
Execute the command 1:
python setup.py sdist bdist_wheel
Execute the command 2:
twine upload dist/*
See your package on Pypi.org: studenttestpackage
Install your package
pip install studenttestpackage==1.0
Run your Python function in your Package: testprogram.py
SUCCESSFUL RESULT!
Modify Files to Build Your OWN Python Package
The above files will produce a python package studenttestpackage - but you want to create a NEW python package for yourself. To do this you can easily modify the folders and files.
Important
Everytime you make changes to your package you MUST provide a new version number in the setup.py
You want to create OWN Package. To the following:
Modify the name of the package: studenttestpackage to your desired name i.e. bugsbunny in steps 4.a and 4.b
Modify 9.a and 9.b to your new package name bugsbunny
name=’bugsbunny’, (THIS MUST MATCH THE NAME OF YOUR PACKAGE)
packages=[‘bugsbunny’], (THIS MUST MATCH THE NAME OF YOUR PACKAGE)
Modify 11.a
name = “bugsbunny” (THIS MUST MATCH THE NAME OF YOUR PACKAGE)
Re-Run: 14.a, 14.b, 14.c
Install your package
pip install bugsbunny==1.0
import the package in your Python program
import bugsbunny as tp



