Skip to main content
Project generated with PyScaffold Built Status ReadTheDocs Coveralls PyPI-Server

validate-pyproject

Automated checks on pyproject.toml powered by JSON Schema definitions

Description

With the approval of PEP 517 and PEP 518, the Python community shifted towards a strong focus on standardisation for packaging software, which allows more freedom when choosing tools during development and make sure packages created using different technologies can interoperate without the need for custom installation procedures.

This shift became even more clear when PEP 621 was also approved, as a standardised way of specifying project metadata and dependencies.

validate-pyproject was born in this context, with the mission of validating pyproject.toml files, and make sure they are compliant with the standards and PEPs. Behind the scenes, validate-pyproject relies on JSON Schema files, which, in turn, are also a standardised way of checking if a given data structure complies with a certain specification.

Usage

The easiest way of using validate-pyproject is via CLI. To get started, you need to install the package, which can be easily done using pipx:

$ pipx install 'validate-pyproject[all]'
# or to install and run in a single command
$ pipx run 'validate-pyproject[all]' --help

Now you can use validate-pyproject as a command line tool:

# in you terminal
$ validate-pyproject --help
$ validate-pyproject path/to/your/pyproject.toml

You can also use validate-pyproject in your Python scripts or projects:

# in your python code
from validate_pyproject import api, errors

# let's assume that you have access to a `loads` function
# responsible for parsing a string representing the TOML file
# (you can check the `toml` or `tomli` projects for that)
pyproject_as_dict = loads(pyproject_toml_str)

# now we can use validate-pyproject
validator = api.Validator()

try:
    validator(pyproject_as_dict)
except errors.ValidationError as ex:
    print(f"Invalid Document: {ex.message}")

To do so, don’t forget to add it to your virtual environment or specify it as a project or library dependency.

More details about validate-pyproject and its Python API can be found in our docs, which includes a description of the used JSON schemas, instructions for using it in a pre-compiled way and information about extending the validation with your own plugins.

Plugins

The validate-pyproject-schema-store plugin has a vendored copy of pyproject.toml related SchemaStore entries. You can even install this using the [store] extra:

$ pipx install ‘validate-pyproject[all,store]’

Some of the tools in SchemaStore also have integrated validate-pyproject plugins, like cibuildwheel and scikit-build-core. However, unless you want to pin an exact version of those tools, the SchemaStore copy is lighter weight than installing the entire package.

If you want to write a custom plugin for your tool, please consider also contributing a copy to SchemaStore.

pre-commit / prek

validate-pyproject can be installed as a pre-commit hook:

---
repos:
  - repo: https://github.com/abravalheri/validate-pyproject
    rev: <insert current version here>
    hooks:
      - id: validate-pyproject
        # Optional extra validations from SchemaStore:
        additional_dependencies: ["validate-pyproject-schema-store[all]"]

By default, this pre-commit / prek hook will only validate the pyproject.toml file at the root of the project repository. You can customize that by defining a custom regular expression pattern using the files parameter.

You can also use pre-commit autoupdate or prek auto-update to update to the latest stable version of validate-pyproject (recommended).

You can also use validate-pyproject-schema-store as a pre-commit hook, which allows pre-commit to pin and update that instead of validate-pyproject itself.

Note

This project and its sister project ini2toml were initially created in the context of PyScaffold, with the purpose of helping migrating existing projects to PEP 621-style configuration when it is made available on setuptools. For details and usage information on PyScaffold see https://pyscaffold.org/.

Metadata

Release files for validate-pyproject 0.26

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for validate-pyproject 0.26
File Size Uploaded
validate_pyproject-0.26.tar.gz 122.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for validate-pyproject 0.26
File Interpreter ABI Platform
validate_pyproject-0.26-py3-none-any.whl Python 3 none any Details

Total release size: 178.2 kB

Release files / validate_pyproject-0.26.tar.gz

Download URL validate_pyproject-0.26.tar.gz
Size 122.1 kB
Tags Source
SHA-256 checksum
How to use checksums
eb3e48eeed404761ca4bb45a91d1fa82d83bbaf3aedcfca4ee9483b4bb3e2b9e
BLAKE2b-256 checksum
How to use checksums
c9ac5a51cd7e1c294d1bd3389d792617e015d3eda981242c1bbd8b21ee7c8725
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / validate_pyproject-0.26-py3-none-any.whl

Download URL validate_pyproject-0.26-py3-none-any.whl
Size 56.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab3fa448d7178d44d1b06e4b526ab5136e3faa7a1b7e7c6320c8a17fc11a9a2e
BLAKE2b-256 checksum
How to use checksums
0bde0fdee664da979fc0dd99398da63ccf228cb21de46a154dbc19fbf43e4d29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

This release

0.26 This release

2 release files

0.25

2 release files

0.24.1

2 release files

0.24

2 release files

0.23

2 release files

0.22

2 release files

0.21

2 release files

0.20.2

2 release files

0.19

2 release files

0.18

2 release files

0.17

2 release files

0.16

2 release files

0.15

2 release files

0.14

2 release files

0.13

2 release files

0.12.2

2 release files

0.12.1

2 release files

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.8.1

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7

2 release files

0.6.1

2 release files

0.6

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page