π How to Publish Your Own Python Package on PyPI β A Beginner-Friendly Guide
Publish your own Python package like a pro using GitHub + PyPI
π¦ Example Package: VickClass on PyPI
π» Source Code: github.com/imvickykumar999/PyPI-API
π§ Why Publish to PyPI?
If you've written a Python class or module that others might find useful, share it with the world by publishing it to PyPI — the official Python package repository.
Once published, users can install your package with a simple:
pip install YourPackageName
Sounds cool? Let’s get started!
π Project Structure
Set up your project like this:
PyPI-API/
βββ vicksclass/
β βββ __init__.py
β βββ vicks.py
βββ README.md
βββ setup.py
βββ MANIFEST.in
βββ License.txt
βββ requirements.txt
π‘ Example: vicks.py
Put your core functionality here. A simple example:
class Bank_Account:
def __init__(self, balance=0):
self.balance = balance
print("Hello!!! Welcome to the Deposit & Withdrawal Machine")
def deposit(self, amount):
self.balance += amount
print("\n Amount Deposited:", amount)
def withdraw(self, amount):
if self.balance >= amount:
self.balance -= amount
print("\n You Withdrew:", amount)
else:
print("\n Insufficient balance")
def display(self):
print("\n Net Available Balance =", self.balance)
π Required Files Explained
setup.py
This file tells PyPI what your package is all about:
from setuptools import setup, find_packages
setup(
name='VickClass',
version='0.0.1',
description='A simple class utility package',
long_description=open('README.md', encoding='utf-8').read(),
long_description_content_type='text/markdown',
url='https://github.com/imvickykumar999/PyPI-API',
author='Vicky Kumar',
author_email='imvickykumar999@gmail.com',
license='MIT',
packages=find_packages(include=['vicksclass']),
keywords=['class', 'bank', 'python'],
classifiers=[
'Development Status :: 3 - Alpha',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
],
python_requires='>=3.6',
)
MANIFEST.in
Tell PyPI what extra files to include:
include README.md
include License.txt
π README.md
This is what shows up on your PyPI project page. Add a quick intro, usage example, and links to GitHub/docs.
π οΈ Step-by-Step Guide to Publish
1. Install Required Tools
pip install --user build twine
2. Build the Package
python3 -m build
This creates a dist/ folder with .tar.gz and .whl files.
3. Create a PyPI Account
-
Go to pypi.org
-
Confirm your email
-
Go to your account settings → API tokens → Create a new token
4. Upload to PyPI
twine upload dist/* --non-interactive -u __token__ -p pypi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Make sure to replace pypi-xxxxxxxx... with your actual API token.
β Install and Use Your Package
pip install VickClass
Then use it in your code:
from vicksclass.vicks import Bank_Account
acc = Bank_Account(1000)
acc.deposit(500)
acc.withdraw(200)
acc.display()
π Updating Your Package
To update your package:
-
Change the version in
setup.py(e.g.,0.0.1→0.0.2) -
Rebuild:
python3 -m build
-
Re-upload:
twine upload dist/*
π§ Final Thoughts
Publishing to PyPI helps you:
-
Distribute your code easily
-
Practice writing reusable and documented modules
-
Share with the global Python community
-
Build a public portfolio of your Python work
π Credits
This guide was inspired by a real project:
π¦ VickClass on PyPI
π Source Code on GitHub
Have questions or feedback?
Feel free to open an issue on GitHub or contact the author.
Happy coding! π¨π»π
0 Comments