Core API Reference¶
Complete auto-generated reference for every public module in steplib.core.
Public API¶
The top-level steplib package re-exports the most commonly used
symbols for convenience. Each is documented in its respective section below.
- steplib.__version__ = '1.4.1.dev1'¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
Decorators¶
The @step decorator and related helpers.
The decorator stores StepInfo metadata on the decorated function. When
multiple decorators are stacked on the same function, each call appends a
new StepInfo entry to fn.__steplib_steps__.
- steplib.core.decorators.get_step_infos(fn)[source]¶
Return all
StepInfoentries attached to a decorated function.
- steplib.core.decorators.step(pattern, *, category, backend=None, description=None, parameters=None, example=None, tags=None, version=None, deprecated=False, i18n=None, requires=None)[source]¶
Attach
StepInfometadata to a step function.Can be stacked to register multiple patterns (e.g. for i18n or alternative backends) on the same implementation function.
- Parameters:
pattern (
str) – The behave matching pattern (e.g."I send a {method} request to {url}").category (
str) – Module/domain category (e.g."api","web").backend (
str|None) – Underlying technology (e.g."httpx","requests").description (
str|None) – Human-readable description; defaults to the function docstring.parameters (
list[Param] |None) – Typed parameter descriptors.tags (
list[str] |None) – Tags for grouping/filtering in the CLI.deprecated (
bool|str) –True, a deprecation message, orFalse.i18n (
dict[str,str] |None) – Translations of the pattern keyed by language code.requires (
list[str] |None) – Context attributes the step needs (e.g.["steplib.api.client"]).
- Return type:
- Returns:
A decorator that records the metadata and returns the function unchanged.
Metadata¶
Step metadata dataclass.
- class steplib.core.metadata.StepInfo(pattern, category, func, backend=None, description=None, parameters=<factory>, example=None, tags=<factory>, version=None, deprecated=False, i18n=<factory>, requires=<factory>)[source]¶
Bases:
objectImmutable metadata describing a single step registration.
A function decorated with
@stepmay produce multipleStepInfoentries (one per stacked decorator call). Each entry is expanded into one or more patterns via i18n translations.
Parameters¶
Parameter types and the Param dataclass for step metadata.
- class steplib.core.params.Param(name, type=<class 'str'>, required=False, default=None, description=None, choices=<factory>)[source]
Bases:
objectDescribes a single step parameter extracted from the pattern.
- name
Placeholder name as it appears in the pattern (e.g.
"method").
- type
Python type or registered type name (e.g.
int,"Json").
- required
Whether the parameter must be present.
- default
Default value when the parameter is not in the pattern.
- description
Human-readable description of the parameter.
- choices
Allowed values after conversion.
-
default:
Any
-
name:
str
-
required:
bool
- class steplib.core.params.TypeRegistry[source]
Bases:
objectRegistry of custom types registered via
register_type.Encapsulates mutable state that was previously a module-level dict, avoiding global mutable state.
- get(name)[source]
Return the registered type for name, or
Noneif not registered.
- register(name, py_type)[source]
Register a custom type usable in patterns as
{value:Name}.
- steplib.core.params.register_type(name, py_type)[source]
Register a custom type usable in patterns as
{value:Name}.Delegates to the default
TypeRegistryinstance.
- steplib.core.params.resolve_type(type_ref)[source]
Resolve a type reference (type object or name) to a Python type.
Delegates to the default
TypeRegistryinstance.
Registry¶
Central registry for step metadata and behave integration.
- class steplib.core.registry.BehaveLikeRegistry(*args, **kwargs)[source]¶
Bases:
ProtocolMinimal protocol for behave’s step registration API.
- class steplib.core.registry.StepRegistry(auto_register_behave=True)[source]¶
Bases:
objectStores
StepInfoentries and optionally registers them with behave.- Parameters:
auto_register_behave (
bool) – WhenTrue, each pattern is also registered with behave’s global step registry viabehave.step.
- add(fn)[source]¶
Register all step metadata attached to fn.
Extracts
StepInfoentries fromfn.__steplib_steps__, expands i18n translations, checks for duplicates, and optionally registers each pattern with behave.- Parameters:
- Raises:
StepContractError – If fn has no steplib step metadata.
DuplicateStepError – If a pattern is already registered for the same backend.
- Return type:
- filter(category=None, backend=None, tag=None)[source]¶
Return steps matching the given filters (all optional, AND-combined).
- get(pattern, backend=None)[source]¶
Return the
StepInfofor pattern (optionally filtered by backend).When backend is
None, returns the first match regardless of backend.
Discovery¶
Discovery and loading of steplib plugins via entry points.
- steplib.core.discovery.autoload(context, categories=None, backends=None)[source]¶
Load all installed steplib plugins and attach state to context.
- Parameters:
context (
Any) – The behave context object.categories (
list[str] |None) – Optional list of categories to keep (e.g.["api"]). WhenNone, all categories are loaded.backends (
dict[str,str] |None) – Optional mapping of category → backend to keep (e.g.{"api": "httpx"}). WhenNone, all backends are loaded.
- Return type:
- Returns:
A
SteplibStateholding the filtered registry.
- steplib.core.discovery.get_registry()[source]¶
Build a registry from all installed plugins without behave registration.
Used by the CLI to query step metadata outside of a behave run.
- Return type:
State¶
Per-run and per-scenario state attached to behave’s context.
- class steplib.core.state.BehaveContext(*args, **kwargs)[source]
Bases:
ProtocolMinimal protocol for behave’s
contextobject.- config
The behave configuration object.
- steplib
The
SteplibStateattached by steplib’s autoload/load.
-
config:
Any
-
steplib:
Any
- class steplib.core.state.SteplibState(context, registry)[source]
Bases:
objectHolds the steplib state attached to
context.steplib.Modules set their own namespaces as attributes on this object (e.g.
state.api = ApiContext(...)).- Parameters:
context (
Any) – The behave context object.registry (
StepRegistry) – TheStepRegistrypopulated during autoload/load.
- cleanup()[source]
Close resources after a scenario.
Called from
after_scenario. Iterates over all module-level attributes (non-underscore) and callscleanup()if available.- Return type:
- property context: Any
The behave context.
- property registry: StepRegistry
The step registry.
i18n¶
Internationalisation helpers for step patterns.
The design mandates that all patterns (base + translations) are registered with behave. No language filtering is performed at registration time; behave matches the pattern that corresponds to the text in the feature file.
- steplib.core.i18n.SUPPORTED_LANGS: frozenset[str] = frozenset({'en', 'es', 'pt'})¶
Language codes supported by steplib’s i18n system.
- steplib.core.i18n.expand_patterns(info)[source]¶
Expand a
StepInfointo(lang, pattern)pairs.The base pattern is tagged
"en". Each entry ininfo.i18nadds a translated pattern tagged with its language code.
Validation¶
Static validation of step contracts.
Checks that every registered step satisfies the rules described in
design-03-step-contract.md:
Patterns are parseable by
parse.Parameter names match pattern placeholders.
No duplicate patterns within the same backend.
i18n translations have the same placeholders as the base pattern.
Stacked patterns share the same placeholders and order.
Each step has a
category.
- steplib.core.validation.validate_steps(registry)[source]¶
Validate all steps in the registry.
- Parameters:
registry (
StepRegistry) – The registry to validate.- Return type:
- Returns:
A list of human-readable error messages (empty if all steps are valid).
Ecosystem¶
Ecosystem integration helpers for behave-kit, behave-tables and behave-data.
These functions lazily import the corresponding libraries and raise
MissingDependencyError with the appropriate extra name if the library
is not installed.
- steplib.core.ecosystem.assert_soft(condition, message='')[source]¶
Perform a soft assertion using
behave-kit.- Parameters:
- Raises:
MissingDependencyError – If
behave-kitis not installed.- Return type:
- steplib.core.ecosystem.check_behave_doctor_available()[source]¶
Check if
behave-doctoris installed.- Return type:
- Returns:
Trueifbehave-doctoris importable,Falseotherwise.
- steplib.core.ecosystem.check_behave_model_available()[source]¶
Check if
behave-modelis installed.- Return type:
- Returns:
Trueifbehave-modelis importable,Falseotherwise.
- steplib.core.ecosystem.load_test_data(source, **kwargs)[source]¶
Load test data from a file using
behave-data.- Parameters:
- Return type:
- Returns:
The loaded data.
- Raises:
MissingDependencyError – If
behave-datais not installed.StepContractError – If
behave-datais installed but has noloadfunction.
- steplib.core.ecosystem.wrap_table(table)[source]¶
Wrap a behave table using
behave-tablesfor easy conversion.- Parameters:
table (
Any) – Thecontext.tableobject from behave.- Return type:
- Returns:
A wrapped table object with methods like
as_dicts().- Raises:
MissingDependencyError – If
behave-tablesis not installed.
Exceptions¶
Custom exceptions for steplib.
- exception steplib.core.exceptions.DuplicateStepError(pattern, backend=None)[source]¶
Bases:
SteplibErrorRaised when two steps register the same pattern in the same backend.
- exception steplib.core.exceptions.MissingDependencyError(extra, package=None)[source]¶
Bases:
SteplibErrorRaised when an optional dependency (extra) is not installed.
- extra¶
The name of the missing extra (e.g.
"api","kit").
- package¶
The import name of the missing package, if known.
- exception steplib.core.exceptions.StepContractError[source]¶
Bases:
SteplibErrorRaised when a step function does not satisfy the step contract.
Behave integration¶
Integration helpers for behave’s environment.py.
before_all and after_scenario can be imported directly as behave
hooks. before_scenario must be written by the user (it calls
context.steplib.reset()).
Usage:
# features/environment.py
from steplib.behave import after_scenario, before_all
def before_scenario(context, scenario):
context.steplib.reset()
- class steplib.behave.SteplibState(context, registry)[source]¶
Bases:
objectHolds the steplib state attached to
context.steplib.Modules set their own namespaces as attributes on this object (e.g.
state.api = ApiContext(...)).- Parameters:
context (
Any) – The behave context object.registry (
StepRegistry) – TheStepRegistrypopulated during autoload/load.
- cleanup()[source]¶
Close resources after a scenario.
Called from
after_scenario. Iterates over all module-level attributes (non-underscore) and callscleanup()if available.- Return type:
- property registry: StepRegistry¶
The step registry.
- steplib.behave.after_scenario(context, scenario)[source]¶
Clean up steplib resources after a scenario.
- steplib.behave.autoload(context, categories=None, backends=None)[source]¶
Load all installed steplib plugins and attach state to context.
See
steplib.core.discovery.autoload()for details.- Parameters:
- Return type:
- Returns:
A
SteplibStateholding the filtered registry.
- steplib.behave.before_all(context)[source]¶
Run autoload and attach steplib state to context.
- Parameters:
context (
Any) – The behave context object.- Return type:
- Returns:
The
SteplibStateattached tocontext.steplib.
- steplib.behave.load(context, *modules)[source]¶
Load specific step modules by dotted path.
See
steplib.core.discovery.load()for details.- Parameters:
- Return type:
- Returns:
A
SteplibStateholding the registry.