Skip to content

Commit 6e8b3c3

Browse files
committed
docs: Summarize API in the top-level module docstring
Issue-317: #317
1 parent e5fa798 commit 6e8b3c3

File tree

1 file changed

+141
-3
lines changed

1 file changed

+141
-3
lines changed

src/griffe/__init__.py

+141-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,151 @@
1313
All messages written to standard output or error are logged using the `logging` module.
1414
Our logger's name is set to `"griffe"` and is public (you can rely on it).
1515
You can obtain the logger from the standard `logging` module: `logging.getLogger("griffe")`.
16-
17-
If you need to alter our logger, do so temporarily and restore it to its original state,
18-
for example using [context managers][contextlib.contextmanager].
1916
Actual logging messages are not part of the public API (they might change without notice).
2017
2118
Raised exceptions throughout the package are part of the public API (you can rely on them).
2219
Their actual messages are not part of the public API (they might change without notice).
20+
21+
The following paragraphs will help you discover the package's content.
22+
23+
## CLI entrypoints
24+
25+
Griffe provides a command-line interface (CLI) to interact with the package. The CLI entrypoints can be called from Python code.
26+
27+
- [`griffe.main`][]: Run the main program.
28+
- [`griffe.check`][]: Check for API breaking changes in two versions of the same package.
29+
- [`griffe.dump`][]: Load packages data and dump it as JSON.
30+
31+
## Loaders
32+
33+
To load API data, Griffe provides several high-level functions.
34+
35+
- [`griffe.load`][]: Load and return a Griffe object.
36+
- [`griffe.load_git`][]: Load and return a module from a specific Git reference.
37+
- [`griffe.load_pypi`][]: Load and return a module from a specific package version downloaded using pip.
38+
39+
## Models
40+
41+
The data loaded by Griffe is represented by several classes.
42+
43+
- [`griffe.Module`][]: The class representing a Python module.
44+
- [`griffe.Class`][]: The class representing a Python class.
45+
- [`griffe.Function`][]: The class representing a Python function or method.
46+
- [`griffe.Attribute`][]: The class representing a Python attribute.
47+
- [`griffe.Alias`][]: This class represents an alias, or indirection, to an object declared in another module.
48+
49+
Additional classes are available to represent other concepts.
50+
51+
- [`griffe.Decorator`][]: This class represents a decorator.
52+
- [`griffe.Parameters`][]: This class is a container for parameters.
53+
- [`griffe.Parameter`][]: This class represent a function parameter.
54+
55+
## Agents
56+
57+
Griffe is able to analyze code both statically and dynamically, using the following "agents".
58+
However most of the time you will only need to use the loaders above.
59+
60+
- [`griffe.visit`][]: Parse and visit a module file.
61+
- [`griffe.inspect`][]: Inspect a module.
62+
63+
## Serializers
64+
65+
Griffe can serizalize data to dictionary and JSON.
66+
67+
- [`griffe.Object.as_json`][griffe.Object.as_json]
68+
- [`griffe.Object.from_json`][griffe.Object.from_json]
69+
- [`griffe.JSONEncoder`][]: JSON encoder for Griffe objects.
70+
- [`griffe.json_decoder`][]: JSON decoder for Griffe objects.
71+
72+
## API checks
73+
74+
Griffe can compare two versions of the same package to find breaking changes.
75+
76+
- [`griffe.find_breaking_changes`][]: Find breaking changes between two versions of the same API.
77+
- [`griffe.Breakage`][]: Breakage classes can explain what broke from a version to another.
78+
79+
## Extensions
80+
81+
Griffe supports extensions. You can create your own extension by subclassing the `griffe.Extension` class.
82+
83+
- [`griffe.load_extensions`][]: Load configured extensions.
84+
- [`griffe.Extension`][]: Base class for Griffe extensions.
85+
86+
## Docstrings
87+
88+
Griffe can parse docstrings into structured data.
89+
90+
Main class:
91+
92+
- [`griffe.Docstring`][]: This class represents docstrings.
93+
94+
Docstring section and element classes all start with `Docstring`.
95+
96+
Docstring parsers:
97+
98+
- [`griffe.parse`][]: Parse the docstring.
99+
- [`griffe.parse_auto`][]: Parse a docstring by automatically detecting the style it uses.
100+
- [`griffe.parse_google`][]: Parse a Google-style docstring.
101+
- [`griffe.parse_numpy`][]: Parse a Numpydoc-style docstring.
102+
- [`griffe.parse_sphinx`][]: Parse a Sphinx-style docstring.
103+
104+
## Exceptions
105+
106+
Griffe uses several exceptions to signal errors.
107+
108+
- [`griffe.GriffeError`][]: The base exception for all Griffe errors.
109+
- [`griffe.LoadingError`][]: Exception for loading errors.
110+
- [`griffe.NameResolutionError`][]: Exception for names that cannot be resolved in a object scope.
111+
- [`griffe.UnhandledEditableModuleError`][]: Exception for unhandled editables modules, when searching modules.
112+
- [`griffe.UnimportableModuleError`][]: Exception for modules that cannot be imported.
113+
- [`griffe.AliasResolutionError`][]: Exception for aliases that cannot be resolved.
114+
- [`griffe.CyclicAliasError`][]: Exception raised when a cycle is detected in aliases.
115+
- [`griffe.LastNodeError`][]: Exception raised when trying to access a next or previous node.
116+
- [`griffe.RootNodeError`][]: Exception raised when trying to use siblings properties on a root node.
117+
- [`griffe.BuiltinModuleError`][]: Exception raised when trying to access the filepath of a builtin module.
118+
- [`griffe.ExtensionError`][]: Base class for errors raised by extensions.
119+
- [`griffe.ExtensionNotLoadedError`][]: Exception raised when an extension could not be loaded.
120+
- [`griffe.GitError`][]: Exception raised for errors related to Git.
121+
122+
# Expressions
123+
124+
Griffe stores snippets of code (attribute values, decorators, base class, type annotations) as expressions.
125+
Expressions are basically abstract syntax trees (AST) with a few differences compared to the nodes returned by [`ast`][].
126+
Griffe provides a few helpers to extract expressions from regular AST nodes.
127+
128+
- [`griffe.get_annotation`][]: Get a type annotation as expression.
129+
- [`griffe.get_base_class`][]: Get a base class as expression.
130+
- [`griffe.get_condition`][]: Get a condition as expression.
131+
- [`griffe.get_expression`][]: Get an expression from an AST node.
132+
- [`griffe.safe_get_annotation`][]: Get a type annotation as expression, safely (returns `None` on error).
133+
- [`griffe.safe_get_base_class`][]: Get a base class as expression, safely (returns `None` on error).
134+
- [`griffe.safe_get_condition`][]: Get a condition as expression, safely (returns `None` on error).
135+
- [`griffe.safe_get_expression`][]: Get an expression from an AST node, safely (returns `None` on error).
136+
137+
The base class for expressions.
138+
139+
- [`griffe.Expr`][]
140+
141+
Expression classes all start with `Expr`.
142+
143+
# Loggers
144+
145+
If you want to log messages from extensions, get a logger with `get_logger`.
146+
The `logger` attribute is used by Griffe itself. You can use it to temporarily disable Griffe logging.
147+
148+
- [`griffe.logger`][]: Our global logger, used throughout the library.
149+
- [`griffe.get_logger`][]: Create and return a new logger instance.
150+
151+
# Helpers
152+
153+
To test your Griffe extensions, or to load API data from code in memory, Griffe provides the following helpers.
154+
155+
- [`griffe.temporary_pyfile`][]: Create a Python file containing the given code in a temporary directory.
156+
- [`griffe.temporary_pypackage`][]: Create a package containing the given modules in a temporary directory.
157+
- [`griffe.temporary_visited_module`][]: Create and visit a temporary module with the given code.
158+
- [`griffe.temporary_visited_package`][]: Create and visit a temporary package.
159+
- [`griffe.temporary_inspected_module`][]: Create and inspect a temporary module with the given code.
160+
- [`griffe.temporary_inspected_package`][]: Create and inspect a temporary package.
23161
"""
24162

25163
from __future__ import annotations

0 commit comments

Comments
 (0)