CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-fire

A library for automatically generating command line interfaces from any Python object.

Pending
Overview
Eval results
Files

help-documentation.mddocs/

Help and Documentation

Fire provides comprehensive utilities for generating help text and usage information for CLI components, with support for docstring parsing, automatic formatting, and customizable output.

Capabilities

Help Text Generation

Generate formatted help text for any Fire component, including function signatures, docstrings, and usage examples.

def HelpText(component, trace=None, verbose=False):
    """
    Generate help text for a component.
    
    Analyzes the component to extract documentation, signatures, and usage
    information, formatting it for display to users.
    
    Parameters:
    - component: Component to generate help for (function, class, module, etc.)
    - trace: Optional FireTrace object showing execution path
    - verbose: Whether to include private/hidden members and detailed info
    
    Returns:
    String containing formatted help text
    """

Usage Text Generation

Generate concise usage information showing how to invoke a component from the command line.

def UsageText(component, trace=None, verbose=False):
    """
    Generate usage text for a component.
    
    Creates a concise summary of how to use the component from the command line,
    including argument names, types, and optional parameters.
    
    Parameters:
    - component: Component to generate usage for
    - trace: Optional FireTrace object showing execution path  
    - verbose: Whether to include additional usage details
    
    Returns:
    String containing formatted usage text
    """

Docstring Processing

Fire includes comprehensive docstring parsing capabilities for extracting structured information from Python docstrings.

class DocstringInfo:
    """
    Information extracted from docstrings (namedtuple).
    
    Attributes:
    - summary: Brief description (first line)
    - description: Detailed description  
    - args: List of ArgInfo objects for parameters
    - returns: Return value description
    - yields: Generator yield value description
    - raises: Exception information
    """

class ArgInfo:
    """
    Argument information from docstrings (namedtuple).
    
    Attributes:
    - name: Parameter name
    - type: Parameter type annotation or inferred type
    - description: Parameter description
    """

class KwargInfo(ArgInfo):
    """
    Keyword argument information, extends ArgInfo (namedtuple).
    
    Same attributes as ArgInfo but specifically for keyword arguments.
    """

Usage Examples

Basic help generation:

import fire
from fire import helptext

def process_file(filename, output_dir="./output", verbose=False):
    """
    Process a file and save results.
    
    Args:
        filename: Path to input file to process
        output_dir: Directory to save processed results  
        verbose: Enable verbose logging output
        
    Returns:
        Path to the processed output file
    """
    # Implementation here
    pass

# Generate help text
help_text = helptext.HelpText(process_file)
print(help_text)

# Generate usage text  
usage_text = helptext.UsageText(process_file)
print(usage_text)

Class help generation:

import fire
from fire import helptext

class DataAnalyzer:
    """Analyze datasets with various statistical methods."""
    
    def __init__(self, data_path):
        """Initialize analyzer with data file path."""
        self.data_path = data_path
    
    def summary(self, include_plots=False):
        """
        Generate summary statistics.
        
        Args:
            include_plots: Whether to generate visualization plots
            
        Returns:
            Dictionary containing summary statistics
        """
        pass
    
    def correlations(self, method='pearson'):
        """
        Calculate correlations between variables.
        
        Args:
            method: Correlation method ('pearson', 'spearman', 'kendall')
            
        Returns:
            Correlation matrix as pandas DataFrame
        """
        pass

# Generate help for the class
help_text = helptext.HelpText(DataAnalyzer)
print(help_text)

Using Fire's built-in help:

import fire

class Calculator:
    """A simple calculator with basic arithmetic operations."""
    
    def add(self, x, y):
        """Add two numbers together."""
        return x + y
    
    def multiply(self, x, y):
        """Multiply two numbers.""" 
        return x * y

if __name__ == '__main__':
    fire.Fire(Calculator)
    # Command line: python calc.py -- --help
    # Shows help for the Calculator class
    
    # Command line: python calc.py add -- --help  
    # Shows help for the add method

Help Text Features

Automatic signature extraction: Fire automatically extracts and formats function signatures, including:

  • Parameter names and types
  • Default values
  • Variable arguments (*args, **kwargs)
  • Type hints and annotations

Docstring parsing: Supports multiple docstring formats:

  • Google style
  • NumPy style
  • Sphinx style
  • Plain text descriptions

Usage examples:

# Get help for main component
python my_cli.py -- --help

# Get help for specific subcommand  
python my_cli.py subcommand -- --help

# Verbose help with private members
python my_cli.py -- --help --verbose

# Usage information only
python my_cli.py -- --usage

Formatted output includes:

  • Component name and description
  • Usage syntax with argument names
  • Parameter descriptions with types and defaults
  • Return value information
  • Exception documentation
  • Related commands and subcommands

Customization

Fire's help system respects:

  • Type hints for parameter type display
  • Docstring conventions for structured information
  • Default values for optional parameter indication
  • Private member filtering (unless --verbose is used)

The help text automatically adapts to the component type:

  • Functions: Show signature and docstring
  • Classes: Show constructor and available methods
  • Modules: Show available functions and classes
  • Objects: Show available attributes and methods

Install with Tessl CLI

npx tessl i tessl/pypi-fire

docs

argument-parsing.md

core-cli.md

help-documentation.md

index.md

interactive-mode.md

shell-completion.md

tile.json