Skip to main content

Python plugin for api-parity (reference walker + port annotations).

Project description

api-parity-py

Python plugin for the api-parity project. Produces JSON envelopes that the api-parity differ consumes.

See the project README for the full cross-language story (Python ↔ Rust, four directions).

Install

pip install api-parity-py

Modes

How entries get produced, chosen with --mode:

  • Walker — introspects a package's public API via inspect.getmembers and emits one entry per class / method / property / function. Works on both kinds of envelope.
  • Annotation — collects decorators (@parity, @parity_impl, @parity_ref) attached to your own code at import time. Works on both kinds of envelope.
  • AST — parses source files with ast, without importing them. reference only.

Defaults: reference → walker, port → annotation.

Usage

# Walk an upstream package as a reference:
api-parity-py reference pyspark.sql.connect -o ref.json

# Annotate your own port (see below) and dump it:
api-parity-py port mylib -o port.json

# Or walk your own library and treat every public API as implemented:
api-parity-py port --mode=walker mylib -o port.json

Inventorying source you can't import

Both the walker and the annotation collector load the target. When that isn't possible — a test suite its distribution doesn't ship, or a module whose import pulls in a dependency graph that fails for reasons unrelated to the names you want — read the names off the syntax tree instead:

api-parity-py reference pyspark.sql.tests.test_catalog \
  --from-source vendor/test_catalog.py -o ref.json

target is the dotted name in every mode; --from-source (which selects mode = ast) only changes where the names are read from. Point it at a file and target names that module; point it at a directory and target names that package, with the files beneath it extending the name. Either way entries key to the paths your annotations are written against, not to where the source sits in your checkout.

Only lexically-present names are visible: base classes are names rather than resolved classes, so inherited members stay attributed to the class that declares them; import-time construction is invisible; and kind follows decorator spelling. Prefer the walker whenever the target imports cleanly.

Annotating a Python port

from api_parity_py import parity, parity_impl, Status

@parity_impl(path="pyspark.sql.session.SparkSession", status=Status.IMPLEMENTED)
class SparkSession:
    @parity(path=".sql", status=Status.IMPLEMENTED, since="3.4")
    def sql(self, query): ...

    @parity(path=".stop", status=Status.UNIMPLEMENTED, comment="no shutdown hook yet")
    def stop(self): ...

A leading . in a child path is rewritten to <parent>.<child> at decoration time. Status.UNIMPLEMENTED requires a comment.

For declarative reference inventories (rare — usually a walker is better), see @parity_ref.

End-to-end

api-parity-py reference pyspark.sql.connect -o ref.json
api-parity-py port      mylib                -o port.json
api-parity   compare    ref.json port.json

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

api_parity_py-0.0.3.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

api_parity_py-0.0.3-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file api_parity_py-0.0.3.tar.gz.

File metadata

  • Download URL: api_parity_py-0.0.3.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for api_parity_py-0.0.3.tar.gz
Algorithm Hash digest
SHA256 54565556fb9f8be3cfac91c3de466fb072ca66f81dd4cc4f24c9b32e9b67f26a
MD5 c6265f4671c4aeb062d6e17a0597f111
BLAKE2b-256 c763acadfac504c8067a10ea21a2f7b27931a796348399ce2abd680bbef68416

See more details on using hashes here.

Provenance

The following attestation bundles were made for api_parity_py-0.0.3.tar.gz:

Publisher: release.yaml on franciscoabsampaio/api-parity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file api_parity_py-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: api_parity_py-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for api_parity_py-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 38bb91b735227f21c6d67b496e549274f290d3b3e74f7c4e3edbfae37d27dffc
MD5 57362994563bb5ee4080e39b6d0c188f
BLAKE2b-256 99bc706cd98330864c8485ecc25b5bde56137a048c3e81968280f3c4062bfb35

See more details on using hashes here.

Provenance

The following attestation bundles were made for api_parity_py-0.0.3-py3-none-any.whl:

Publisher: release.yaml on franciscoabsampaio/api-parity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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