1 minute read

Python project could be a mess if you don’t have a clear structure. pyproject.toml is a file that helps you manage your Python project. It is a configuration file that contains information about your project, such as dependencies, build system, and other project metadata.

Combined with environment management tools like poetry, pipenv or conda, pyproject.toml can help you manage your Python project more efficiently.

What is pyproject.toml?

pyproject.toml is a configuration file that contains information about your Python project. It is used to specify the build system, dependencies, and other project metadata. It is a replacement for the setup.py file and is recommended by the Python Packaging Authority (PyPA) as the preferred way to manage Python projects.

Sample pyproject.toml:

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "spam-eggs"
version = "2020.0.0"
dependencies = [
  "httpx",
  "gidgethub[httpx]>4.0.0",
  "django>2.1; os_name != 'nt'",
  "django>2.0; os_name == 'nt'",
]
requires-python = ">=3.8"
authors = [
  {name = "Pradyun Gedam", email = "[email protected]"},
  {name = "Tzu-Ping Chung", email = "[email protected]"},
  {name = "Another person"},
  {email = "[email protected]"},
]
maintainers = [
  {name = "Brett Cannon", email = "[email protected]"}
]
description = "Lovely Spam! Wonderful Spam!"
readme = "README.rst"
license = {file = "LICENSE.txt"}
keywords = ["egg", "bacon", "sausage", "tomatoes", "Lobster Thermidor"]
classifiers = [
  "Development Status :: 4 - Beta",
  "Programming Language :: Python"
]

[project.optional-dependencies]
gui = ["PyQt5"]
cli = [
  "rich",
  "click",
]

[project.urls]
Homepage = "https://example.com"
Documentation = "https://readthedocs.org"
Repository = "https://github.com/me/spam.git"
"Bug Tracker" = "https://github.com/me/spam/issues"
Changelog = "https://github.com/me/spam/blob/master/CHANGELOG.md"

[project.scripts]
spam-cli = "spam:main_cli"

[project.gui-scripts]
spam-gui = "spam:main_gui"

[project.entry-points."spam.magical"]
tomatoes = "spam:main_tomatoes"

A short sample for personal project

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "bagel-factor"
version = "0.0.1"
authors = [
  { name="<NAME>", email="<EMAIL>" },
]
description = "<DESCRIPTION>"
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: MIT License",
    "Operating System :: OS Independent",
]
dependencies = [
    "pandas>=2.2.0",
    "matplotlib",
    "sqlalchemy>=2.0.0",
    "pymysql"
]   

[project.urls]
Homepage = "https://your-homepage.com"
Issues = "https://github.com/<your-repo>/issues"

Tags:

Updated: