Skip to main content

difftastic Python wrapper

Project description

ocdiff

Fast and simple side-by-side diff library for Python - wraps similar, inspired by icdiff.

Usage

pip install ocdiff
ocdiff.html_diff(
    a: str,
    b: str,
    context_lines: int | None = None,
    max_total_width: int | None = None,
) -> str
ocdiff.console_diff(
    a: str,
    b: str,
    context_lines: int | None = None,
    max_total_width: int | None = None,
) -> str

Example Output

Screenshot

CLI usage

ocdiff a.txt b.txt

Usage in pytest with rich

In your conftest.py, add:

import ocdiff
import ocdiff.helpers
import rich.console

def rich_repr(o: Any) -> str:
    string_io = io.StringIO()
    rich.console.Console(
        file=string_io,
        width=ocdiff.helpers.terminal_width() // 2 - 10,
        tab_size=4,
        no_color=True,
        highlight=False,
        log_time=False,
        log_path=False,
    ).print(o)
    string_io.seek(0)
    return string_io.getvalue()


def pytest_assertrepr_compare(config: Any, op: str, left: Any, right: Any) -> list[str] | None:
    very_verbose = config.option.verbose >= 2
    if not very_verbose:
        return None

    if op != "==":
        return None

    try:
        if abs(left + right) < 100:
            return None
    except TypeError:
        pass

    try:
        if isinstance(left, str) and isinstance(right, str):
            pretty_left = left
            pretty_right = right
        else:
            pretty_left = rich_repr(left)
            pretty_right = rich_repr(right)
        return ocdiff.console_diff(
            pretty_left,
            pretty_right,
            context_lines=10,
            max_total_width=ocdiff.helpers.terminal_width() - len("E     "),
        ).splitlines()
    except Exception:
        return None



Install/Develop

uv pip install -e '.[dev]'
maturin develop

Make release

  • Add pypi token and user = __token__ to settings (do this once).
  • Upversion pyproject.toml.
export VERSION=$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])'); git tag -a v$VERSION head -m v$VERSION && git push origin v$VERSION

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.

ocdiff-0.0.42-cp314-cp314-manylinux_2_28_x86_64.whl (275.6 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

ocdiff-0.0.42-cp314-cp314-manylinux_2_28_aarch64.whl (258.2 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ ARM64

ocdiff-0.0.42-cp314-cp314-macosx_11_0_arm64.whl (239.5 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ocdiff-0.0.42-cp313-cp313-manylinux_2_28_x86_64.whl (275.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

ocdiff-0.0.42-cp313-cp313-manylinux_2_28_aarch64.whl (257.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

ocdiff-0.0.42-cp313-cp313-macosx_11_0_arm64.whl (239.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ocdiff-0.0.42-cp312-cp312-manylinux_2_28_x86_64.whl (275.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

ocdiff-0.0.42-cp312-cp312-manylinux_2_28_aarch64.whl (258.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

ocdiff-0.0.42-cp312-cp312-macosx_11_0_arm64.whl (239.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ocdiff-0.0.42-cp311-cp311-manylinux_2_28_x86_64.whl (277.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

ocdiff-0.0.42-cp311-cp311-manylinux_2_28_aarch64.whl (259.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

ocdiff-0.0.42-cp311-cp311-macosx_11_0_arm64.whl (240.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file ocdiff-0.0.42-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7f9ad41507953cd8695b0a15321957a2e3074cb6247d1a6d78f2a710995eb39a
MD5 d1b7acb4b91a74db487e68695ffce252
BLAKE2b-256 2d501ad6edde498b2bfb47436737c0a2b23b01653d88345f9cbb30f5b8327399

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp314-cp314-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp314-cp314-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 116899e3a952796429855d90899eb41737b0a3feaf542da6ab2d4ea3cefcf1b5
MD5 663d631772c247f1aa91a3d447124e7d
BLAKE2b-256 f212c54a24a5af605b31f401317dd8204a8e6e09435b39995557abbadced96e3

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 86ef1049fca390e15278804258b71e86e8120d794d65ba831ece09cb5848d6b8
MD5 cc5612d202cb323cc4c5d486d7b595de
BLAKE2b-256 11e618fca3867d61cf807b66e108fc52c835c9593258cf05b3f7408c75d0e8b0

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 890ef6ad76d5d4bb51e728a5b652d25aee29faa7f83d27c710044733fd1892d2
MD5 51a1f4c44c45c7bc64d5b33724f369bc
BLAKE2b-256 78f5f154bc164f6f140e386534689e73ee19f31dca8ba8154c0f1a8f6847340e

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 71b870e7bc3f22ebb750d0e5aa6f67fb5bdd0c3105fec559c2137a78b4966acc
MD5 5211cbb4c9c399335fdaad9e613aa286
BLAKE2b-256 4e33d0c82d76694d4cccd4384481c410973b2cbaf8c4415a610a95c37e588d1f

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8d5c0f5591291538c7e2c863024fc7086a0df3ac2b8a475e3384789922f0580
MD5 a5d42635a2661c5b5a39b1a79e8afabe
BLAKE2b-256 b512026a832d4853143209dbbdde291417a9d1a1c1c24d046e414a57667da512

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 97e09092f3fde6a001fd829ff15d0803857f9e63cad86ff41584877b8e7f8267
MD5 75de5cdd9e4640c119b4502dead366ff
BLAKE2b-256 55205726fbed2f0ce468539d9fb6517a36bdbcd0c6461b6d49afe144eddda6c9

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 016f6137039ff727621e2ab2b85c5a3f9bafd19481b4587df8f6d919a7623c43
MD5 d71c2ac51376cc00394402a969c5e1bc
BLAKE2b-256 9795abcc8d09cb50dacd271aa5074a19a86b4c06450d4ccc41a007797df2687b

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 da5e72723d640d274b8de1895e8d82f748703cacade498da1c56ff7d38bfa067
MD5 2069738a11ad4b543b44b75be1f1b982
BLAKE2b-256 9423c3685f23c8dd96d0103143736c6d10647330cfb6ab88f7ac655e13fdef34

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b6d235c12c91629d197afa104c2fee1de6be4f1c658932c3c09ee7592720acc4
MD5 ea7c4c6c280bd932bf70469c35aec02a
BLAKE2b-256 4e38eed5edcaf33415fc6553e6574d90003e54464c178137fcdc005c37766a65

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2c3282d2755221c3b790cacbb9c319419ae258191a4b488bbea83e0f3ceb3b5f
MD5 8d1742c9b497f08959c88c1453d87985
BLAKE2b-256 a8818c1759a28331c65d94534da164f972bc16f794337059ac7c8fb02c63285b

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.42-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.42-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 930c956b0549cd65a0cce81b16dc545d73b4a299a5550faf9b47efc460c9e635
MD5 38d18e1aad2b488c4e45fee1298b0cd2
BLAKE2b-256 2b4a830666a07da7214046258dace6d04a2afeddcb15b21e55280f7f7df73306

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