pyproject-toml

0.1.0 · active · verified Fri Apr 17

pyproject-toml is a Python library designed to parse and manage `pyproject.toml` files according to various PEPs, including PEP 517, 518, 621, and 631. It provides a structured way to access project metadata and build system configuration. The current version is 0.1.0, and it follows an infrequent release cadence based on new PEP implementations or bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically create a dummy `pyproject.toml` file, load it using `PyProjectTOML`, and access common project metadata like name and version. The example cleans up the created file afterwards.

import os
from pyproject_toml import PyProjectTOML

# Create a dummy pyproject.toml for the example
dummy_toml_content = """
[project]
name = "my-dummy-project"
version = "0.1.0"
description = "A short description."
requires-python = ">=3.9"
authors = [
  {name = "Jane Doe", email = "jane@example.com"},
]
"""
with open("pyproject.toml", "w") as f:
    f.write(dummy_toml_content)

try:
    # Initialize and load the pyproject.toml file
    pyproject = PyProjectTOML()
    data = pyproject.load()

    # Access project metadata
    project_name = data["project"]["name"]
    project_version = data["project"]["version"]

    print(f"Project Name: {project_name}")
    print(f"Project Version: {project_version}")

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists("pyproject.toml"):
        os.remove("pyproject.toml")

view raw JSON →