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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ocdiff-0.0.43-cp314-cp314-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp314-cp314-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 275.7 kB
- Tags: CPython 3.14, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f265ef09075d4320b82f4ebb4ce4a41e5d9f317e3e3c34d77b81a98c651f91ba
|
|
| MD5 |
ce9ef29b947d756a52aaf91af3dd3400
|
|
| BLAKE2b-256 |
992aa3a2c38dbfc7faea093360e3d848bb4558dd09cd509dbcd4af70e863041e
|
File details
Details for the file ocdiff-0.0.43-cp314-cp314-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp314-cp314-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 258.3 kB
- Tags: CPython 3.14, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
009f63a5c026ead87b0ae8acd676738065847379fe8190e243081df145cc0253
|
|
| MD5 |
3e76f60b6a822856206adbb566896efd
|
|
| BLAKE2b-256 |
1c096d864b810ab36c91c16ff10ead4fbb0543bb528e042f573742e2381bea17
|
File details
Details for the file ocdiff-0.0.43-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 239.5 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5184de1106076caf33c1021972a1ce491f43e041007140639b744ac36630ba2f
|
|
| MD5 |
7e9a3c5d6d648483a05b11bcfce2e8e1
|
|
| BLAKE2b-256 |
2b7e3fed88bf6acd7345a9d24b1ba2c6229de8e22a316b86271eab64ecb475eb
|
File details
Details for the file ocdiff-0.0.43-cp313-cp313-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp313-cp313-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 275.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dc2ef56752b8ae0c761a77d075bcadc2996f111c2aac4132d58518e852ba62e
|
|
| MD5 |
e359d289513dcd66d37d552f11c1e7cf
|
|
| BLAKE2b-256 |
5352daec39130c8023f8d17f8f71479074546550ebe2b25b854d7283db93d68c
|
File details
Details for the file ocdiff-0.0.43-cp313-cp313-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp313-cp313-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 258.0 kB
- Tags: CPython 3.13, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99cbd3c9768e6a94c2da26a15b620a6da0cbaa42504de5c716884761c532a7c9
|
|
| MD5 |
2c6a4f22ceb2fd84ebd8199a6c6f575d
|
|
| BLAKE2b-256 |
4d7d120c1ba53fce166b820817c44f023153c973a0b763875a8fa29826948727
|
File details
Details for the file ocdiff-0.0.43-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 239.3 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cfc2e355b53f0fc3917b83efcda7c7e81ff36884c69dd20d29a12011f844620
|
|
| MD5 |
0f12a12e594376b68e68572796b85af8
|
|
| BLAKE2b-256 |
96d9b2fbd5592a5d6895c4a6556763ed61927667cc86f32975ada6f28ef0ee29
|
File details
Details for the file ocdiff-0.0.43-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 276.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98746e9ef76fabbce96cc93fdb5e36201f0d183d5cf774bec2197aa91b4cfc3b
|
|
| MD5 |
2c18ed83523b21d28712bc8a311773a5
|
|
| BLAKE2b-256 |
13381f1ed6d37cc71e5a1e290ed2b189119fb3b8c38ecc5b2dbbb1c080ae7a71
|
File details
Details for the file ocdiff-0.0.43-cp312-cp312-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp312-cp312-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 258.0 kB
- Tags: CPython 3.12, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
753c1e2243ec25162cebce3114bcb93503b90ee6fe9c451f37fc86b4851c810a
|
|
| MD5 |
fdf1678bd16682ee83d24ce504670cd6
|
|
| BLAKE2b-256 |
8a6a7c95b2bf3aa0341e4ec21719eb8cb0f3a37bfe7284d831b31188e3a826f2
|
File details
Details for the file ocdiff-0.0.43-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 239.3 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a351abe2c36c0cbed861199b52c1566af13dac351e8d479aad374f232887b0
|
|
| MD5 |
de88ab5d15ef6f8519f2442e7f0c179b
|
|
| BLAKE2b-256 |
e2909c3e60e427af99d1a1350b87abb97d47ef4339f7fc37a9b28188e6a19f7c
|
File details
Details for the file ocdiff-0.0.43-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 277.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b54dd3b9cd878f258b611f853f6972894245343ea178c90d3b513e3d9f92beee
|
|
| MD5 |
ab44f8e313340d30eed70fce2e61885e
|
|
| BLAKE2b-256 |
81160a429cbfa1cdf74171cde80396cc13842b01a0e427b86cca8af2a1a341d9
|
File details
Details for the file ocdiff-0.0.43-cp311-cp311-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp311-cp311-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 259.8 kB
- Tags: CPython 3.11, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff7ccf1c359b603a791bbbe39d22729a67843025b52f0de132b3ba5b9867c925
|
|
| MD5 |
8101084953f0e7b32c219cdb21eed065
|
|
| BLAKE2b-256 |
aae281d72e75541e8139a4966c89ead978a81e9f3dd9a18df5bf48e256cfff13
|
File details
Details for the file ocdiff-0.0.43-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: ocdiff-0.0.43-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 240.4 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c200ac47e261ebed2fb4336ca4712c381bb07cca23dfacb9df9918cb8ec7ab1
|
|
| MD5 |
7d9ab364c0cf85794685d6333bf85f87
|
|
| BLAKE2b-256 |
5fc308251f4a2ed109d010edcc36b2f434d046bd3a5cc18d61a4ece5a72f54f6
|