Gherkin parser (official, by Cucumber team). It is a parser and compiler for the Gherkin language, which is a business-readable, domain-specific language used in Behavior-Driven Development (BDD) to describe software's behavior. It is developed and maintained by the Cucumber team and is designed to produce easily consumable Abstract Syntax Tree (AST) and Pickle objects. As of version 39.0.0, it officially supports Python versions 3.9 through 3.13. Releases are frequent, aligning with the broader Cucumber ecosystem development.
pip install gherkin-officialVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse Gherkin feature text into a Gherkin Document Abstract Syntax Tree (AST) and then compile it into 'Pickle' objects, which are simplified representations suitable for execution. It also shows basic access to the parsed data.
Ensure your project runs on Python 3.9 or a newer supported version.
Review and update `.feature` files to strictly adhere to the current Gherkin specification. Consult the Gherkin reference for up-to-date syntax.
Direct all development-related inquiries, bug reports, and pull requests to the main `cucumber/gherkin` repository (https://github.com/cucumber/gherkin).
Directly use the `gherkin-official` library's Python API (`from gherkin import Parser, Compiler`) for parsing and compiling Gherkin features within your applications.
Always use `from gherkin import Parser, Compiler` to access the core functionality.
Ensure the package is installed using `pip install gherkin-official`. When importing, use specific submodules like `from gherkin.parser import Parser` or `from gherkin.token_scanner import TokenScanner`, rather than just `import gherkin`.
Import the `Parser` class explicitly from the `gherkin.parser` submodule and then instantiate and use it. For example: `from gherkin.parser import Parser; parser = Parser(); document = parser.parse(token_scanner)`.
Review the Gherkin feature file for syntax errors according to the official Gherkin language specification. Pay close attention to keywords, indentation (two spaces recommended), and the structure of scenarios, outlines, and examples. Ensure comments are on their own line starting with '#' and not within tag sections or data tables.
Pass the Gherkin feature file content as a string when instantiating `TokenScanner`. For example: `with open('your_feature_file.feature', 'r', encoding='utf-8') as f: gherkin_content = f.read(); token_scanner = TokenScanner(gherkin_content)`.