Skip to main content

Python API dumping and comparison tool

Project description

Python API dumping and comparison tool

Dumps the public API of a Python module and its members to a file, which can then be used to show differences in the public API between two dumps, e.g. of different versions of the same module.

Command-line interface

$ py-api-dumper --help
  • To dump the public API of a module mymod:

    $ py-api-dumper dump -o mymod1.dump mymod
    

    mymod1.dump will record the public API of mymod in a reloadable format.

  • To print the API of mymod in text format:

    $ py-api-dumper dump mymod
    MODULE : mymod
        CLASS : myclass
            FUNCTION : __init__ : no-return-type
                REQUIRED : 0 : x : int
    ...
    

    The text format is a tree of entries of each nested class, class method, function, member variable, etc. in the public API.

  • To compare the API of mymod between different versions:

    $ py-api-dumper diff mymod-old.dump mymod-new.dump
    --- mymod-old.dump mymod=1.0
    +++ mymod-new.dump mymod=2.0
    +MODULE : mymod
    +    CLASS : myclass
    +        FUNCTION : __init__ : no-return-type
    +            REQUIRED : 1 : b : no-type
    

    The above output shows the expected output if, between mymod versions 1.0 and 2.0, an additional positional argument b had been added to the __init__ method of the class mymod.myclass.

    $ py-api-dumper diff -o mymod.diff ...
    

    This will write out the API differences to mymod.diff in JSON format:

    • the paths to the dumps of the old and new APIs, e.g. mymod-old.dump vs. mymod-new.dump;
    • the version of mymod at the old and new API dumps, e.g. mymod 1.0 vs. 2.0;
    • API entries which have been removed, i.e. present in the old API but not in the new API (e.g. none in the above example);
    • API entries which have been added, i.e. present in the new API but not in the old API (e.g. the b argument in the above example).

Python interface

from py_api_dumper import APIDump, APIDiff
  • To dump the public API of a module mymod:

    import mymod
    dump = APIDump.from_modules(mymod)   # OR: APIDump.from_modules("mymod")
    dump.save_to_file("mymod.dump")
    
  • To print the API of mymod in text format:

    dump.print_as_text()
    
  • To compare the API of mymod between different versions:

    diff = APIDiff.from_files("mymod-old.dump", "mymod-new.dump")
    diff.print_as_text()
    with open("mymod.diff", as file):
          diff.print_as_json(file)
    

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

py_api_dumper-2.0.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

py_api_dumper-2.0.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file py_api_dumper-2.0.1.tar.gz.

File metadata

  • Download URL: py_api_dumper-2.0.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for py_api_dumper-2.0.1.tar.gz
Algorithm Hash digest
SHA256 82ba973c96c20f62a7657c6d8e0b5cd1d5cce6f1d0d8946feb61bbc5440cead5
MD5 3c2204149aad44c044314cc21464f2f0
BLAKE2b-256 aac2d7bb149984736818d50c77b16d1c84a472628930ae541cc458d7b0808420

See more details on using hashes here.

File details

Details for the file py_api_dumper-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: py_api_dumper-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for py_api_dumper-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b77cb85ce206572b1f94660d04be4adb17c5b6e4f19b8ba734d2f0125051256
MD5 3384d903df674b28e159427415f6c451
BLAKE2b-256 38c34d16b905390240d59d6322b17477cfe48bcd53e1770c30b2163cfe4bd688

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