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