behave-gen

July 27, 2026 · View on GitHub

A CLI toolkit for scaffolding and evolving Behave BDD projects.

CI Docs PyPI Python License Code style: ruff Types: mypy

behave-gen helps you create, extend, and maintain Behave (Python BDD) projects. It scaffolds new projects, generates .feature files and concrete step definitions, integrates ecosystem tools (behave-doctor, behave-lint, behave-format), and migrates Cucumber projects to Behave.

Features

CommandDescription
initScaffold a new Behave project with sensible defaults.
add featureGenerate .feature files from templates (default, CRUD).
add stepsAdd real, runnable step libraries (HTTP, auth). No empty skeletons.
add environmentRewrite environment.py with behave-kit/behave-data wiring.
add configAdd ecosystem packages to pyproject.toml idempotently.
checkRun behave-doctor diagnostics with actionable suggestions.
doctorAlias for check.
lintLint .feature files via behave-lint.
formatFormat .feature files via behave-format.
from-openapiGenerate features and HTTP steps from an OpenAPI 3.x spec.
from-postmanGenerate features from a Postman Collection v2.1.
from-swaggerConvert Swagger 2.0 to OpenAPI 3.x and generate features.
migrateMigrate a Cucumber (Java) project to Behave.
previewPretty-print a .feature file.
statsReport project statistics (features, scenarios, steps, tags).
updateRe-apply generated environment and step libraries.

Installation

pip install behave-gen

Requirements

  • Python 3.11 or newer.
  • A working pip / venv environment.

Optional extras extend functionality as shown below.

With optional extras:

pip install behave-gen[doctor,lint,format,openapi]
pip install behave-gen[all]
ExtraProvides
doctorbehave-doctor — static analysis for check/doctor.
lintbehave-lint — Gherkin linting for lint.
formatbehave-format — Gherkin formatting for format.
openapipyyaml — YAML parsing for from-openapi.
swaggerpyyaml — YAML parsing for from-swagger.
jinja2jinja2 — alternative template engine.
kitbehave-kit — environment hooks.
databehave-data — test data fixtures.
allAll of the above.

Quick start

# Create a new Behave project
behave-gen init my-project
cd my-project

# Add a feature file
behave-gen add feature login

# Add HTTP step definitions
behave-gen add steps --lib http

# Check project health
behave-gen check

# Run tests
behave

Generating from an OpenAPI spec

behave-gen from-openapi spec.yaml --out-dir gen --step-lib http --tag api

This produces .feature files grouped by path, each with scenarios that use the HTTP step library syntax. The --step-lib http flag also generates a concrete, runnable http_steps.py module.

Migrating from Cucumber

behave-gen migrate path/to/cucumber-project --out-dir migrated

Feature files are copied into a Behave features/ layout. Java step definitions are not auto-translated; use behave-gen add steps to generate Python equivalents.

Examples

The examples/ directory contains ready-to-run projects that demonstrate each workflow:

  • basic-projectinit + add feature + add steps with HTTP and auth step libraries.
  • openapi-projectfrom-openapi generating features and HTTP steps from a Petstore OpenAPI 3.0 spec.
  • migrated-projectmigrate converting a Cucumber (Java) project to Behave feature files.

See examples/README.md for details.

Architecture

behave_gen/
  cli/            Typer CLI application
  commands/       One module per CLI command
  generators/     Pluggable code generators (OpenAPI, Postman)
  plugins/        Source-specific parsers and builders
  step_libraries/ Built-in step library templates (HTTP, auth)
  templates/      Project and feature templates
  diagnostics.py  Optional-dependency handling

Supply chain & trust

  • Trusted Publishing (OIDC) — releases to PyPI use Trusted Publishing via GitHub Actions OIDC. No long-lived API tokens are stored in secrets.
  • Pinned actions — all GitHub Actions are pinned to specific versions (e.g. @v7, @v1.14.1).
  • Minimal dependencies — only behave, behave-model, and typer at runtime. All other dependencies are optional extras.
  • py.typed marker — the package ships with inline type hints.
  • Reproducible buildshatchling build backend with no dynamic metadata.

Development

git clone https://github.com/MathiasPaulenko/behave-gen.git
cd behave-gen
pip install -e ".[dev,docs]"
pre-commit install
CommandDescription
make helpShow all available targets.
make devInstall with dev extras.
make lintRun ruff check + mypy --strict.
make lint-fixAuto-fix lint issues.
make formatFormat the code with ruff format.
make format-checkVerify formatting without changes.
make testRun the test suite.
make test-covRun tests with coverage.
make buildBuild sdist + wheel into ref/output/dist/.
make docsBuild documentation site.
make docs-serveServe documentation locally.
make cleanRemove build artifacts and caches.

See CONTRIBUTING.md for full guidelines.

Documentation

Full documentation, including the CLI reference, configuration guide, and Python API docs, is published at mathiaspaulenko.github.io/behave-gen.

Acknowledgements

  • Built on top of Behave and the Python packaging ecosystem.
  • Template and scaffolding patterns inspired by the Python open source community's emphasis on minimal, composable tools.

License

MIT