๐ Do you also want to be included in that elite, mysterious, and totally brag-worthy list of contributors for a public PyPI package?
Yes? No? Still scrolling like itโs an Instagram reel? ๐ฑ
Cool, letโs fix that.
Why to create a py package? ๐ค๐
Before you start dreaming about PyPI fame (and GitHub stars ๐ that your relatives wonโt understand), pause for a reality check.
First, decide if your project is actually PyPI-worthy. Before touching configs, sanity-check that your project is reusable (no hardcoded paths, credentials, or โworks only on my laptopโ local files ๐ปโ) & has a clear entry point (functions/CLI).
If your script is โrun once and forgetโ โ PyPI is overkill ๐
If others (or future-you, after 3 months of memory loss ๐ง ) can reuse it โ publish it ๐
Think of it like the World Cup ๐ โ not every gully cricketer makes it to the squad, but the good ones do ๐
Same rules apply here.
๐ Folder structure needed (yes, structure matters)
Just like Indiaโs budget announcements ๐ โ boring, structured, but very important.
my_package/
โ
โโโ src/
โ โโโ my_package/
โ โโโ __init__.py
โ โโโ core.py
โ โโโ utils.py
โ
โโโ tests/
โ โโโ test_basic.py
โ
โโโ README.md
โโโ LICENSE
โโโ pyproject.toml
โโโ MANIFEST.in
โโโ .gitignore
Mess this up, and PyPI will treat your package the way Twitter treats breaking news โ harshly ๐ฌ๐ฆ.
Content of pyproject.toml โค๏ธโ๐ฅ
This is the heart of deployment.
Mess this up and your package dies faster than a government promise during elections ๐ณ๏ธ๐.
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "my-package"
version = "0.1.0"
description = "Utility to validate API responses using schema rules"
readme = "README.md"
license = { file = "LICENSE" }
authors = [
{ name = "FIRSTNAME LASTNAME", email = "your@email.com" }
]
requires-python = ">=3.8"
dependencies = [
]
[project.urls]
Homepage = "https://github.com/yourname/my-package"
Yes, every line matters.
No, PyPI doesnโt care if โit worked locallyโ ๐โ.
Contents of MANIFEST.in (donโt skip ๐)
Ensures non-code files are packaged.
Skipping this is like hosting the World Cup final without a trophy ๐ โ technically possible, emotionally devastating.
include README.md
include LICENSE
Without this, your PyPI page may break.
And users will judge you silently ๐ค.
Key rules ๐จ
There are some key rules while uploading your package on the PyPI website. These are non-negotiable โ like ICC rules during finals ๐ค๐:
- Name must be unique on PyPI (yes,
utils,helpers,test-libare already taken ๐) - Version must follow semver
- Once uploaded โ cannot overwrite the same version (PyPI never forgets ๐)
Requirements ๐
- A sample project which should adhere to these conditions
- Any code editor. Iโm using VS Code here (because obviously ๐)
- A valid package name should be unique โ ๏ธ
- A PyPI & test.pypi Account
; PyPI account can be created from here & tutorial for the same is in this youtube video
TestPyPI account can be created from here & tutorial for the same is in this youtube video
Yes, two accounts.
No, PyPI doesnโt trust you immediately โ neither should it ๐๐.
Steps to create & upload ๐
Install build tools ๐ ๏ธ
pip install --upgrade build twine
-
buildโ creates wheel & source -
twineโ uploads to PyPI (your final boss ๐ฎ)
Build your package ๐ฆ
python -m build
If this executes successfully (pray to the Python gods ๐๐), it will create:
dist/
โโโ my_package-0.1.0-py3-none-any.whl
โโโ my_package-0.1.0.tar.gz
If it fails โ congrats ๐, youโre officially learning ๐คจ
Upload to testPyPI (optional but smart ๐ง )
twine upload --repository testpypi dist/*
Then install your uploaded package from testPyPI:
pip install --index-url https://test.pypi.org/simple/ my-package
Test import + functionality here.
Break things now, not in production ๐ฌ๐ฅ.
Upload to real PyPI ๐
twine upload dist/*
; make sure dist/* uploads everything inside dist/.
And boom ๐ฅ โ Congratulations, youโve just uploaded your own package! ๐๐
Take a moment. Screenshot it. Flex on LinkedIn ๐.
Something more ๐
Common mistakes โ
โ Hardcoded paths
โ Forgot README / LICENSE
โ Version conflict
โ Import errors due to bad structure
โ Uploading secrets accidentally (this one hurts the most ๐๐)
Pro tips ๐ก
โ
Add CLI using entry-points
โ
Automate release via GitHub Actions
โ
Tag versions (v0.1.0)
โ
Add __version__ inside package
โ
Use ruff / black before publishing
Clean code = happy users ๐.
Hope youโve successfully created your first package on PyPI ๐๐ฏ
Do share your package name in comments โ letโs hype each other like World Cup fans ๐ฎ๐ณ๐.
Iโve recently committed pyshrink. Do check it out ๐โจ.
Also, if youโve got questions, confusion, or existential doubts about packaging โ comment it out ๐ฌ๐.
Author
๐ Nitin Kumar
Top comments (0)