Skip to content

griffe ¤

Griffe package.

Signatures for entire Python programs. Extract the structure, the frame, the skeleton of your project, to generate API documentation or find breaking changes in your API.

The entirety of the public API is exposed here, in the top-level griffe module.

All messages written to standard output or error are logged using the logging module. Our logger's name is set to "griffe" and is public (you can rely on it). You can obtain the logger from the standard logging module: logging.getLogger("griffe"). Actual logging messages are not part of the public API (they might change without notice).

Raised exceptions throughout the package are part of the public API (you can rely on them). Their actual messages are not part of the public API (they might change without notice).

The following paragraphs will help you discover the package's content.

CLI entrypoints¤

Griffe provides a command-line interface (CLI) to interact with the package. The CLI entrypoints can be called from Python code.

  • griffe.main: Run the main program.
  • griffe.check: Check for API breaking changes in two versions of the same package.
  • griffe.dump: Load packages data and dump it as JSON.

Loaders¤

To load API data, Griffe provides several high-level functions.

  • griffe.load: Load and return a Griffe object.
  • griffe.load_git: Load and return a module from a specific Git reference.
  • griffe.load_pypi: Load and return a module from a specific package version downloaded using pip.

Models¤

The data loaded by Griffe is represented by several classes.

  • griffe.Module: The class representing a Python module.
  • griffe.Class: The class representing a Python class.
  • griffe.Function: The class representing a Python function or method.
  • griffe.Attribute: The class representing a Python attribute.
  • griffe.Alias: This class represents an alias, or indirection, to an object declared in another module.

Additional classes are available to represent other concepts.

Agents¤

Griffe is able to analyze code both statically and dynamically, using the following "agents". However most of the time you will only need to use the loaders above.

Serializers¤

Griffe can serizalize data to dictionary and JSON.

API checks¤

Griffe can compare two versions of the same package to find breaking changes.

Extensions¤

Griffe supports extensions. You can create your own extension by subclassing the griffe.Extension class.

Docstrings¤

Griffe can parse docstrings into structured data.

Main class:

Docstring section and element classes all start with Docstring.

Docstring parsers:

Exceptions¤

Griffe uses several exceptions to signal errors.

Expressions¤

Griffe stores snippets of code (attribute values, decorators, base class, type annotations) as expressions. Expressions are basically abstract syntax trees (AST) with a few differences compared to the nodes returned by ast. Griffe provides a few helpers to extract expressions from regular AST nodes.

The base class for expressions.

Expression classes all start with Expr.

Loggers¤

If you want to log messages from extensions, get a logger with get_logger. The logger attribute is used by Griffe itself. You can use it to temporarily disable Griffe logging.

Helpers¤

To test your Griffe extensions, or to load API data from code in memory, Griffe provides the following helpers.