Griffe CLI
griffecli provides the command-line interface for Griffe, a powerful library designed to extract structural information and API signatures from Python projects. It's used to generate API documentation and detect breaking changes. The current version is 2.0.2, and it follows the release cadence of its core library, Griffe, which is actively maintained.
Warnings
- breaking Griffe 2.x (and thus griffecli 2.x) introduced significant breaking changes from Griffe 1.x. The internal API was heavily refactored, which impacts users who were accessing Griffe programmatically (e.g., `GriffeLoader` instantiation). The output format of `griffe dump` also changed.
- gotcha griffecli is primarily a command-line wrapper. The actual core logic and API are provided by the `griffe` library. When using programmatically, you will typically import directly from `griffe` (e.g., `from griffe.loader import GriffeLoader`) rather than trying to import from `griffecli` itself.
- deprecated The `docstrings_parser` argument (a parameter) was removed in Griffe 2.x. Its functionality was replaced by the `docstring_parser` argument (a string name, like 'markdown' or 'griffe') or inferred automatically.
Install
-
pip install griffecli
Imports
- main
from griffe.cli import main
Quickstart
import os
from pathlib import Path
from griffe.cli import main
# Create a dummy module for demonstration
Path('my_module.py').write_text(
""""""A simple module.
def hello():
"""Say hello."""
return 'Hello, Griffe!'
"""
)
# Programmatically run the 'griffe dump' command
# Equivalent to: griffe dump my_module.py --output-format json
# We pass arguments as if they were from the command line
try:
main(['dump', 'my_module.py', '--output-format', 'json'])
except SystemExit as e:
if e.code != 0:
print(f"Error running Griffe: {e}")
# Clean up
Path('my_module.py').unlink(missing_ok=True)
Path('my_module.json').unlink(missing_ok=True)