Simplifying Package Distribution with setuptools and pyproject.toml

fadingna

fadingNA

Posted on November 18, 2024

Simplifying Package Distribution with setuptools and pyproject.toml

Hi Everyone,

Have you ever built something cool with Python and wanted to share it with the world? Maybe you’ve made a game, a tool, or something to help with work. If you want others to use it easily, you need to package it up and put it in a place where everyone can get it—like PyPI! Let’s talk about two tools that help with this: setuptools and pyproject.toml.


What is setuptools?

  • Think of setuptools as your helpful friend who makes packing easy. When you want to share your project, setuptools helps bundle all the files together neatly. This way, anyone who wants to use your project can get everything they need, without missing a piece.

What is pyproject.toml?

pyproject.toml is like a checklist for setuptools. It tells setuptools (and other tools) what to do and what your project is all about. It’s just a file you write to explain things like

  • What your project is called.
  • Where to find more information (like a website).

tutorial using pypi packing your project

Example for pyproject.toml

  • You can create pyproject.toml on the root of your project, but please be careful about your project structure.
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "chat-minal"
version = "1.0"
authors = [
  { name = "Nonthachai Plodthong", email = "fadingna@procode.ca" }
]
description = "Chat Completion running on CLI using Language, support OpenAI and Groq"
readme = "README.md"
requires-python = ">=3.11"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent"
]

[project.urls]
Homepage = "https://github.com/xxxx/chat-completion-api"
Issues = "https://github.com/xxxx/chat-completion-api/issues"
Enter fullscreen mode Exit fullscreen mode

However, my app is have sub-directory which is /app so we need to specify on pyproject where to look for main entrance.

[tool.setuptools.packages.find]
where = ['app']
Enter fullscreen mode Exit fullscreen mode

That's it your pyproject.toml is ready for upload to pypi or test-pypi.

Step to upload to PyPi

  1. Build Your Project:

python3 -m build

  1. Upload to PyPi python3 -m twine upload dist/* this will upload to pypi.org

python3 -m twine upload --repository test-pypi dist/* this will upload to test-pypi.org


Wrapping Up

With setuptools and pyproject.toml, packaging and sharing your Python project is easy and fun! You’ve got everything you need to let the world see and use what you’ve built.

chat-minal · PyPI

Chat Completion running on CLI using Language, support OpenAI and Groq

favicon pypi.org
💖 💪 🙅 🚩
fadingna
fadingNA

Posted on November 18, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related