Skip to main content

behave-data

PyPI Python Tests Docs Coverage License

Data management for Behave — typed tables, diffs, dynamic examples, fixtures, and secrets with zero boilerplate.

Built on top of behave-tables.

Full documentation: mathiaspaulenko.github.io/behave-data


Why?

Behave data tables are strings. Everything is "42", "true", "". You write boilerplate in environment.py to convert types, handle nulls, load examples, and manage test data.

behave-data fixes this:

Without behave-data With behave-data
row["age"] → "42" (string) row["age"] → 42 (int)
Empty cell → "" Empty cell → None
Hardcoded Examples in .feature Load from CSV, JSON, YAML, Excel, SQL, HTTP
Manual before_all / after_scenario @needs_data, @with_fixture, @cleanup_after tags
Secrets in feature files env:VAR, file:path, secret:name with masking

Features

  • Typed Tables — name:str, age:int, active:bool, price:float, created:date with automatic conversion
  • Null Resolution — Empty cells become None, configurable markers ("", "null", "N/A"), per-column overrides
  • Table Diff — Cucumber-style diff output with row/column mismatch detection
  • Raw Tables — Access tables without header assumption, vertical tables, transposed data
  • Dynamic Examples — @load_examples:csv:users.csv replaces static Examples blocks; named data_sources for URLs, SQL, nested paths
  • Fixtures — Reusable data recipes with nesting (ref:other) and parametrization
  • Builders — Construct test data with derived fields and overrides
  • Secrets — env:, file:, secret: placeholders with Vault and AWS backends, automatic masking
  • Declarative Tags — @needs_data, @with_fixture, @cleanup_after for zero-boilerplate setup/teardown

Install

Requires Python 3.11+ and behave 1.3.0+.

pip install behave-data

Optional extras:

Extra Packages Use case
yaml PyYAML YAML loader
excel openpyxl Excel loader
sql SQLAlchemy SQL loader
http requests HTTP loader
vault hvac HashiCorp Vault secrets
aws boto3 AWS Secrets Manager
all all above All optional loaders and backends
dev pytest, ruff, mypy, build Development
pip install behave-data[yaml,excel]    # multiple extras
pip install behave-data[dev]           # contribute

Quickstart

# features/environment.py
from behave_data import (
    setup_data,
    before_feature_hook,
    before_scenario_hook,
    before_step_hook,
    after_scenario_hook,
)


def before_all(context):
    setup_data(context)


def before_feature(context, feature):
    before_feature_hook(context, feature)


def before_scenario(context, scenario):
    before_scenario_hook(context, scenario)


def before_step(context, step):
    before_step_hook(context, step)


def after_scenario(context, scenario):
    after_scenario_hook(context, scenario)
# features/login.feature
@load_examples:csv:users.csv
Scenario Outline: User login
  Given a user with name "<name>" and email "<email>"
  When they log in
  Then they see the dashboard

  Examples:
# features/steps/login.py
from behave_data import typed_wrap, diff


@then("the users should match")
def step_match(context):
    table = typed_wrap(context.table)
    for row in table.typed_dicts():
        assert isinstance(row["age"], int)  # typed, not string
        assert row["city"] is None or row["city"]  # None for empty cells

That's it. Type annotations in headers, nulls resolved, examples from external files, tags for setup/teardown — all automatic.

Documentation

Section Link
Quickstart Quickstart
Typed Tables Typed Tables
Null Handling Null Handling
Table Diff Diff
Dynamic Examples Dynamic Examples
Fixtures Fixtures
Builders Builders
Secrets Secrets
Declarative Tags Tags
Hooks Hooks
Configuration Configuration
Cookbook Cookbook
Troubleshooting Troubleshooting
API Reference API
Migration Guide Migration
Changelog Changelog

Migration from behave-tables

behave-data depends on behave-tables and extends it:

  1. pip install behave-data — behave-tables comes as a dependency
  2. Use typed_wrap() instead of wrap() for typed column conversion
  3. Add setup_data(context) in before_all() to enable hooks, fixtures, builders, and secrets

All behave-tables APIs (as_dicts, as_models, transpose, to_csv, to_json, find_row, select, etc.) remain available via the re-exported TableWrapper and wrap().

See the Migration Guide for details.

Configuration

# behave_data.yml
null_markers: ["", "null", "None", "N/A"]
null_markers_by_column:
  age: ["", "unknown"]
secret_backend: env
secret_path: secrets/
load_base_dir: features/data/
data_sources:
  users_api: "http:https://api.example.com/users"   # @load_examples:users_api

See Configuration for all options.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for setup, development commands, and the release checklist.

For security issues, see SECURITY.md.

Acknowledgements

  • Built on behave-tables for table manipulation.
  • Inspired by the Behave community's need for first-class data handling in Gherkin scenarios.

License

MIT

Metadata

Release files for behave-data 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for behave-data 1.1.0
File Size Uploaded
behave_data-1.1.0.tar.gz 85.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for behave-data 1.1.0
File Interpreter ABI Platform
behave_data-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 126.5 kB

Release files / behave_data-1.1.0.tar.gz

Download URL behave_data-1.1.0.tar.gz
Size 85.7 kB
Tags Source
SHA-256 checksum
How to use checksums
85ca36b13231ca529559bb68bda200ed5c0c7a9caa36542a9c31d9754f9c0f4a
BLAKE2b-256 checksum
How to use checksums
1a01a283554157d232db130cf75d0aaa789edb21cc271bdaa86992f54515847c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release files / behave_data-1.1.0-py3-none-any.whl

Download URL behave_data-1.1.0-py3-none-any.whl
Size 40.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e403e5c0904acb0390cbca442d82924d37a960fd84e8e9821b3d2882a221bcbe
BLAKE2b-256 checksum
How to use checksums
b25148e8bc2146b7f3b0a8c44b57fdc5e00ba954d2b002d5526da82f373ecb61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page