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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fd0244e8db0e899e9e636c4a83bd689c0c6271db152d379222c85e5be29cddc
|
|
| MD5 |
bfa9090208dd64b9f1b71d9f665eab59
|
|
| BLAKE2b-256 |
a61aa61c28912a8e32a15b275c13904eee4159cd11679c45f44e65ff30d6bc64
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
git_unified_diff_parse-0.1.1.tar.gz -
Subject digest:
0fd0244e8db0e899e9e636c4a83bd689c0c6271db152d379222c85e5be29cddc - Sigstore transparency entry: 1495983111
- Sigstore integration time:
-
Permalink:
kruthis123/git-unified-diff-parse@d0b846b2ae2b7d39b5f531d0250d88ac8785ae24 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/kruthis123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0b846b2ae2b7d39b5f531d0250d88ac8785ae24 -
Trigger Event:
push
-
Statement type:
File details
Details for the file git_unified_diff_parse-0.1.1-py3-none-any.whl.
File metadata
- Download URL: git_unified_diff_parse-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd410e9c8d9415fdaf7a93ff272a1c1389d735fc2a22437957b1f71d5c8a8e62
|
|
| MD5 |
c8c605a9f51c4effc399136d200f99f0
|
|
| BLAKE2b-256 |
88cd4c277612106ee5532be18c8ac3ecb5e7f41aac9f9a3344e8af8db4fa5764
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
git_unified_diff_parse-0.1.1-py3-none-any.whl -
Subject digest:
dd410e9c8d9415fdaf7a93ff272a1c1389d735fc2a22437957b1f71d5c8a8e62 - Sigstore transparency entry: 1495983235
- Sigstore integration time:
-
Permalink:
kruthis123/git-unified-diff-parse@d0b846b2ae2b7d39b5f531d0250d88ac8785ae24 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/kruthis123
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d0b846b2ae2b7d39b5f531d0250d88ac8785ae24 -
Trigger Event:
push
-
Statement type: