Skip to main content

behave-format

CI Docs PyPI Python License

The opinionated formatter for Behave .feature files.

Black is for Python. gofmt is for Go. behave-format is for Gherkin.

Documentation: https://mathiaspaulenko.github.io/behave-format/


Overview

behave-format is a deterministic, opinionated formatter for Behave .feature files. It consumes the canonical domain model from behave-model and produces clean, consistent, beautifully formatted output.

Key principle: behave-format does NOT parse Gherkin. It does NOT lint. It does NOT validate. It ONLY transforms a behave-model.Project into formatted .feature files.

.feature files → behave-model (domain model) → behave-format → formatted .feature files

Features

  • Opinionated — minimal configuration, sensible defaults
  • Deterministic — same input always produces same output
  • Idempotent — format(format(x)) == format(x)
  • Fast — handles thousands of feature files efficiently
  • CI-friendly — --check mode with exit code 1 when formatting is needed
  • Safe — never changes semantics (names, step text, table values, docstrings)

Installation

pip install behave-format

Quick Start

CLI

# Format files in place (default)
behave-format features/

# Check mode (CI) — exit 1 if formatting is needed
behave-format --check features/

# Diff mode — show differences without writing
behave-format --diff features/

Python API

from behave_model import load_project
from behave_format import format_project, render_project, Settings

project = load_project("features/")

# Format the project model in place
format_project(project)

# Or render to text
text = render_project(project, Settings())

Formatting Rules

Tags

Tags are sorted alphabetically by default:

@api @smoke

Features

  • One blank line before each Feature
  • Clean title formatting

Scenarios

  • One blank line before each Scenario
  • Two-space indentation for steps
  Given user exists
  When user logs in
  Then dashboard is shown

Tables

Tables are always aligned:

Before:

|user|password|
|john|123|

After:

| user | password |
| john | 123      |

Blank Lines

  • No trailing blank lines
  • No multiple consecutive empty lines
  • Consistent spacing between blocks

Indentation

  • Spaces only (no tabs)
  • Default: 2 spaces

Configuration

Minimal configuration via pyproject.toml:

[tool.behave-format]
indent = 2
sort_tags = true
sort_features = false
sort_scenarios = false
line_length = 120
Option Default Description
indent 2 Number of spaces for indentation
sort_tags true Sort tags alphabetically
sort_features false Sort features by name
sort_scenarios false Sort scenarios by name
line_length 120 Maximum line length — wraps long tag lines

Before / After

Before

@smoke @auth
Feature: Login
  As a user
  I want to log in

  Background:
    Given a database connection

  @happy
  Scenario: Successful login
    Given the user is on the login page
    When the user enters "admin" and "password"
    Then the user should be logged in

After

@auth @smoke
Feature: Login
  As a user
  I want to log in

  Background:
    Given a database connection

  @happy
  Scenario: Successful login
    Given the user is on the login page
    When the user enters "admin" and "password"
    Then the user should be logged in

Architecture

behave_format/
├── config/
│   └── settings.py        # Settings dataclass + pyproject.toml loader
├── loader.py              # Parse via behave-model + restore comments/keywords
├── pipeline/
│   ├── normalize.py       # Whitespace, indentation, tag normalization
│   ├── sort.py            # Sort tags, features, scenarios
│   ├── align.py           # Table alignment, trailing whitespace
│   └── formatter.py       # Main orchestrator (format_project)
├── printer/
│   ├── feature_printer.py
│   ├── scenario_printer.py
│   ├── step_printer.py
│   ├── table_printer.py
│   └── tag_printer.py
└── cli/
    └── main.py            # CLI entry point

Pipeline

  1. Normalize — clean whitespace, standardize indentation, normalize tags
  2. Sort — order tags (alphabetically by default), optionally features and scenarios
  3. Align — align table columns, remove trailing spaces
  4. Print — convert behave-model → .feature text (deterministic)

Safety

The formatter NEVER changes semantics:

  • Feature names: preserved
  • Scenario names: preserved
  • Step text: preserved (only whitespace normalized)
  • DocString content: preserved
  • Table values: preserved (only alignment changes)
  • Comments content: preserved

Integration

behave-format integrates naturally with the Behave ecosystem:

Development

pip install -e ".[dev]"
pytest tests/ -v
ruff check .
ruff format --check .

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Run ruff check . and pytest tests/ before submitting
  4. Open a Pull Request

License

MIT

Metadata

Release files for behave-format 1.2.2

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-format 1.2.2
File Size Uploaded Provenance Actions
behave_format-1.2.2.tar.gz 54.2 kB With provenance Details for behave_format-1.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for behave-format 1.2.2
File Interpreter ABI Platform Actions
behave_format-1.2.2-py3-none-any.whl Python 3 none any Details for behave_format-1.2.2-py3-none-any.whl

Total release size: 82.3 kB

Release files / behave_format-1.2.2.tar.gz

Download URL behave_format-1.2.2.tar.gz
Size 54.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8a2c32000acb3a0133e092dab413213906b6ff0f4fc84e0ce881fbb2c15795a7
BLAKE2b-256 checksum
How to use checksums
d4f81785e6a1120e918d9081f5d53556d622975a6b5ab4e48323c568e7157446
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 17, 2026.

Transparency log

Release files / behave_format-1.2.2-py3-none-any.whl

Download URL behave_format-1.2.2-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5264bf5adaefb791909153bfce9d3f81bc358bd6c0426546d0c4b1aecb2014db
BLAKE2b-256 checksum
How to use checksums
b7752cf6687eb789ec7b3b9b8c924efbefb98deabbf5d27a4c9e2ed2a9887a3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 17, 2026.

Transparency log

Security for behave-format 1.2.2

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for behave_format-1.2.2.tar.gz

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 Nov 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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