Install/update pip (python package manager)
python3 -m pip install --upgrade pip
Create a project with the structure same like this
packaging_pypa
├── LICENSE
├── README.md
├── pyproject.toml
├── src
│ ├── eat-the-whole-world
│ │ ├── __init__.py
│ │ └── factorial.py
└── tests
packaging_pypa
: working directoryREADME.md
: say something about your projectLICENSE
: tells users who install your package the terms under which they can use your packagetests/
: test filessrc
: contains package source code,eat-the-whole-world
: name of package, it should be unique that doesn’t conflict with packages uploaded by other people
pyproject.toml
: project metadata, here is a sample
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "eat-the-whole-world"
version = "0.0.1"
authors = [
{ name="linhpduc", email="<real_email>" },
]
description = "A package can eat the whole world"
readme = "README.md"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
Create distribution archives
python3 -m pip install --upgrade build
python3 -m build
Goto PyPI or TestPyPI website to reg an account and create a API Token. Save API token to file ~/.pypirc
:
[testpypi]
username = __token__
password = <real_token>
Install twine
, a tool for publishing packages
python3 -m pip install --upgrade twine
Upload all of the archives
python3 -m twine upload --repository testpypi dist/*
And ... let's rock!