anys
Matchers for pytest
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 anysuv
uv add anyspoetry
poetry add anysInstalling 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
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
PyHamcrestPyHamcrest provides a framework for writing…
permissive · top 5,000 on PyPI
calleeProvides argument matchers for unittest.mock…
permissive · top 15,000 on PyPI
re-assertProvides a helper class for regex assertions…
permissive · top 15,000 on PyPI
pytest-unorderedProvides a pytest assertion helper to compare…
permissive · top 5,000 on PyPI
libsastlibsast is a static application security…
copyleft · top 15,000 on PyPI
pampyPampy provides pattern matching for Python,…
permissive · top 15,000 on PyPI
dirty-equalsProvides custom equality matchers that make…
permissive · top 5,000 on PyPI
robotframework-assertion-engineProvides a standardized assertion engine for…
permissive · top 15,000 on PyPI
pytest-clarityA pytest plugin that displays colored,…
permissive · top 15,000 on PyPI
expectsExpects is an assertion library for TDD/BDD…
permissive · top 15,000 on PyPI