Skip to main content

A parser for unified git diff text into structured Python objects

Project description

git-unified-diff-parse

Parse unified git diff text into structured Python objects.

Install

pip install git-unified-diff-parse

Quickstart

from git_unified_diff_parse import DiffParser

files = DiffParser().parse(diff_text)

for f in files:
    print(f.status, f.new_path)
    for hunk in f.hunks:
        print(hunk.patch)

What you get

DiffParser.parse() returns a list of ChangedFile objects:

Field Type Description
new_path str | None Path on the new side; None for deleted files
old_path str | None Path on the old side; None for added files
status FileStatus added, modified, removed, renamed, copied
hunks List[DiffHunk] Each contiguous block of changes
is_binary bool True for binary files
old_ending_newline bool False if old file had no trailing newline
new_ending_newline bool False if new file has no trailing newline

Each DiffHunk has a patch property that renders the full unified diff block (header + prefixed lines), useful as LLM input.

Example usage

See examples/README.md for a full walkthrough — including how to run an explorer script against a built-in sample diff, a live git diff, or a saved diff file.

License

MIT

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

git_unified_diff_parse-0.1.1.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

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

git_unified_diff_parse-0.1.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file git_unified_diff_parse-0.1.1.tar.gz.

File metadata

  • Download URL: git_unified_diff_parse-0.1.1.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for git_unified_diff_parse-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0fd0244e8db0e899e9e636c4a83bd689c0c6271db152d379222c85e5be29cddc
MD5 bfa9090208dd64b9f1b71d9f665eab59
BLAKE2b-256 a61aa61c28912a8e32a15b275c13904eee4159cd11679c45f44e65ff30d6bc64

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_unified_diff_parse-0.1.1.tar.gz:

Publisher: publish.yml on kruthis123/git-unified-diff-parse

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

File details

Details for the file git_unified_diff_parse-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for git_unified_diff_parse-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd410e9c8d9415fdaf7a93ff272a1c1389d735fc2a22437957b1f71d5c8a8e62
MD5 c8c605a9f51c4effc399136d200f99f0
BLAKE2b-256 88cd4c277612106ee5532be18c8ac3ecb5e7f41aac9f9a3344e8af8db4fa5764

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_unified_diff_parse-0.1.1-py3-none-any.whl:

Publisher: publish.yml on kruthis123/git-unified-diff-parse

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