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

ocdiff-0.0.33-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (305.5 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

ocdiff-0.0.33-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (307.6 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

ocdiff-0.0.33-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (326.2 kB view details)

Uploaded CPython 3.13 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ocdiff-0.0.33-cp313-cp313-macosx_11_0_arm64.whl (266.0 kB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

ocdiff-0.0.33-cp313-cp313-macosx_10_13_x86_64.whl (276.7 kB view details)

Uploaded CPython 3.13 macOS 10.13+ x86-64

ocdiff-0.0.33-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (305.6 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ocdiff-0.0.33-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (307.7 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

ocdiff-0.0.33-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (326.5 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ocdiff-0.0.33-cp312-cp312-macosx_11_0_arm64.whl (266.4 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ocdiff-0.0.33-cp312-cp312-macosx_10_13_x86_64.whl (276.7 kB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

ocdiff-0.0.33-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (305.9 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ocdiff-0.0.33-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (307.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

ocdiff-0.0.33-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (326.9 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

ocdiff-0.0.33-cp311-cp311-macosx_11_0_arm64.whl (266.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ocdiff-0.0.33-cp311-cp311-macosx_10_9_x86_64.whl (277.2 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

File details

Details for the file ocdiff-0.0.33-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6a8a58199971876da7a650d916726d5a2dcc7bcdb83de59533c82e095a89838b
MD5 2ee033a5d8d6a902a0ea9c971e24f9e3
BLAKE2b-256 9540a36a58f354352c11550a457bd5e8367398ad21c8359d50ff22c038292734

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 59bff364c1ebe7324d9c144b0f938ac5406f111cec07dc4d384e30063b9fdc66
MD5 9b73170bbc6d50aede1809613b5f177f
BLAKE2b-256 36d0790527729a6a0ecf0c2e3eb700ff1e0f953536535044e1f3561fbfd90cc2

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ec8763049d63a54975374b90c7e61e680cdb07d0d6a0aa97b3a7215d280c7c6d
MD5 1ddfda2e828b0a84af21fb08c44252ad
BLAKE2b-256 9390c1aec8dd316c30dde196401c6f1db02730d86144db99cfee670f35299ed9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e57a74dcb2e75076c7fd3d3bf6b335a4103e61bd6d40c229f6a8c36bb4b3f1a
MD5 45e90531f95ee1bd0969949a11bb0e44
BLAKE2b-256 174e611cd49a3ee7630597e1fac226322a3d2079042316468e64056eb239884e

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 4b9f5b040334780553636324fc565a801a2d59449f37533f7e57061d9c3b920d
MD5 ecacdcd250890b27349e86ef7f7dd28a
BLAKE2b-256 ac3803320fd4f8dd7b1a6d24c0570fa637f4844f59f821da5c683539c71f729e

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 981508b959e587a8355187a95eb2a40cdf9a7874eac066595e51e12f41e3c480
MD5 040984eb5c63b513181745066e7bb198
BLAKE2b-256 82601feee8e634fda2fbd5a96c9f86c2621100cc09f840f70128e3f48ff2bbee

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 66cbf61272982c8236ee5cf1ae2dc0deb4ec47358c01e271e234fd9d2e9bf4bf
MD5 9d7e234888b26855f04b7da2c4522f14
BLAKE2b-256 364bb3246bf91ec73ac80d6488168d22a9a0a06a787f5345800c89e961b7344f

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 a363d0763655756855e3e4ca7d76ce393f2c14708c6b9d43725bc890d0190145
MD5 02c284d6d4105f864b0be7430e8fcdf2
BLAKE2b-256 886bb5a729c67936dbe40f6f2a1b0b091b54f4621c8a451b1e785b33223af2c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3a18e63564442059fbf8c8ee6692b655cbc0a7ab9d757cf937daddb2769f483
MD5 2232493a80423f0502c6c2809002fd3b
BLAKE2b-256 dbf9c288de4e1da404966fd9a0187913ceecb6a4d9925841b7a1dfd944c13e88

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 5f7c3f36c94a1894f9bccd74afbaa980e4cebd48cb30e70fe137675dcd8d8400
MD5 7aaa8521d0453c318acb32e8465e85fd
BLAKE2b-256 bbab3433d2bcf3a8de8b44d3ea19b157deb1939fe69c2e14fcc58f082e68611d

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc36534101f0940438fcdc6065b77aae04642a98d46965455ca3ebdf67fef08c
MD5 42372562ba07c6a003fcb63302e9c92d
BLAKE2b-256 5deb78b30ccad4a8141f085f5fe8a69344892f90fbc6374badb45006e49dacc8

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8d3e13f062aa7d07f7804fbe0bb3fb1147263ba6127e5c92986e46a6357a6079
MD5 dd82574dd0e89928d0742dc2bb4c17db
BLAKE2b-256 14fc3ee1ba953149a68a77df6603660dd9eef82946968d75eebbbf1b91254833

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 52c9b428cf025e5409cd52732d229642989f51e074e4cc87d4a8f2c4b3cac774
MD5 ba857d6459e4219861b39dd1b4874b3f
BLAKE2b-256 e65fa900ba02f5958f990b722b2e4f40c30a522d538a8fe90cf2016a8025cd45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 441a4e82c1085c9a82f0b76d11dd7d9f9dc5c823d1881fcf01011c98a562f120
MD5 ebe78f9be295dd74d5a1d402ae07d8db
BLAKE2b-256 3402e1421824f9468bc8aa169df6fd30b0b56063759bc53de3f213815f203e6f

See more details on using hashes here.

File details

Details for the file ocdiff-0.0.33-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for ocdiff-0.0.33-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 80449d6c26df6049a272bbd2f2f7f996c427b042c278649f750a875764b3fbce
MD5 5b46c2a63feda93704f5d11503f72725
BLAKE2b-256 d4f3a6c3bf14c2e7228d279c474cad5357fc8999e7746800833c53300a51c8db

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page