Skip to main content

Python implementation of VS Code's diff algorithm

Project description

vscodiff

Python implementation of VS Code's diff algorithm, referenced from the VS Code source code.

Features

  • Myers diff algorithm (O(ND) difference)
  • Line-level diff with subword refinement
  • Timeout-aware computation (set max time per diff)
  • LRU cache for repeated diff requests
  • Move detection support
  • Type-safe — fully typed with py.typed marker

Installation

Recommended — with uv:

uv add vscodiff

Alternative — with pip:

pip install vscodiff

Requires Python ≥ 3.12.

Quick Start

from vscodiff import VSCDiff, DiffOptions

diff = VSCDiff()

# Compute diff between two strings
result = diff.compute_diff("hello\nworld", "hello\nthere\nworld")

for change in result.changes:
    print(f"  original lines {change.original}: {change.inner_changes}")

API

VSCDiff

Main diff entry point. Configure with VSCDiffOptions:

from vscodiff import VSCDiff, VSCDiffOptions, DiffOptions

options = VSCDiffOptions(
    diff_options=DiffOptions(
        ignore_trim_whitespace=True,
        max_computation_time_ms=1000,
        compute_moves=False,
        diff_algorithm="advanced",
    ),
    cache_size=100,
)
diff = VSCDiff(options)
result = diff.compute_diff(original_text, modified_text)

Key Types

Type Description
VSCDiff Main diff engine
DocumentDiff Result: identical, quit_early, changes, moves
DetailedLineRangeMapping A changed line range with inner char-level diffs
RangeMapping Character-level diff range
LinesDiff Raw line diff output (changes + moves + timeout)

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

vscodiff-0.1.0.tar.gz (57.1 kB view details)

Uploaded Source

Built Distribution

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

vscodiff-0.1.0-py3-none-any.whl (53.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for vscodiff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9fb5d68a81c7b470057946d13445126197ef0c7f3f1dd84670a7d661fa205a5a
MD5 272fb394dd21816dfa7acbe2c0bb61d8
BLAKE2b-256 62562bd0964577f95a0eb0e888fd901f48354bbf9c5dffb2bd75979a5bcc2910

See more details on using hashes here.

Provenance

The following attestation bundles were made for vscodiff-0.1.0.tar.gz:

Publisher: cd.yml on meymchen/vscodiff

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

File details

Details for the file vscodiff-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vscodiff-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 53.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vscodiff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58b1c0e42e1c9e0c99201e2bfa726e265468958e3dd1cf81fe05bdd1e9edadfd
MD5 395ea69d7289639bf4005427b7c74692
BLAKE2b-256 42ea84d105fb60d034506aaf176a13bbf18e779bba63618f598a88f96bf0894d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vscodiff-0.1.0-py3-none-any.whl:

Publisher: cd.yml on meymchen/vscodiff

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