Skip to main content

Tool for checking for breaking changes in Python APIs

Project description

About pyapi-checker

Tool for checking for and acknowledging Python API breaking changes. Inspired by gradle-revapi and built with the aexpy API explorer.

Usage

Once you've installed pyapi-checker in an environment in your project you can interface with the pyapi CLI.

pyapi analyze is the command for checking for API breaks in your project which will produce output like this if you have 2 API breaks for example, and also exit with exit code 1:

Python API breaks found in my-lib:
AddRequiredParameter: Add PositionalOrKeyword parameter (functions.bin.parse.parse): new_param.
MoveParameter: Move parameter (functions.bin.parse.parse): handle_errors: 3 -> 4.

So you would want to include pyapi analyze in your CI process to require developers to acknowledge API breaks when creating PRs on a library.

Accepting Breaks

You can accept a single break via:

pyapi acceptBreak "{break code}" "{justification why this is ok}"

Or accept all breaks via:

pyapi acceptAllBreaks "{justification why this is ok}"

Accepted breaks will populate in the .palantir/pyapi.yml file looking like this:

acceptedBreaks:
  version:
    projectName:
    - code: 'break code'
      justification: justification

Version overrides

Sometimes the previous release will have a successfully applied git tag but a failed publish build. In this case pyapi-checker will fail as it cannot resolve the previous API to compare against. To resolve this, you can set a version override that will use a different version instead of the last git tag. To do so, use the

pyapi versionOverride <last-published-version>

command to use the last correctly published version instead. This will create an entry in .palantir/pyapi.yml of the following format:

versionOverrides:
  version: <last-published-version>

Configuration

Python Index

After identifying the last published version preceeding your current commit, pyapi-checker downloads the corresponding wheel for your package and version from a Python index. If you do not specify an index then pyapi-checker uses the following in order (if set):

  1. PIP_INDEX_URL
  2. UV_DEFAULT_INDEX
  3. https://pypi.org/simple

To manually set an index you can set the following configuration:

[tool.pyapi-checker]
index = "<your-index-url>"

Implementation

pyapi-checker uses aexpy to power it's API breakage detection. You can check out the list of types of API breaks that aexpy detects here.

Note: aexpy does not consider any breaks to an internal module, function, attribute, etc. a high priority breaking change and thus we will not flag these breaks to you.

Developer Setup

This repo uses hatchw which is a wrapper around Hatch which automatically installs Python (versions 3.9-3.13) (via uv) and Hatch in a repo-specific venv such that this repo uses Hatch in an isolated manner.

hatchw essentially passes all args to Hatch and so with our scripts in the pyproject.toml file the workflows are intended to be the following:

  1. Run tests: ./hatchw run test
  2. Check formatting/linting/type checking: ./hatchw run check-format
  3. Format/fix linting issues: ./hatchw run format
  4. Build package: ./hatchw run build

If you want to disable any output produced by hatchw itself pass the --hatchw-quiet flag which is not propagated to Hatch.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyapi_checker-0.12.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyapi_checker-0.12.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file pyapi_checker-0.12.0.tar.gz.

File metadata

  • Download URL: pyapi_checker-0.12.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for pyapi_checker-0.12.0.tar.gz
Algorithm Hash digest
SHA256 9106c0bba8df877d12f69f1483121030055a9198b124071955ad6fb90d08c7a6
MD5 f612be62f23d83ed00171c1640a837d9
BLAKE2b-256 99445aac5354fb173e9d80ad1ee7186172351e8058f16d41cbee1a5cf4526c7e

See more details on using hashes here.

File details

Details for the file pyapi_checker-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyapi_checker-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe429962a566e2866b6027d1f7987c55ac66592547b98ffc313d23db70ac4c70
MD5 affaeb12f1420999d5e3a59bf7f718d5
BLAKE2b-256 b55e686c0482adc1a8d1fbb4031102f89d2e49acbb9c80e9d36c698be2c68555

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page