Python API¶
behave-gen exposes a programmatic API for embedding in custom tooling, IDE plugins, or CI integrations.
Project scaffolding¶
behave_gen.commands.init.init_project
¶
init_project(target_dir: str | Path, options: InitOptions, registry: TemplateRegistry | None = None) -> Path
Create a new Behave project at target_dir/options.name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_dir
|
str | Path
|
Parent directory where the project folder is created. |
required |
options
|
InitOptions
|
Init options. |
required |
registry
|
TemplateRegistry | None
|
Optional template registry; defaults to the built-in one. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The resolved path to the created project root. |
Raises:
| Type | Description |
|---|---|
InitError
|
If the target exists and |
Source code in behave_gen/commands/init.py
behave_gen.commands.init.InitOptions
dataclass
¶
Options for the init command.
Source code in behave_gen/commands/init.py
Add feature¶
behave_gen.commands.add.add_feature
¶
add_feature(project_root: str | Path, options: AddFeatureOptions, *, features_dir: str | Path = 'features', default_tags: tuple[str, ...] = ()) -> Path
Generate a .feature file inside project_root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
str | Path
|
Root of the Behave project. |
required |
options
|
AddFeatureOptions
|
Add-feature options. |
required |
features_dir
|
str | Path
|
Features directory relative to |
'features'
|
default_tags
|
tuple[str, ...]
|
Default tags from project configuration, merged with
tags supplied on |
()
|
Returns:
| Type | Description |
|---|---|
Path
|
The path to the generated feature file. |
Raises:
| Type | Description |
|---|---|
AddError
|
If the project/features dir is missing, the template is unknown, the name is invalid, or the generated file fails to parse. |
Source code in behave_gen/commands/add.py
behave_gen.commands.add.AddFeatureOptions
dataclass
¶
Add steps¶
behave_gen.commands.steps.add_steps
¶
add_steps(project_root: str | Path, options: AddStepsOptions, *, steps_dir: str | Path = 'features/steps', output_file: str | Path | None = None) -> Path
Copy a step library into project_root's steps directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
str | Path
|
Root of the Behave project. |
required |
options
|
AddStepsOptions
|
Add-steps options. |
required |
steps_dir
|
str | Path
|
Steps directory relative to |
'features/steps'
|
output_file
|
str | Path | None
|
Optional explicit target path. When omitted the standard
library filename inside |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path to the written step-definition file. |
Raises:
| Type | Description |
|---|---|
AddStepsError
|
If the project is missing, the library is unknown, or the file already exists. |
Source code in behave_gen/commands/steps.py
behave_gen.commands.steps.AddStepsOptions
dataclass
¶
Add environment¶
behave_gen.commands.environment.add_environment
¶
add_environment(project_root: str | Path, options: AddEnvironmentOptions, *, environment_file: str | Path = 'environment.py') -> Path
Rewrite environment.py with the requested kit/data wiring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_root
|
str | Path
|
Root of the Behave project. |
required |
options
|
AddEnvironmentOptions
|
Add-environment options. |
required |
environment_file
|
str | Path
|
Path to the environment file, relative to the project root or absolute. |
'environment.py'
|
Returns:
| Type | Description |
|---|---|
Path
|
The path to the written |
Raises:
| Type | Description |
|---|---|
EnvironmentError
|
If the project root is missing or the file cannot be written. |
Source code in behave_gen/commands/environment.py
behave_gen.commands.environment.AddEnvironmentOptions
dataclass
¶
Configuration¶
behave_gen.config.BehaveGenConfig
dataclass
¶
Immutable behave-gen configuration.
Defaults are deterministic and independent of the host environment so that identical inputs always produce identical projects.
Source code in behave_gen/config.py
__post_init__
¶
Validate the template engine and normalise default tags.
Source code in behave_gen/config.py
as_dict
¶
default
classmethod
¶
with_overrides
¶
Return a new config with the given overrides applied.
Source code in behave_gen/config.py
behave_gen.config.load_config
¶
Load behave-gen configuration from root/pyproject.toml.
Falls back to :meth:BehaveGenConfig.default when the file or the
[tool.behave-gen] table is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str | Path
|
Project root containing |
required |
Returns:
| Type | Description |
|---|---|
BehaveGenConfig
|
A frozen :class: |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
ValueError
|
If the config contains unknown keys or invalid values. |
Source code in behave_gen/config.py
Check¶
behave_gen.commands.check.run_check
¶
run_check(project_root: str | Path | None = None, *, fmt: str = 'text', config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen check.
Returns the exit code: 0 when behave-doctor is missing (graceful) or
when the report has no errors; otherwise the doctor report's exit code.
Source code in behave_gen/commands/check.py
Stats¶
behave_gen.commands.stats.run_stats
¶
run_stats(project_root: str | Path | None = None, *, fmt: str = 'text', config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen stats.
Source code in behave_gen/commands/stats.py
Preview¶
behave_gen.commands.preview.run_preview
¶
run_preview(feature_path: str, project_root: str | Path | None = None, *, config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen preview.
Source code in behave_gen/commands/preview.py
Update¶
behave_gen.commands.update.run_update
¶
run_update(options: UpdateOptions, project_root: str | Path | None = None, *, config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen update.
Source code in behave_gen/commands/update.py
behave_gen.commands.update.UpdateOptions
dataclass
¶
Generators¶
behave_gen.commands.from_openapi.run_from_openapi
¶
run_from_openapi(options: FromOpenApiOptions, project_root: str | Path | None = None, *, config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen from-openapi.
Source code in behave_gen/commands/from_openapi.py
behave_gen.commands.from_openapi.FromOpenApiOptions
dataclass
¶
Options for from-openapi.
Source code in behave_gen/commands/from_openapi.py
behave_gen.commands.from_postman.run_from_postman
¶
run_from_postman(options: FromPostmanOptions, project_root: str | Path | None = None, *, config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen from-postman.
Source code in behave_gen/commands/from_postman.py
behave_gen.commands.from_postman.FromPostmanOptions
dataclass
¶
behave_gen.commands.from_swagger.run_from_swagger
¶
run_from_swagger(options: FromSwaggerOptions, project_root: str | Path | None = None, *, config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen from-swagger.
Source code in behave_gen/commands/from_swagger.py
behave_gen.commands.from_swagger.FromSwaggerOptions
dataclass
¶
Options for from-swagger.
Source code in behave_gen/commands/from_swagger.py
Migration¶
behave_gen.commands.migrate.run_migrate
¶
run_migrate(options: MigrateOptions, project_root: str | Path | None = None, *, config: BehaveGenConfig | None = None) -> int
CLI entry point for behave-gen migrate.