๐Ÿš€ How to Publish Your Own Python Package on PyPI โ€” A Beginner-Friendly Guide

๐Ÿš€ 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:

  1. Change the version in setup.py (e.g., 0.0.10.0.2)

  2. Rebuild:

python3 -m build

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading...