CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-griffe

Extract Python API signatures and detect breaking changes for documentation generation.

Pending
Overview
Eval results
Files

cli.mddocs/

CLI Functions

Command-line interface functions that provide the core functionality of the Griffe CLI tool. These functions can be called programmatically from Python or used as CLI commands.

Capabilities

Main Entry Point

Primary entry point for the Griffe CLI that dispatches to subcommands.

def main(args: list[str] | None = None) -> int:
    """
    Run the main griffe program.
    
    This function is executed when you type `griffe` or `python -m griffe`.
    It parses command-line arguments and dispatches to the appropriate subcommand.
    
    Args:
        args: List of command-line arguments. If None, uses sys.argv[1:]
    
    Returns:
        int: Exit code (0 for success, non-zero for errors)
    """

API Breakage Checking

Check for API breaking changes between two versions of the same package.

def check(
    package: str | Path,
    against: str | None = None,
    against_path: str | Path | None = None,
    *,
    base_ref: str | None = None,
    extensions: Sequence[str | dict[str, Any] | Extension | type[Extension]] | None = None,
    search_paths: Sequence[str | Path] | None = None,
    append_sys_path: bool = False,
    find_stubs_package: bool = False,
    allow_inspection: bool = True,
    force_inspection: bool = False,
    verbose: bool = False,
    color: bool | None = None,
    style: str | ExplanationStyle | None = None,
) -> int:
    """
    Check for API breaking changes between two versions of the same package.
    
    Compares package APIs and reports breaking changes. Can work with local
    packages, Git references, or PyPI versions.
    
    Args:
        package: The package to load and check
        against: Older Git reference (commit, branch, tag) to check against
        against_path: Path when the "against" reference is checked out
        base_ref: Git reference (commit, branch, tag) to check
        extensions: The extensions to use
        search_paths: The paths to search into
        append_sys_path: Whether to append the contents of sys.path to the search paths
        find_stubs_package: Whether to search for stubs packages
        allow_inspection: Whether to allow inspecting modules when visiting them is not possible
        force_inspection: Whether to force using dynamic analysis when loading data
        verbose: Use a verbose output
        color: Use colored output
        style: Output style for explanations
        
    Returns:
        int: Exit code (0 if no breaking changes found, 1 if breaking changes detected)
        
    Examples:
        Check current working directory against previous version:
        >>> griffe.check("mypackage")
        
        Via CLI:
        $ griffe check mypackage --verbose
        $ griffe check --search src mypackage
        $ griffe check package_name -b project-name==2.0 -a project-name==1.0
    """

JSON Serialization

Load packages and dump their API data as JSON.

def dump(
    packages: Sequence[str],
    *,
    output: str | IO | None = None,
    full: bool = False,
    docstring_parser: Parser | None = None,
    docstring_options: dict[str, Any] | None = None,
    extensions: Sequence[str | dict[str, Any] | Extension | type[Extension]] | None = None,
    resolve_aliases: bool = False,
    resolve_implicit: bool = False,
    resolve_external: bool | None = None,
    search_paths: Sequence[str | Path] | None = None,
    find_stubs_package: bool = False,
    append_sys_path: bool = False,
    allow_inspection: bool = True,
    force_inspection: bool = False,
    stats: bool = False,
) -> int:
    """
    Load packages data and dump it as JSON.
    
    Allows serializing loaded API data to JSON format for external processing,
    documentation generation, or storage.
    
    Args:
        packages: The packages to load and dump
        output: Where to output the JSON-serialized data
        full: Whether to output full or minimal data
        docstring_parser: The docstring parser to use
        docstring_options: Additional docstring parsing options
        extensions: The extensions to use
        resolve_aliases: Whether to resolve aliases (indirect objects references)
        resolve_implicit: Whether to resolve every alias or only the explicitly exported ones
        resolve_external: Whether to load additional, unspecified modules to resolve aliases
        search_paths: The paths to search into
        find_stubs_package: Whether to search for stubs packages
        append_sys_path: Whether to append the contents of sys.path to the search paths
        allow_inspection: Whether to allow inspecting modules when visiting them is not possible
        force_inspection: Whether to force using dynamic analysis when loading data
        stats: Whether to compute and include statistics
        
    Returns:
        int: Exit code (0 for success, non-zero for errors)
        
    Examples:
        Dump multiple packages:
        >>> griffe.dump(["httpx", "fastapi"])
        
        Via CLI:
        $ griffe dump httpx fastapi
        $ griffe dump --output api.json mypackage
    """

CLI Parser Configuration

Get the command-line argument parser for the Griffe CLI.

def get_parser() -> argparse.ArgumentParser:
    """
    Return the CLI argument parser.
    
    Creates and returns an argparse parser for the griffe command-line interface.
    Useful for extending or analyzing the CLI structure programmatically.
    
    Returns:
        argparse.ArgumentParser: The configured argument parser
        
    Example:
        >>> parser = griffe.get_parser()
        >>> args = parser.parse_args(['dump', 'mypackage'])
    """

Constants

Default Log Level

DEFAULT_LOG_LEVEL: str

The default log level for the CLI. Can be overridden by the GRIFFE_LOG_LEVEL environment variable. Typically set to "INFO" but may vary based on configuration.

Usage Examples

Programmatic CLI Usage

import griffe

# Run main CLI programmatically  
exit_code = griffe.main()

# Check for breaking changes
exit_code = griffe.check()
if exit_code == 0:
    print("No breaking changes detected")
else:
    print("Breaking changes found!")

# Dump API data
exit_code = griffe.dump()

Advanced CLI Configuration

import griffe
import sys

# Get the CLI parser for custom usage
parser = griffe.get_parser()

# Parse custom arguments
args = parser.parse_args(['check', 'mypackage', '--verbose'])

# Override sys.argv for CLI functions
original_argv = sys.argv[:]
try:
    sys.argv = ['griffe', 'dump', 'mypackage', '--output', 'api.json']
    exit_code = griffe.main()
finally:
    sys.argv = original_argv

Environment Configuration

import os
import griffe

# Set log level via environment
os.environ['GRIFFE_LOG_LEVEL'] = 'DEBUG'

# Run with debug logging
griffe.main()

Types

import argparse

# Type for the CLI argument parser
ArgumentParser = argparse.ArgumentParser

Install with Tessl CLI

npx tessl i tessl/pypi-griffe

docs

agents.md

breaking-changes.md

cli.md

docstrings.md

extensions.md

index.md

loaders.md

models.md

serialization.md

tile.json