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.

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.0.tar.gz (18.4 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.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: git_unified_diff_parse-0.1.0.tar.gz
  • Upload date:
  • Size: 18.4 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.0.tar.gz
Algorithm Hash digest
SHA256 61ae051c8a9e9546cb86c3c808ff83113cbc635c37260bc66734e5fd9bcfb520
MD5 415aad2e34b62a162d1c0f6261286f36
BLAKE2b-256 ed8facfb008a451b4baa9440c90393adbf04f80073e9284413a1e8708ded3802

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_unified_diff_parse-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for git_unified_diff_parse-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6852ebe797b65c99e56355a195d938834bc88231f868620122fd85d042fbaed3
MD5 643b104a69d2365f42f89f8044ebe107
BLAKE2b-256 35a01e90a08b6d1988107883e78c57f3bc1b9d817ef3e66ac64e26d96abd2b22

See more details on using hashes here.

Provenance

The following attestation bundles were made for git_unified_diff_parse-0.1.0-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