fabricatio-diff
Intelligent diff-based editing for LLM-driven text transformations. Combines fuzzy line matching, hashline-anchored edits, and LLM-generated search-and-replace operations into a single package.
Installation
This package is part of the fabricatio monorepo and can be installed as an optional dependency:
pip install fabricatio[diff]
# or
uv pip install fabricatio[diff]
For a full installation:
pip install fabricatio[full]
# or
uv pip install fabricatio[full]
Overview
fabricatio-diff provides two complementary layers for text editing:
- Rust-accelerated primitive operations — hashline anchoring, fuzzy line matching, unified diffs, and similarity measurement, exposed via PyO3 bindings.
- Python orchestration — a
Diffmodel andDiffEditcapability that use LLMs to generate search/replace operations from natural language requirements and apply them with configurable precision.
Key Components
Diff model
Represents a text transformation as a search / replace pair with optional line-range anchoring.
from fabricatio_diff.models.diff import Diff
# Pattern-matching diff
d = Diff(search="old text", replace="new text")
result = d.apply(source_text, match_precision=0.9)
# Anchor-based line-range diff (stable against content shifts)
d = Diff.from_anchors(start_anchor="10:a1b2", end_anchor="15:c3d4", replace="new lines")
# Line-number-based range diff
d = Diff.from_line_range(start=10, end=15, replace="new lines")
# Reverse a diff
rev = d.reverse()
# Format content with LINE:HASH anchors for LLM prompt context
hashed = d.format_with_hashes(source_text)
DiffEdit capability
Mixin class that delegates diff generation to an LLM via prompt templates. Parses the LLM response for <<<<SEARCH / <<<<REPLACE blocks and constructs a validated Diff.
from fabricatio_diff.capabilities.diff_edit import DiffEdit
class MyAgent(DiffEdit, SomeOtherCapability):
pass
agent = MyAgent()
result = await agent.diff_edit(source_text, "rename variable x to count")
Rust Primitives (imported from fabricatio_diff.rust)
| Function | Description |
|---|---|
rate(a, b) |
Normalized Damerau-Levenshtein similarity (0.0–1.0) |
match_lines(haystack, needle, precision=0.9) |
Find a fuzzy-matching block of lines |
show_diff(a, b) |
Generate a unified diff between two strings |
compute_hash(line) |
xxHash-based per-line hash |
format_hashes(content, start_line=1) |
Annotate each line with LINE:HASH |
parse_hashline_anchor(anchor) |
Parse "42:ab12" into (line, hash) |
apply_set_line(content, anchor, new_text) |
Replace one line by anchor |
apply_insert_after(content, anchor, text) |
Insert after an anchored line |
apply_replace(content, old, new, all=False) |
Simple text substitution |
apply_replace_lines(content, start, end, text) |
Replace a range between two anchors |
Configuration
from fabricatio_diff.config import DiffConfig
# Match precision threshold (1.0 = exact, lower = fuzzier)
diff_config.match_precision = 0.85
# Prompt template for diff generation
diff_config.diff_template = "my/custom/template"
The DiffConfig dataclass is loaded from the global Fabricatio configuration system under the "diff" key.
Dependencies
fabricatio-core— core interfaces, configuration system, and prompt template manager- Rust crates:
strsim(similarity),similar(unified diffs),rho-hashline(line hashing),rayon(parallel search)
License
MIT — see LICENSE
Metadata
Release files for fabricatio-diff 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 23.3 MB
Release files / fabricatio_diff-0.4.0-cp314-cp314-win_amd64.whl
| Download URL | fabricatio_diff-0.4.0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
df6d1a4602483abd8331ca637760b0994454108975aeab248b4c16e136095be7
|
|
BLAKE2b-256 checksum How to use checksums |
e5d03c6a120c9a1ad50369ed38609ff06c5b34488f789728ebe6b83d36a8211c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl
| Download URL | fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.14 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
d097da19b9cfb13be790a2ca7a807c9bf40e27a8c621201b28b2e819be7b4eb7
|
|
BLAKE2b-256 checksum How to use checksums |
222faaa4b7fe09c0dd12250344515c56af8a2aa0d2da01225cb101bbf6524c77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl
| Download URL | fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.14 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
445c17e56b0a3614ed164422ffd18ce41f637354ee489d0fb49534c4f6378fd2
|
|
BLAKE2b-256 checksum How to use checksums |
f1f16a708487ee8f232f8fdb927c89f2dfa51bacd0ba6c3554dc93a076cd1eda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | fabricatio_diff-0.4.0-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
555632d09811ef1467b2b222dbc7b397405fd128830e071835ddcf8e6cf8a6bd
|
|
BLAKE2b-256 checksum How to use checksums |
20941bae0fa3bbe7ae15a09cb2965764409c14d8662ae21c559a0ddc021eb948
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp313-cp313-win_amd64.whl
| Download URL | fabricatio_diff-0.4.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7d8198834b51f8cec60b3035173a9d5c30268b5cb712335e562340923154daf8
|
|
BLAKE2b-256 checksum How to use checksums |
1c484a62c338bc7fa3974efabf7f51052f6cbec25f610e7723dfe7e26e17e4dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
2cca920c62f8fe12bcce2f4138bb6a3590757b8673f5aedcb9055da628319176
|
|
BLAKE2b-256 checksum How to use checksums |
f9d1f9f2e35aabf92508835f3815b34776049f88006291099eb7b3c9d7edc7a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl
| Download URL | fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
c27f1504e4e3277029ae6477d15269a10b703d47034199dcc10c8dc104713506
|
|
BLAKE2b-256 checksum How to use checksums |
9972397257fd93f4fe3b75853e3d66be0224daaa02c55a2de20e9033fe4425c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | fabricatio_diff-0.4.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
45e897d11e80dfb3bbbae4497ade9e27ca881d8c8eafc763907ff8282efb590b
|
|
BLAKE2b-256 checksum How to use checksums |
48c58e8d83cec99f6a826407085125460f051d002209332da1ccfffe59aa72af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp312-cp312-win_amd64.whl
| Download URL | fabricatio_diff-0.4.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f4e29d44ea60745263894b41f9371c8d93a379fdd9fa035599fc0b226f017e50
|
|
BLAKE2b-256 checksum How to use checksums |
f42f34e2eb170ca2a14a993f60310a53f947d7929b14f948bb0a26e1a1e117fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
| Download URL | fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 2.2 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
e140661fb3c3856ed730c0010664ae3d6871c1bbc6a40997b71876221f5034c6
|
|
BLAKE2b-256 checksum How to use checksums |
359abfd23ae1599750dfa2f02f613ecfc90ac0738e08a6f36f1d7ecb159b0a41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl
| Download URL | fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ ARM64 |
|
SHA-256 checksum How to use checksums |
7d7bc746b179eb6adb38ce938aba5b5c835b124fe482197a6fdeac77a1678639
|
|
BLAKE2b-256 checksum How to use checksums |
eed0348fefffcd38cc50554fa9390c8c4e96c25b0befa21a7ffc1890b75042ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / fabricatio_diff-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | fabricatio_diff-0.4.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ab090515432952d7308dda76399dfcae386dd0a64bbb1d8642ddac7110d1aecc
|
|
BLAKE2b-256 checksum How to use checksums |
eacb0dc8591451deea02726eafa250ceb101b1c37e8f7a1ba00c60eea65739cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|