skillfed

ensure

Literate BDD assertions in Python with no magic

ensure v1.0.4 863.4K downloads/30d#4,868 on PyPI157
Permissive license Apache Software License DORMANT released

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 ensure

uv

uv add ensure

poetry

poetry add ensure

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: MacOS :: MacOS XOperating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

readable assertions pythonliterate bdd assertionsvalidation helpers pythonexpressive condition checkingassertion library no magicruntime type validationchainable assertions
assertion-libraryvalidationbdd

More Python Modules packages