pyproject-parser

0.14.0 · active · verified Thu Apr 16

pyproject-parser is a Python library designed to parse and access data from 'pyproject.toml' files, adhering to PEP 517 and PEP 621 specifications. It simplifies programmatic access to project metadata, build system configurations, and other sections defined in 'pyproject.toml'. The library is actively maintained, with frequent releases, often including pre-releases (betas) before stable versions, and is currently at version 0.14.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a 'pyproject.toml' file and access its project metadata using the `PyProject` class and its `from_path` method. It creates a temporary dummy 'pyproject.toml' to ensure the example is runnable.

from pyproject_parser import PyProject
from pathlib import Path

# Create a dummy pyproject.toml for demonstration
dummy_toml_content = '''
[project]
name = "my-awesome-project"
version = "0.1.0"
authors = [
    {name = "John Doe", email = "john@example.com"}
]
description = "A minimal project"
readme = "README.md"
requires-python = ">=3.8"
keywords = ["python", "example"]
classifiers = [
    "Programming Language :: Python :: 3"
]

[build-system]
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"
'''

dummy_toml_path = Path("dummy_pyproject.toml")
dummy_toml_path.write_text(dummy_toml_content)

try:
    project = PyProject.from_path(dummy_toml_path)

    print(f"Project Name: {project.name}")
    print(f"Project Version: {project.version}")
    print(f"Required Python: {project.requires_python}")
    if project.authors:
        print(f"Author: {project.authors[0].name} <{project.authors[0].email}>")
finally:
    # Clean up the dummy file
    dummy_toml_path.unlink()

view raw JSON →