[tutorial] Build your own python package

๐Ÿ“Œ Introduction

Building your own Python package is beneficial for maintaining large projects, as it helps manage code that is otherwise scattered across directories.

๐Ÿš€ Quick Start

  • Create a setup.py file:
1
2
3
from setuptools import setup, find_packages

setup(name="ntust_simslab", version="0.13", packages=find_packages())
  • Create a pyproject.toml file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[tool.poetry]
name = "ntust_simslab"
version = "0.13"
description = "A simple example for building a Python package."
authors = ["Hsiang-Jen Li <hsiangjenli@gmail.com>"]
readme = "README.md"
packages = [{include = "ntust_simslab"}]

[tool.poetry.dependencies]
python = "^3.8"
requests = "^2.28.2"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

๐Ÿ” Recap

  • Building a Python package helps maintain code organization in larger projects.
  • Using setup.py is the traditional method, while pyproject.toml is the modern approach with Poetry.
  • Itโ€™s essential to have an account on PyPI to publish your package.

๐Ÿ”— References

[tutorial] Build your own python package

https://hsiangjenli.github.io/blog/tutorial_pypi_pkg/

Author

Hsiang-Jen Li & ChatGPT-4o Mini

Posted on

2024-01-15

Updated on

2025-02-28

Licensed under