skillfed

anys

Matchers for pytest

anys v0.3.1 953.6K downloads/30d#4,650 on PyPI26
Permissive license MIT Active released

What it is and what it does

anys is a testing utility that provides matcher objects for writing more flexible assertions in unit tests. Instead of comparing exact values, matchers let you assert that a value meets a criterion—such as being a valid ISO 8601 datetime string, falling within a numeric range, matching a regex pattern, or having specific attributes. This is especially useful when testing code that produces values you can't predict in advance (like timestamps or generated IDs) but still need to validate.

The package exports pre-built matchers for common types (ANY_INT, ANY_STR, ANY_DATETIME_STR, etc.) and composable matcher classes (AnyGT, AnyMatch, AnyWithAttrs, etc.) that you combine with standard Python equality comparisons. Matchers can be nested in dictionaries, lists, and other structures, and combined using & (both must match) and | (either may match) operators. It has no runtime dependencies and supports Python 3.8 through 3.13 on both CPython and PyPy.

Use it for:

  • Assert that API responses contain valid timestamps or UUIDs without hardcoding exact values.
  • Validate nested data structures where some fields are dynamic but must meet type or pattern constraints.
  • Check that function return values fall within expected numeric ranges without manual boundary comparisons.
  • Test objects with attributes that vary between runs (e.g., creation times) while verifying other fields exactly.
  • Combine multiple criteria to match complex values—e.g., strings matching a regex AND containing a substring.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides matcher objects that compare equal to values meeting specified criteria, enabling flexible assertions in pytest-style unit tests without manual field-by-field comparison.

Yes. This is a lightweight, well-maintained testing utility with no dependencies, permissive licensing, and active development. It solves a real problem in unit testing—validating dynamic or partially-known values—and integrates seamlessly with pytest assertions. The API is straightforward, and the matcher composition model is flexible. Install it if you write tests with pytest and encounter fields you can't assert exactly.

Install

anys on PyPI

pip

pip install anys

uv

uv add anys

poetry

poetry add anys

Installing anys

Before you install

Low friction installation with no runtime dependencies. Actively maintained with recent commits; last release was 2024-12-01, and the repository shows ongoing activity.

License in practice

MIT license is permissive; you can use, modify, and distribute this package with minimal restrictions, making it safe for both open-source and commercial projects.

Quickstart

from anys import ANY_DATETIME_STR, AnyGT

assert response == {
    "status": "ok",
    "timestamp": ANY_DATETIME_STR,
    "count": AnyGT(0)
}

Requires Python 3.8 or higher.

Verify before relying

  • Whether matchers work correctly when nested in custom class instances with non-standard __eq__ implementations.
  • Performance characteristics when combining many matchers with & and | operators on large data structures.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 621 days since the last release
Last repo commit
First released
Downloads 953,611/month — #4,650 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: anys-0.3.1-py3-none-any.whl

Keywords: comparison, matchers, pytest, testing, unit test

Intended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: TestingTopic :: Software Development :: Testing :: UnitTyping :: Typed

Tags

pytest assertion matchersflexible test comparisonsdynamic value matchingunit test helperspattern-based assertionsconditional equality checkstest fixture validation
pytesttest-utilitiesassertion-helpers

More Testing packages