Skip to main content

A static analysis tool for diffing public Python APIs.

Project description

Difflog

Automated Changelog Generation via API Diffing for Python Projects

Difflog simplifies the task of generating changelogs by using static analysis to detect API-level changes in Python scripts. It outputs a concise Markdown changelog, ideal for release notes or CI/CD workflows.

Example integration: See .github/workflows/changes.yml


Installation

Install Difflog via pip:

pip install difflog

Detecting API Changes Between Files

Given two versions of a Python script:

main1.py

def main():
    print("Hello, world!")

if __name__ == "__main__":
    main()

main2.py

def main(name: str):
    print("Hello, world! My name is", name)

if __name__ == "__main__":
    main("John")
    print("Goodbye, world!")

Run the following command to detect API differences:

python -m difflog main1.py main2.py

Example output:

[main] Added positional or keyword argument `name`

For more examples, see tests/test_api_diffing.py


Generating a Markdown Changelog from Git

If you're working in a Git repository, you can generate a changelog based on file-level API changes between commits:

difflog.git_report > CHANGES.md

This will:

  • Analyze code changes since the last Git push
  • Output a changelog in GitHub's Markdown format to CHANGES.md

You can also specify a revision range:

difflog.git_report --from-rev v1.0.0 --to-rev HEAD > CHANGES.md

Programmatic API Usage

Use Difflog as a Python module for custom workflows, e.g., filtering changes, customizing output formats, etc.

import difflog

with open("old_file.py") as f:
    old_code = f.read()

with open("new_file.py") as f:
    new_code = f.read()

for change in difflog.diff(old_code, new_code):
    print(change)

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository
  2. Create a new branch
  3. Submit a pull request

See existing issues or open a new one to discuss your ideas.


License

Licensed under the Apache License 2.0. See LICENSE for details.


Acknowledgments

Difflog leverages the excellent DeepDiff library for structural diffing.

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

difflog-0.0.2.dev0.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

difflog-0.0.2.dev0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file difflog-0.0.2.dev0.tar.gz.

File metadata

  • Download URL: difflog-0.0.2.dev0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for difflog-0.0.2.dev0.tar.gz
Algorithm Hash digest
SHA256 194a715038d6019b1453c0593beb1d84ce6d7e7b7c862102c372683052262d93
MD5 37a914a88c87e0d44920b354eacb0a4a
BLAKE2b-256 c7c851e17db7c37d9656d9a0a77a1b65a58afd6fcfd974e06d7672276795abf3

See more details on using hashes here.

File details

Details for the file difflog-0.0.2.dev0-py3-none-any.whl.

File metadata

  • Download URL: difflog-0.0.2.dev0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for difflog-0.0.2.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 af0c1eb1d07c1fa17d9d0110c12d3cefb84b0d153f63f95caeeb88034f863f19
MD5 a3f4b25afc4a6117a233e2d21f6ff432
BLAKE2b-256 7b41e7ef88c6ab0afcff4690fc507e3dc0c79e05c1693636a89a87efe5189979

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