Tools
Tools: Guide to publish your first PyPI library ๐
2026-02-08
0 views
admin
Why to create a py package? ๐ค๐ ## ๐ Folder structure needed (yes, structure matters) ## Content of pyproject.toml โค๏ธโ๐ฅ ## Contents of MANIFEST.in (donโt skip ๐) ## Key rules ๐จ ## Requirements ๐ ## Steps to create & upload ๐ ## Install build tools ๐ ๏ธ ## Build your package ๐ฆ ## Upload to testPyPI (optional but smart ๐ง ) ## Upload to real PyPI ๐ ## Something more ๐ ## Common mistakes โ ## Pro tips ๐ก ๐ 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. 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. Just like Indiaโs budget announcements ๐ โ boring, structured, but very important. Mess this up, and PyPI will treat your package the way Twitter treats breaking news โ harshly ๐ฌ๐ฆ. This is the heart of deployment.
Mess this up and your package dies faster than a government promise during elections ๐ณ๏ธ๐. Yes, every line matters.
No, PyPI doesnโt care if โit worked locallyโ ๐โ. Ensures non-code files are packaged.
Skipping this is like hosting the World Cup final without a trophy ๐ โ technically possible, emotionally devastating. Without this, your PyPI page may break.
And users will judge you silently ๐ค. There are some key rules while uploading your package on the PyPI website. These are non-negotiable โ like ICC rules during finals ๐ค๐: ; 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 ๐๐. If this executes successfully (pray to the Python gods ๐๐), it will create: If it fails โ congrats ๐, youโre officially learning ๐คจ Then install your uploaded package from testPyPI: Test import + functionality here.
Break things now, not in production ๐ฌ๐ฅ. ; 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 ๐. โ Hardcoded paths
โ Forgot README / LICENSE
โ Version conflict
โ Import errors due to bad structure
โ Uploading secrets accidentally (this one hurts the most ๐๐) โ
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 Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse CODE_BLOCK:
my_package/
โ
โโโ src/
โ โโโ my_package/
โ โโโ __init__.py
โ โโโ core.py
โ โโโ utils.py
โ
โโโ tests/
โ โโโ test_basic.py
โ
โโโ README.md
โโโ LICENSE
โโโ pyproject.toml
โโโ MANIFEST.in
โโโ .gitignore Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
my_package/
โ
โโโ src/
โ โโโ my_package/
โ โโโ __init__.py
โ โโโ core.py
โ โโโ utils.py
โ
โโโ tests/
โ โโโ test_basic.py
โ
โโโ README.md
โโโ LICENSE
โโโ pyproject.toml
โโโ MANIFEST.in
โโโ .gitignore CODE_BLOCK:
my_package/
โ
โโโ src/
โ โโโ my_package/
โ โโโ __init__.py
โ โโโ core.py
โ โโโ utils.py
โ
โโโ tests/
โ โโโ test_basic.py
โ
โโโ README.md
โโโ LICENSE
โโโ pyproject.toml
โโโ MANIFEST.in
โโโ .gitignore CODE_BLOCK:
[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 = "[email protected]" }
]
requires-python = ">=3.8" dependencies = [
] [project.urls]
Homepage = "https://github.com/yourname/my-package" Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
[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 = "[email protected]" }
]
requires-python = ">=3.8" dependencies = [
] [project.urls]
Homepage = "https://github.com/yourname/my-package" CODE_BLOCK:
[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 = "[email protected]" }
]
requires-python = ">=3.8" dependencies = [
] [project.urls]
Homepage = "https://github.com/yourname/my-package" CODE_BLOCK:
include README.md
include LICENSE Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
include README.md
include LICENSE CODE_BLOCK:
include README.md
include LICENSE COMMAND_BLOCK:
pip install --upgrade build twine Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
pip install --upgrade build twine COMMAND_BLOCK:
pip install --upgrade build twine CODE_BLOCK:
python -m build Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
python -m build CODE_BLOCK:
python -m build CODE_BLOCK:
dist/
โโโ my_package-0.1.0-py3-none-any.whl
โโโ my_package-0.1.0.tar.gz Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
dist/
โโโ my_package-0.1.0-py3-none-any.whl
โโโ my_package-0.1.0.tar.gz CODE_BLOCK:
dist/
โโโ my_package-0.1.0-py3-none-any.whl
โโโ my_package-0.1.0.tar.gz CODE_BLOCK:
twine upload --repository testpypi dist/* Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
twine upload --repository testpypi dist/* CODE_BLOCK:
twine upload --repository testpypi dist/* COMMAND_BLOCK:
pip install --index-url https://test.pypi.org/simple/ my-package Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK:
pip install --index-url https://test.pypi.org/simple/ my-package COMMAND_BLOCK:
pip install --index-url https://test.pypi.org/simple/ my-package CODE_BLOCK:
twine upload dist/* Enter fullscreen mode Exit fullscreen mode CODE_BLOCK:
twine upload dist/* CODE_BLOCK:
twine upload dist/* - Name must be unique on PyPI (yes, utils, helpers, test-lib are already taken ๐)
- Version must follow semver
- Once uploaded โ cannot overwrite the same version (PyPI never forgets ๐) - 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 - build โ creates wheel & source
- twine โ uploads to PyPI (your final boss ๐ฎ)
how-totutorialguidedev.toaimlpythongitgithub