Skip to main content

An extension of fabricatio, which brings up the diff edit capabilities

Project description

fabricatio-diff

MIT Python Versions PyPI Version PyPI Downloads PyPI Downloads Bindings: PyO3 Build Tool: uv + maturin

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:

  1. Rust-accelerated primitive operations — hashline anchoring, fuzzy line matching, unified diffs, and similarity measurement, exposed via PyO3 bindings.
  2. Python orchestration — a Diff model and DiffEdit capability 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

fabricatio_diff-0.4.0-cp314-cp314-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.14Windows x86-64

fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

fabricatio_diff-0.4.0-cp314-cp314-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

fabricatio_diff-0.4.0-cp313-cp313-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.13Windows x86-64

fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

fabricatio_diff-0.4.0-cp313-cp313-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

fabricatio_diff-0.4.0-cp312-cp312-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12Windows x86-64

fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl (1.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

fabricatio_diff-0.4.0-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file fabricatio_diff-0.4.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 df6d1a4602483abd8331ca637760b0994454108975aeab248b4c16e136095be7
MD5 04ed0ff2fb343d92cf38e0ee25fe5888
BLAKE2b-256 e5d03c6a120c9a1ad50369ed38609ff06c5b34488f789728ebe6b83d36a8211c

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d097da19b9cfb13be790a2ca7a807c9bf40e27a8c621201b28b2e819be7b4eb7
MD5 020530f88fbf0af432d605c73ec36cd9
BLAKE2b-256 222faaa4b7fe09c0dd12250344515c56af8a2aa0d2da01225cb101bbf6524c77

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ ARM64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 445c17e56b0a3614ed164422ffd18ce41f637354ee489d0fb49534c4f6378fd2
MD5 ea8674f47234175a3181ce00fb91e0f6
BLAKE2b-256 f1f16a708487ee8f232f8fdb927c89f2dfa51bacd0ba6c3554dc93a076cd1eda

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.14, macOS 11.0+ ARM64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 555632d09811ef1467b2b222dbc7b397405fd128830e071835ddcf8e6cf8a6bd
MD5 3e467359a1113f34c9dd56c8d960fe49
BLAKE2b-256 20941bae0fa3bbe7ae15a09cb2965764409c14d8662ae21c559a0ddc021eb948

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7d8198834b51f8cec60b3035173a9d5c30268b5cb712335e562340923154daf8
MD5 8cae30e690442ca8f3a17f84127bc519
BLAKE2b-256 1c484a62c338bc7fa3974efabf7f51052f6cbec25f610e7723dfe7e26e17e4dc

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2cca920c62f8fe12bcce2f4138bb6a3590757b8673f5aedcb9055da628319176
MD5 7ade596cb390af829a2babb3505da3e5
BLAKE2b-256 f9d1f9f2e35aabf92508835f3815b34776049f88006291099eb7b3c9d7edc7a4

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ ARM64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c27f1504e4e3277029ae6477d15269a10b703d47034199dcc10c8dc104713506
MD5 90783567546f7034aaa27d05030e1dcd
BLAKE2b-256 9972397257fd93f4fe3b75853e3d66be0224daaa02c55a2de20e9033fe4425c4

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.13, macOS 11.0+ ARM64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 45e897d11e80dfb3bbbae4497ade9e27ca881d8c8eafc763907ff8282efb590b
MD5 990a463a0e9cf6bc8403c0e1305f292a
BLAKE2b-256 48c58e8d83cec99f6a826407085125460f051d002209332da1ccfffe59aa72af

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f4e29d44ea60745263894b41f9371c8d93a379fdd9fa035599fc0b226f017e50
MD5 b329ad508f885304c7723f840bc81359
BLAKE2b-256 f42f34e2eb170ca2a14a993f60310a53f947d7929b14f948bb0a26e1a1e117fe

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ x86-64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e140661fb3c3856ed730c0010664ae3d6871c1bbc6a40997b71876221f5034c6
MD5 c59fc5faf767ccda835497ae6bdf6076
BLAKE2b-256 359abfd23ae1599750dfa2f02f613ecfc90ac0738e08a6f36f1d7ecb159b0a41

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.12, manylinux: glibc 2.34+ ARM64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 7d7bc746b179eb6adb38ce938aba5b5c835b124fe482197a6fdeac77a1678639
MD5 c4c70e6340d116fdf2330769c9db8ec7
BLAKE2b-256 eed0348fefffcd38cc50554fa9390c8c4e96c25b0befa21a7ffc1890b75042ba

See more details on using hashes here.

File details

Details for the file fabricatio_diff-0.4.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

  • Download URL: fabricatio_diff-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: CPython 3.12, macOS 11.0+ ARM64
  • Uploaded using 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}

File hashes

Hashes for fabricatio_diff-0.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ab090515432952d7308dda76399dfcae386dd0a64bbb1d8642ddac7110d1aecc
MD5 071dfe1d0c14b056ae3f567ec7425f09
BLAKE2b-256 eacb0dc8591451deea02726eafa250ceb101b1c37e8f7a1ba00c60eea65739cc

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