Build & Publish a Python Package
2024-10-26 19:26:41

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
32
from setuptools import find_packages, setup
import os

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

setup(
name='<package>',
version='0.0.1',
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',
)

run

1
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/*

publish to test.pypi:

1
twine upload -r testpypi dist/*

publish to pypi:

1
twine upload dist/*

more detail: https://www.youtube.com/watch?v=5KEObONUkik&t=918s

Prev
2024-10-26 19:26:41
Next