{"id":2471,"library":"dirty-equals","title":"Dirty Equals","description":"dirty-equals is a Python library for doing 'dirty' (but useful) things with equality comparisons. It allows for flexible assertions in tests and other contexts, such as comparing values against types, regular expressions, or fuzzy time ranges. The current version is 0.11.0, and the library maintains an active release cadence, with major updates typically every few months.","status":"active","version":"0.11.0","language":"en","source_language":"en","source_url":"https://github.com/samuelcolvin/dirty-equals","tags":["testing","comparison","utility","assertion","equals"],"install":[{"cmd":"pip install dirty-equals","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for specific dirty-equals validators like IsUrl, IsEmail, IsUUID, etc.","package":"pydantic","optional":true}],"imports":[{"symbol":"IsInt","correct":"from dirty_equals import IsInt"},{"symbol":"IsStr","correct":"from dirty_equals import IsStr"},{"symbol":"IsNow","correct":"from dirty_equals import IsNow"},{"symbol":"IsListOrTuple","correct":"from dirty_equals import IsListOrTuple"},{"symbol":"IsUrl","correct":"from dirty_equals import IsUrl"}],"quickstart":{"code":"from datetime import datetime\nfrom dirty_equals import IsInt, IsStr, IsNow, IsListOrTuple\n\n# Basic type checking\nassert 123 == IsInt()\nassert \"hello\" == IsStr()\n\n# Fuzzy time comparison (matches if within a reasonable delta)\nnow_time = datetime.now()\n# The library internally compares against datetime.now() at the moment of assertion.\n# The assertion will pass if now_time is approximately equal to the current time.\nassert now_time == IsNow()\n\n# Asserting content and types within collections\nassert [1, \"two\", 3] == IsListOrTuple(IsInt(), IsStr(), IsInt())\n\nprint(\"Dirty equals assertions successful!\")","lang":"python","description":"Demonstrates basic usage of dirty-equals for type checking, fuzzy time comparisons, and asserting elements within collections. The `IsNow()` helper provides a flexible way to compare datetimes without needing an exact match, useful in tests."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher if you need to use dirty-equals 0.10.0+.","message":"Python 3.8 support was dropped in version 0.10.0. dirty-equals now requires Python 3.9 or newer.","severity":"breaking","affected_versions":">=0.10.0"},{"fix":"Use version 0.7.1 or later instead of 0.7.0.","message":"The v0.7.0 release was announced but never published to PyPI. Users attempting to install or reference v0.7.0 will fail. The intended changes were included in v0.7.1.","severity":"gotcha","affected_versions":"0.7.0"},{"fix":"Understand that `IsNow()` is dynamic. If you need to compare against a specific historical timestamp, you might need a different approach or to capture `datetime.now()` precisely when creating your expected value.","message":"`IsNow` compares against the *current* moment of time when the assertion runs, not against a specific pre-defined timestamp. This is suitable for fuzzy time comparisons but not for exact matches against a fixed reference.","severity":"gotcha","affected_versions":"<0.5.0 had different behavior, >=0.5.0 has current behavior"},{"fix":"Ensure you are using dirty-equals v0.11.0 or newer when comparing nested dataclass objects to avoid subtle comparison bugs.","message":"Comparison of nested dataclasses was fixed in version 0.11.0. Older versions might exhibit unexpected behavior or failures when comparing complex nested dataclass structures.","severity":"gotcha","affected_versions":"<0.11.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}