Build & Publish a Python Package
2025-11-29 17:36:46

Build

Prepare setup.py
An example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from setuptools import find_packages, setup

with open("README.md", "r") as f:
long_description = f.read()

setup(
name='<package>',
version='0.0.1', # update this if you are updating new version
description='',
packages=find_packages(include=['<package>', '<package>.*']),
long_description=long_description,
long_description_content_type="text/markdown",
url='',
author='',
author_email='',
license='GPL-3.0',
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
],
install_requires=[
'pandas',
'numpy'
],
extras_require={
'all': [],
'dev': ['pytest>=7.0', 'twine>=4.0.2']
},
python_requires='>=3.6',
)

If you have previous build, remember to clean them up by

1
rm -rf dist build *.egg-info

run

1
2
3
python -m build # recommended, requires "build" package
# or
python setup.py bdist_wheel sdist

(optional) to test package locally

1
pip install .

Publish

Setup info on test.pypi or pypi if not yet. The API key for publishing can be found there.

check:

1
twine check dist/* # requires "twine" package

publish to test.pypi:

1
twine upload -r testpypi dist/*

publish to pypi:

1
twine upload dist/*

For more detail check Youtube tutorial

Prev
2025-11-29 17:36:46
Next