ensure
Literate BDD assertions in Python with no magic
What it is and what it does
ensure is a standalone assertion library that lets you write validation checks using a fluent, readable API inspired by JavaScript testing frameworks. Instead of cryptic assert statements or unittest methods, you chain readable clauses like `.is_an(int)`, `.contains()`, and `.has_key()` to express what you expect. The library raises informative EnsureError exceptions with clear messages when checks fail, making it useful for both test code and production validation (e.g., API input checking).
The package depends only on six and installs as a pure Python wheel. It supports Python 3.6 through 3.11 and includes a decorator, @ensure_annotations, for enforcing function signature type hints at runtime. Because ensure doesn't use the assert statement (which can be disabled with Python's -O flag), validations remain active in optimized production deployments.
Use it for:
- Validate API request parameters with readable error messages for client feedback.
- Write BDD-style test assertions that read like English sentences.
- Enforce function argument types at runtime using @ensure_annotations decorator.
- Chain multiple conditions on complex data structures (dicts, lists, sets) with fluent syntax.
- Validate data structure shape and contents in production code without test framework overhead.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ensure provides literate assertion helpers for validating conditions in Python with readable error messages, usable in both tests and production code without relying on the assert statement.
Yes, if you want readable assertions in tests or production validation. The library is stable, has no known vulnerabilities, and adds minimal install friction. The dormant maintenance (no updates since late 2023) is a minor concern but not a blocker—the API is mature and the codebase is simple. Suitable for projects prioritizing readable validation code over framework integration.
Install
ensure on PyPI
pip
pip install ensureuv
uv add ensurepoetry
poetry add ensureInstalling ensure
Before you install
Low friction install with a single lightweight dependency (six). Dormant maintenance status since late 2023, though the repository remains active and the package is marked Production/Stable.
License in practice
Licensed under Apache Software License (permissive), allowing use in commercial and proprietary projects with minimal restrictions.
Quickstart
pip install ensure
from ensure import ensure
ensure(1).is_an(int)
ensure({1: 2}).has_key(1).whose_value.equals(2)
ensure([1, 2, 3]).is_sorted()
Requires Python 3.6 or later; function annotation enforcement via @ensure_annotations decorator requires Python 3.
Verify before relying
- Whether dormant maintenance status affects real-world reliability or compatibility with current Python versions beyond 3.11.
- Performance characteristics compared to other assertion libraries in production validation scenarios.
Package facts
| License | Apache Software License (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — six |
| Maintenance | dormant — 978 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 863,431/month — #4,868 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: ensure-1.0.4-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
suresure provides fluent, chainable assertion…
copyleft · top 15,000 on PyPI
assertpyProvides a fluent assertion API for writing…
permissive · top 5,000 on PyPI
expectsExpects is an assertion library for TDD/BDD…
permissive · top 15,000 on PyPI
surerSurer provides fluent, RSpec-inspired assertion…
permissive · top 15,000 on PyPI
assertsProvides stand-alone assertion functions for…
unclear · top 15,000 on PyPI
re-assertProvides a helper class for regex assertions…
permissive · top 15,000 on PyPI
robotframework-assertion-engineProvides a standardized assertion engine for…
permissive · top 15,000 on PyPI
pytest-assumeA pytest plugin that collects and reports…
permissive · top 15,000 on PyPI
delayed-assertCollects multiple assertion failures in a test…
unclear · top 15,000 on PyPI
PyHamcrestPyHamcrest provides a framework for writing…
permissive · top 5,000 on PyPI