An open API service indexing awesome lists of open source software.

https://github.com/coldbricks/hearback

Listener-side output re-validation decorator against schema/predicate.
https://github.com/coldbricks/hearback

coldbricks decorator output-validation pypi python typed validation zero-dependency

Last synced: 14 days ago
JSON representation

Listener-side output re-validation decorator against schema/predicate.

Awesome Lists containing this project

README

          

# hearback

[![PyPI](https://img.shields.io/pypi/v/hearback.svg)](https://pypi.org/project/hearback/)
[![Python Versions](https://img.shields.io/pypi/pyversions/hearback.svg)](https://pypi.org/project/hearback/)
[![CI](https://github.com/coldbricks/hearback/actions/workflows/ci.yml/badge.svg)](https://github.com/coldbricks/hearback/actions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

Listener-side counterpart to echo-confirmation: a decorator that re-validates function outputs against a schema or predicate before they leave the call boundary.

## Install

```bash
pip install hearback
```

## Quickstart

```python
from hearback import hearback, HearbackError

@hearback(lambda n: isinstance(n, int) and n >= 0)
def absolute_delta(a, b):
return abs(a - b)

assert absolute_delta(3, 10) == 7

@hearback(str)
def label(x):
return x

assert label("ok") == "ok"
try:
label(123)
except HearbackError:
pass
```

## Why this exists

- Enforce output contracts at the function boundary
- Accept a callable predicate or a type / tuple of types
- Surface failures as `HearbackError` with the bad value

## API

| Symbol | Description |
|--------|-------------|
| `hearback(predicate)` | Decorator; predicate is callable or type |
| `HearbackError` | Raised when output fails re-validation |

## Related packages

Part of the coldbricks micro-library suite (small, typed, zero-dependency helpers):

| Package | Role |
|---------|------|
| [`buzzkill`](https://github.com/coldbricks/buzzkill) | Guaranteed shutdown callbacks |
| [`aftercare`](https://github.com/coldbricks/aftercare) | Reverse-order teardown |
| [`fluffer`](https://github.com/coldbricks/fluffer) | Startup pre-warm |
| [`edging`](https://github.com/coldbricks/edging) | Token-bucket rate limit |
| [`readback`](https://github.com/coldbricks/readback) | Echo-confirmation validation |
| **hearback** | Output re-validation decorator |
| [`agecheck`](https://github.com/coldbricks/agecheck) | Timezone-correct age thresholds |
| [`transponder`](https://github.com/coldbricks/transponder) | State broadcast on change |

## Development

```bash
pip install -e ".[dev]"
pytest -q
ruff check .
mypy src
```

## Roadmap

This is an early **0.1.0** release (Alpha) with active development planned:

- JSON Schema / pydantic integration
- Async function support
- Structured advisory payloads on failure

## License

MIT © Coldbricks — coldbricks@gmail.com