{"id":2594,"library":"moreorless","title":"moreorless: Python Diff Wrapper","description":"Moreorless is a thin Python wrapper around `difflib.unified_diff` designed to simplify its usage and address common edge cases, such as the \"No newline at eof\" issue. It provides a more user-friendly interface for generating unified diffs, applying patches, and producing colorized diff output. The current version is 0.5.0, with an irregular release cadence based on contributions and feature enhancements.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/thatch/moreorless/","tags":["diff","text comparison","unified diff","patch","difflib","cli"],"install":[{"cmd":"pip install moreorless","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for command-line utilities and colorized diff output.","package":"click","optional":false}],"imports":[{"symbol":"unified_diff","correct":"from moreorless import unified_diff"},{"symbol":"apply_single_file","correct":"from moreorless.patch import apply_single_file"},{"note":"Colorized output functions are in the 'click' submodule.","wrong":"from moreorless import echo_color_unified_diff","symbol":"echo_color_unified_diff","correct":"from moreorless.click import echo_color_unified_diff"},{"symbol":"combined_diff","correct":"from moreorless.combined import combined_diff"}],"quickstart":{"code":"from moreorless import unified_diff\nfrom moreorless.click import echo_color_unified_diff\n\nold_text = \"\"\"Line 1\\nLine 2\\nLine 3 - original\\nLine 4\\n\"\"\"\nnew_text = \"\"\"Line 1\\nLine 2 - modified\\nLine 3 - changed\\nLine 5 - new\\n\"\"\"\n\n# Get a raw unified diff string\ndiff_string = unified_diff(old_text, new_text, 'old_file.txt', 'new_file.txt')\nprint(\"\\n--- Raw Unified Diff ---\")\nprint(diff_string)\n\n# Or print a colorized diff directly to stdout (requires 'click' package)\nprint(\"\\n--- Colorized Diff (using click) ---\")\necho_color_unified_diff(old_text, new_text, 'old_file.txt', 'new_file.txt')","lang":"python","description":"This example demonstrates how to generate a raw unified diff string using `unified_diff` and how to print a colorized diff to the console using `echo_color_unified_diff`. The `filename` arguments are used in the diff header."},"warnings":[{"fix":"Consult Python's `difflib` documentation for advanced use cases or deep customization.","message":"While `moreorless` simplifies `difflib.unified_diff`, it is still a wrapper. For highly complex or performance-critical diffing scenarios, understanding the underlying `difflib` module might be beneficial.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your terminal supports ANSI escape codes for colorized output. If you only need the diff string, use `unified_diff` directly which does not involve `click`'s output formatting.","message":"The `echo_color_unified_diff` function (and other color-related utilities) internally uses the `click` library for terminal output. While `click` is a required dependency, users unfamiliar with `click` might find the integration surprising or encounter issues if their terminal environment doesn't support ANSI escape codes.","severity":"gotcha","affected_versions":"All"},{"fix":"Consider contributing to the project or opening issues for bugs/feature requests to help drive development. For enterprise-grade needs, evaluate its fit carefully.","message":"The `moreorless` library is relatively small with limited community contributions (few stars, forks). While actively maintained by the author, major feature additions or rapid bug fixes might not occur as quickly as with larger, more widely adopted libraries.","severity":"deprecated","affected_versions":"All"},{"fix":"Upgrade to `moreorless>=0.5.0` to use the combined diff feature.","message":"The `combined_diff` functionality was introduced in version `0.5.0`. Attempts to use `moreorless.combined.combined_diff` in versions prior to `0.5.0` will result in an `ImportError` or `AttributeError`.","severity":"breaking","affected_versions":"<0.5.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}