Skip to content

dataclasses ¤

This module contains the data classes that represent Python objects.

The different objects are modules, classes, functions, and attribute (variables like module/class/instance attributes).

Classes:

  • Alias

    This class represents an alias, or indirection, to an object declared in another module.

  • Attribute

    The class representing a Python module/class/instance attribute.

  • Class

    The class representing a Python class.

  • Decorator

    This class represents decorators.

  • Docstring

    This class represents docstrings.

  • Function

    The class representing a Python function.

  • Kind

    Enumeration of the different object kinds.

  • Module

    The class representing a Python module.

  • Object

    An abstract class representing a Python object.

  • Parameter

    This class represent a function parameter.

  • ParameterKind

    Enumeration of the different parameter kinds.

  • Parameters

    This class is a container for parameters.

Alias ¤

Alias(
    name: str,
    target: str | Object | Alias,
    *,
    lineno: int | None = None,
    endlineno: int | None = None,
    runtime: bool = True,
    parent: Module | Class | Alias | None = None,
    inherited: bool = False
)

          flowchart TD
          griffe.dataclasses.Alias[Alias]
          griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
          griffe.mixins.GetMembersMixin[GetMembersMixin]
          griffe.mixins.SetMembersMixin[SetMembersMixin]
          griffe.mixins.DelMembersMixin[DelMembersMixin]
          griffe.mixins.SerializationMixin[SerializationMixin]

                        griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Alias
                            griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
              



          click griffe.dataclasses.Alias href "" "griffe.dataclasses.Alias"
          click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
          click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
          click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
          click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
          click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
          

This class represents an alias, or indirection, to an object declared in another module.

Aliases represent objects that are in the scope of a module or class, but were imported from another module.

They behave almost exactly like regular objects, to a few exceptions:

  • line numbers are those of the alias, not the target
  • the path is the alias path, not the canonical one
  • the name can be different from the target's
  • if the target can be resolved, the kind is the target's kind
  • if the target cannot be resolved, the kind becomes Kind.ALIAS

Parameters:

  • name (str) –

    The alias name.

  • target (str | Object | Alias) –

    If it's a string, the target resolution is delayed until accessing the target property. If it's an object, or even another alias, the target is immediately set.

  • lineno (int | None, default: None ) –

    The alias starting line number.

  • endlineno (int | None, default: None ) –

    The alias ending line number.

  • runtime (bool, default: True ) –

    Whether this alias is present at runtime or not.

  • parent (Module | Class | Alias | None, default: None ) –

    The alias parent.

  • inherited (bool, default: False ) –

    Whether this alias wraps an inherited member.

Methods:

  • __delitem__

    Delete a member with its name or path.

  • __getitem__

    Get a member with its name or path.

  • __setitem__

    Set a member with its name or path.

  • as_dict

    Return this alias' data as a dictionary.

  • as_json

    Return this target's data as a JSON string.

  • del_member

    Delete a member with its name or path.

  • filter_members

    Filter and return members based on predicates.

  • from_json

    Create an instance of this class from a JSON string.

  • get_member

    Get a member with its name or path.

  • has_labels

    Tell if this object has all the given labels.

  • is_exported

    Tell if this object/alias is implicitely exported by its parent.

  • is_kind

    Tell if this object is of the given kind.

  • is_public

    Whether this object is considered public.

  • member_is_exported

    Whether a member of this object is "exported".

  • mro

    Return a list of classes in order corresponding to Python's MRO.

  • resolve

    Resolve a name within this object's and parents' scope.

  • resolve_target

    Resolve the target.

  • set_member

    Set a member with its name or path.

Attributes:

alias_endlineno instance-attribute ¤

alias_endlineno: int | None = endlineno

The ending line number of the alias.

alias_lineno instance-attribute ¤

alias_lineno: int | None = lineno

The starting line number of the alias.

aliases property ¤

aliases: dict[str, Alias]

The aliases pointing to this object.

all_members property ¤

all_members: dict[str, Object | Alias]

All members (declared and inherited).

This method is part of the consumer API: do not use when producing Griffe trees!

annotation property writable ¤

annotation: str | Expr | None

The attribute type annotation.

attributes property ¤

attributes: dict[str, Attribute]

The attribute members.

This method is part of the consumer API: do not use when producing Griffe trees!

bases property ¤

bases: list[Expr | str]

The class bases.

canonical_path property ¤

canonical_path: str

The full dotted path of this object.

The canonical path is the path where the object was defined (not imported).

classes property ¤

classes: dict[str, Class]

The class members.

This method is part of the consumer API: do not use when producing Griffe trees!

decorators property ¤

decorators: list[Decorator]

The class/function decorators.

deleter property ¤

deleter: Function | None

The deleter linked to this function (property).

docstring property writable ¤

docstring: Docstring | None

The target docstring.

endlineno property ¤

endlineno: int | None

The ending line number of the target object.

exports property ¤

exports: set[str] | list[str | ExprName] | None

The names of the objects exported by this (module) object through the __all__ variable.

Exports can contain string (object names) or resolvable names, like other lists of exports coming from submodules:

from .submodule import __all__ as submodule_all

__all__ = ["hello", *submodule_all]

Exports get expanded by the loader before it expands wildcards and resolves aliases.

extra property ¤

extra: dict

Namespaced dictionaries storing extra metadata for this object, used by extensions.

filepath property ¤

filepath: Path | list[Path]

The file path (or directory list for namespace packages) where this object was defined.

final_target property ¤

final_target: Object

The final, resolved target, if possible.

This will iterate through the targets until a non-alias object is found.

functions property ¤

functions: dict[str, Function]

The function members.

This method is part of the consumer API: do not use when producing Griffe trees!

has_docstring property ¤

has_docstring: bool

Whether this alias' target has a non-empty docstring.

has_docstrings property ¤

has_docstrings: bool

Whether this alias' target or any of its members has a non-empty docstring.

imports property ¤

imports: dict[str, str]

The other objects imported by this alias' target.

Keys are the names within the object (from ... import ... as AS_NAME), while the values are the actual names of the objects (from ... import REAL_NAME as ...).

imports_future_annotations property ¤

imports_future_annotations: bool

Whether this module import future annotations.

inherited instance-attribute ¤

inherited: bool = inherited

Whether this alias represents an inherited member.

inherited_members cached property ¤

inherited_members: dict[str, Alias]

Members that are inherited from base classes.

Each inherited member of the target will be wrapped in an alias, to preserve correct object access paths.

This method is part of the consumer API: do not use when producing Griffe trees!

is_attribute property ¤

is_attribute: bool

Whether this object is an attribute.

is_class property ¤

is_class: bool

Whether this object is a class.

is_explicitely_exported property ¤

is_explicitely_exported: bool

Whether this object/alias is explicitely exported by its parent.

is_function property ¤

is_function: bool

Whether this object is a function.

is_implicitely_exported property ¤

is_implicitely_exported: bool

Whether this object/alias is implicitely exported by its parent.

is_init_module property ¤

is_init_module: bool

Whether this module is an __init__.py module.

is_module property ¤

is_module: bool

Whether this object is a module.

is_namespace_package property ¤

is_namespace_package: bool

Whether this module is a namespace package (top folder, no __init__.py).

is_namespace_subpackage property ¤

is_namespace_subpackage: bool

Whether this module is a namespace subpackage.

is_package property ¤

is_package: bool

Whether this module is a package (top module).

is_subpackage property ¤

is_subpackage: bool

Whether this module is a subpackage.

kind property ¤

kind: Kind

The target's kind, or Kind.ALIAS if the target cannot be resolved.

labels property ¤

labels: set[str]

The target labels (property, dataclass, etc.).

lineno property ¤

lineno: int | None

The starting line number of the target object.

lines property ¤

lines: list[str]

The lines containing the source of this object.

lines_collection property ¤

lines_collection: LinesCollection

The lines collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

members cached property ¤

members: dict[str, Object | Alias]

The target's members (modules, classes, functions, attributes).

module property ¤

module: Module

The parent module of this object.

Raises:

  • ValueError

    When the object is not a module and does not have a parent.

modules property ¤

modules: dict[str, Module]

The module members.

This method is part of the consumer API: do not use when producing Griffe trees!

modules_collection property ¤

modules_collection: ModulesCollection

The modules collection attached to the alias parents.

name instance-attribute ¤

name: str = name

The alias name.

overloads property writable ¤

overloads: dict[str, list[Function]] | list[Function] | None

The overloaded signatures declared in this class/module or for this function.

package property ¤

package: Module

The absolute top module (the package) of this object.

parameters property ¤

parameters: Parameters

The parameters of the current function or __init__ method for classes.

This property can fetch inherited members, and therefore is part of the consumer API: do not use when producing Griffe trees!

parent property writable ¤

parent: Module | Class | Alias | None

The parent of this alias.

path property ¤

path: str

The dotted path / import path of this object.

public instance-attribute ¤

public: bool | None = None

Whether this alias is public.

relative_filepath property ¤

relative_filepath: Path

The file path where this object was defined, relative to the current working directory.

If this object's file path is not relative to the current working directory, return its absolute path.

Raises:

  • ValueError

    When the relative path could not be computed.

relative_package_filepath property ¤

relative_package_filepath: Path

The file path where this object was defined, relative to the top module path.

Raises:

  • ValueError

    When the relative path could not be computed.

resolved property ¤

resolved: bool

Whether this alias' target is resolved.

resolved_bases property ¤

resolved_bases: list[Object]

Resolved class bases.

This method is part of the consumer API: do not use when producing Griffe trees!

returns property writable ¤

returns: str | Expr | None

The function return type annotation.

runtime instance-attribute ¤

runtime: bool = runtime

Whether this alias is available at runtime.

setter property ¤

setter: Function | None

The setter linked to this function (property).

source property ¤

source: str

The source code of this object.

target property writable ¤

target: Object | Alias

The resolved target (actual object), if possible.

Upon accessing this property, if the target is not already resolved, a lookup is done using the modules collection to find the target.

target_path instance-attribute ¤

target_path: str

The path of this alias' target.

value property ¤

value: str | Expr | None

The attribute value.

wildcard property ¤

wildcard: str | None

The module on which the wildcard import is performed (if any).

__delitem__ ¤

__delitem__(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]

__getitem__ ¤

__getitem__(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]

__setitem__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Parameters:

Examples:

>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux

as_dict ¤

as_dict(
    *, full: bool = False, **kwargs: Any
) -> dict[str, Any]

Return this alias' data as a dictionary.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

as_json ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this target's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

del_member ¤

del_member(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))

filter_members ¤

filter_members(
    *predicates: Callable[[Object | Alias], bool]
) -> dict[str, Object | Alias]

Filter and return members based on predicates.

Parameters:

  • *predicates (Callable[[Object | Alias], bool], default: () ) –

    A list of predicates, i.e. callables accepting a member as argument and returning a boolean.

Returns:

from_json classmethod ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

get_member ¤

get_member(key: str | Sequence[str]) -> Object | Alias

Get a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]

has_labels ¤

has_labels(labels: set[str]) -> bool

Tell if this object has all the given labels.

Parameters:

  • labels (set[str]) –

    A set of labels.

Returns:

  • bool

    True or False.

is_exported ¤

is_exported(*, explicitely: bool = True) -> bool

Tell if this object/alias is implicitely exported by its parent.

Parameters:

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

is_kind ¤

is_kind(kind: str | Kind | set[str | Kind]) -> bool

Tell if this object is of the given kind.

Parameters:

  • kind (str | Kind | set[str | Kind]) –

    An instance or set of kinds (strings or enumerations).

Raises:

  • ValueError

    When an empty set is given as argument.

Returns:

  • bool

    True or False.

is_public ¤

is_public(
    *, strict: bool = False, check_name: bool = True
) -> bool

Whether this object is considered public.

In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.

Therefore, to decide whether an object is public, we follow this algorithm:

  • If the object's public attribute is set (boolean), return its value.
  • In strict mode, the object is public only if it is explicitely exported (listed in __all__). Strict mode should only be used for module members.
  • Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
  • Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
  • Otherwise, the object is public.

member_is_exported ¤

member_is_exported(
    member: Object | Alias, *, explicitely: bool = True
) -> bool

Whether a member of this object is "exported".

By exported, we mean that the object is included in the __all__ attribute of its parent module or class. When __all__ is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.

Parameters:

  • member (Object | Alias) –

    The member to verify.

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

mro ¤

mro() -> list[Class]

Return a list of classes in order corresponding to Python's MRO.

resolve ¤

resolve(name: str) -> str

Resolve a name within this object's and parents' scope.

Parameters:

  • name (str) –

    The name to resolve.

Raises:

Returns:

  • str

    The resolved name.

resolve_target ¤

resolve_target() -> None

Resolve the target.

Raises:

  • AliasResolutionError

    When the target cannot be resolved. It happens when the target does not exist, or could not be loaded (unhandled dynamic object?), or when the target is from a module that was not loaded and added to the collection.

  • CyclicAliasError

    When the resolved target is the alias itself.

set_member ¤

set_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Parameters:

Examples:

>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)

Attribute ¤

Attribute(
    *args: Any,
    value: str | Expr | None = None,
    annotation: str | Expr | None = None,
    **kwargs: Any
)

          flowchart TD
          griffe.dataclasses.Attribute[Attribute]
          griffe.dataclasses.Object[Object]
          griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
          griffe.mixins.GetMembersMixin[GetMembersMixin]
          griffe.mixins.SetMembersMixin[SetMembersMixin]
          griffe.mixins.DelMembersMixin[DelMembersMixin]
          griffe.mixins.SerializationMixin[SerializationMixin]

                        griffe.dataclasses.Object --> griffe.dataclasses.Attribute
                            griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
                            griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
              




          click griffe.dataclasses.Attribute href "" "griffe.dataclasses.Attribute"
          click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
          click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
          click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
          click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
          click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
          click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
          

The class representing a Python module/class/instance attribute.

Parameters:

Methods:

  • __delitem__

    Delete a member with its name or path.

  • __getitem__

    Get a member with its name or path.

  • __setitem__

    Set a member with its name or path.

  • as_dict

    Return this function's data as a dictionary.

  • as_json

    Return this object's data as a JSON string.

  • del_member

    Delete a member with its name or path.

  • filter_members

    Filter and return members based on predicates.

  • from_json

    Create an instance of this class from a JSON string.

  • get_member

    Get a member with its name or path.

  • has_labels

    Tell if this object has all the given labels.

  • is_exported

    Tell if this object/alias is implicitely exported by its parent.

  • is_kind

    Tell if this object is of the given kind.

  • is_public

    Whether this object is considered public.

  • member_is_exported

    Whether a member of this object is "exported".

  • resolve

    Resolve a name within this object's and parents' scope.

  • set_member

    Set a member with its name or path.

Attributes:

aliases instance-attribute ¤

aliases: dict[str, Alias] = {}

The aliases pointing to this object.

all_members property ¤

all_members: dict[str, Object | Alias]

All members (declared and inherited).

This method is part of the consumer API: do not use when producing Griffe trees!

annotation instance-attribute ¤

annotation: str | Expr | None = annotation

The attribute type annotation.

attributes property ¤

attributes: dict[str, Attribute]

The attribute members.

This method is part of the consumer API: do not use when producing Griffe trees!

canonical_path property ¤

canonical_path: str

The full dotted path of this object.

The canonical path is the path where the object was defined (not imported).

classes property ¤

classes: dict[str, Class]

The class members.

This method is part of the consumer API: do not use when producing Griffe trees!

docstring instance-attribute ¤

docstring: Docstring | None = docstring

The object docstring.

endlineno instance-attribute ¤

endlineno: int | None = endlineno

The ending line number of the object.

exports instance-attribute ¤

exports: set[str] | list[str | ExprName] | None = None

The names of the objects exported by this (module) object through the __all__ variable.

Exports can contain string (object names) or resolvable names, like other lists of exports coming from submodules:

from .submodule import __all__ as submodule_all

__all__ = ["hello", *submodule_all]

Exports get expanded by the loader before it expands wildcards and resolves aliases.

extra instance-attribute ¤

Namespaced dictionaries storing extra metadata for this object, used by extensions.

filepath property ¤

filepath: Path | list[Path]

The file path (or directory list for namespace packages) where this object was defined.

functions property ¤

functions: dict[str, Function]

The function members.

This method is part of the consumer API: do not use when producing Griffe trees!

has_docstring property ¤

has_docstring: bool

Whether this object has a docstring (empty or not).

has_docstrings property ¤

has_docstrings: bool

Whether this object or any of its members has a docstring (empty or not).

imports instance-attribute ¤

imports: dict[str, str] = {}

The other objects imported by this object.

Keys are the names within the object (from ... import ... as AS_NAME), while the values are the actual names of the objects (from ... import REAL_NAME as ...).

inherited class-attribute instance-attribute ¤

inherited: bool = False

Whether this object (alias) is inherited.

Objects can never be inherited, only aliases can.

inherited_members cached property ¤

inherited_members: dict[str, Alias]

Members that are inherited from base classes.

This method is part of the consumer API: do not use when producing Griffe trees!

is_alias class-attribute instance-attribute ¤

is_alias: bool = False

Whether this object is an alias.

is_attribute property ¤

is_attribute: bool

Whether this object is an attribute.

is_class property ¤

is_class: bool

Whether this object is a class.

is_collection class-attribute instance-attribute ¤

is_collection: bool = False

Whether this object is a (modules) collection.

is_explicitely_exported property ¤

is_explicitely_exported: bool

Whether this object/alias is explicitely exported by its parent.

is_function property ¤

is_function: bool

Whether this object is a function.

is_implicitely_exported property ¤

is_implicitely_exported: bool

Whether this object/alias is implicitely exported by its parent.

is_init_module property ¤

is_init_module: bool

Whether this object is an __init__.py module.

is_module property ¤

is_module: bool

Whether this object is a module.

is_namespace_package property ¤

is_namespace_package: bool

Whether this object is a namespace package (top folder, no __init__.py).

is_namespace_subpackage property ¤

is_namespace_subpackage: bool

Whether this object is a namespace subpackage.

is_package property ¤

is_package: bool

Whether this object is a package (top module).

is_subpackage property ¤

is_subpackage: bool

Whether this object is a subpackage.

kind class-attribute instance-attribute ¤

kind = ATTRIBUTE

The object kind.

labels instance-attribute ¤

labels: set[str] = set()

The object labels (property, dataclass, etc.).

lineno instance-attribute ¤

lineno: int | None = lineno

The starting line number of the object.

lines property ¤

lines: list[str]

The lines containing the source of this object.

lines_collection property ¤

lines_collection: LinesCollection

The lines collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

members instance-attribute ¤

members: dict[str, Object | Alias] = {}

The object members (modules, classes, functions, attributes).

module property ¤

module: Module

The parent module of this object.

Raises:

  • ValueError

    When the object is not a module and does not have a parent.

modules property ¤

modules: dict[str, Module]

The module members.

This method is part of the consumer API: do not use when producing Griffe trees!

modules_collection property ¤

modules_collection: ModulesCollection

The modules collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

name instance-attribute ¤

name: str = name

The object name.

package property ¤

package: Module

The absolute top module (the package) of this object.

parent instance-attribute ¤

parent: Module | Class | None = parent

The parent of the object (none if top module).

path property ¤

path: str

The dotted path of this object.

On regular objects (not aliases), the path is the canonical path.

public instance-attribute ¤

public: bool | None = None

Whether this object is public.

relative_filepath property ¤

relative_filepath: Path

The file path where this object was defined, relative to the current working directory.

If this object's file path is not relative to the current working directory, return its absolute path.

Raises:

  • ValueError

    When the relative path could not be computed.

relative_package_filepath property ¤

relative_package_filepath: Path

The file path where this object was defined, relative to the top module path.

Raises:

  • ValueError

    When the relative path could not be computed.

runtime instance-attribute ¤

runtime: bool = runtime

Whether this object is available at runtime.

Typically, type-guarded objects (under an if TYPE_CHECKING condition) are not available at runtime.

source property ¤

source: str

The source code of this object.

value instance-attribute ¤

value: str | Expr | None = value

The attribute value.

__delitem__ ¤

__delitem__(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]

__getitem__ ¤

__getitem__(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]

__setitem__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Parameters:

Examples:

>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux

as_dict ¤

as_dict(**kwargs: Any) -> dict[str, Any]

Return this function's data as a dictionary.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

as_json ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this object's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

del_member ¤

del_member(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))

filter_members ¤

filter_members(
    *predicates: Callable[[Object | Alias], bool]
) -> dict[str, Object | Alias]

Filter and return members based on predicates.

Parameters:

  • *predicates (Callable[[Object | Alias], bool], default: () ) –

    A list of predicates, i.e. callables accepting a member as argument and returning a boolean.

Returns:

from_json classmethod ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

get_member ¤

get_member(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]

has_labels ¤

has_labels(labels: set[str]) -> bool

Tell if this object has all the given labels.

Parameters:

  • labels (set[str]) –

    A set of labels.

Returns:

  • bool

    True or False.

is_exported ¤

is_exported(*, explicitely: bool = True) -> bool

Tell if this object/alias is implicitely exported by its parent.

Parameters:

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

is_kind ¤

is_kind(kind: str | Kind | set[str | Kind]) -> bool

Tell if this object is of the given kind.

Parameters:

  • kind (str | Kind | set[str | Kind]) –

    An instance or set of kinds (strings or enumerations).

Raises:

  • ValueError

    When an empty set is given as argument.

Returns:

  • bool

    True or False.

is_public ¤

is_public(
    *, strict: bool = False, check_name: bool = True
) -> bool

Whether this object is considered public.

In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.

Therefore, to decide whether an object is public, we follow this algorithm:

  • If the object's public attribute is set (boolean), return its value.
  • In strict mode, the object is public only if it is explicitely exported (listed in __all__). Strict mode should only be used for module members.
  • Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
  • Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
  • Otherwise, the object is public.

member_is_exported ¤

member_is_exported(
    member: Object | Alias, *, explicitely: bool = True
) -> bool

Whether a member of this object is "exported".

By exported, we mean that the object is included in the __all__ attribute of its parent module or class. When __all__ is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.

Parameters:

  • member (Object | Alias) –

    The member to verify.

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

resolve ¤

resolve(name: str) -> str

Resolve a name within this object's and parents' scope.

Parameters:

  • name (str) –

    The name to resolve.

Raises:

Returns:

  • str

    The resolved name.

set_member ¤

set_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Parameters:

Examples:

>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)

Class ¤

Class(
    *args: Any,
    bases: Sequence[Expr | str] | None = None,
    decorators: list[Decorator] | None = None,
    **kwargs: Any
)

          flowchart TD
          griffe.dataclasses.Class[Class]
          griffe.dataclasses.Object[Object]
          griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
          griffe.mixins.GetMembersMixin[GetMembersMixin]
          griffe.mixins.SetMembersMixin[SetMembersMixin]
          griffe.mixins.DelMembersMixin[DelMembersMixin]
          griffe.mixins.SerializationMixin[SerializationMixin]

                        griffe.dataclasses.Object --> griffe.dataclasses.Class
                            griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
                            griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
              




          click griffe.dataclasses.Class href "" "griffe.dataclasses.Class"
          click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
          click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
          click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
          click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
          click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
          click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
          

The class representing a Python class.

Parameters:

Methods:

  • __delitem__

    Delete a member with its name or path.

  • __getitem__

    Get a member with its name or path.

  • __setitem__

    Set a member with its name or path.

  • as_dict

    Return this class' data as a dictionary.

  • as_json

    Return this object's data as a JSON string.

  • del_member

    Delete a member with its name or path.

  • filter_members

    Filter and return members based on predicates.

  • from_json

    Create an instance of this class from a JSON string.

  • get_member

    Get a member with its name or path.

  • has_labels

    Tell if this object has all the given labels.

  • is_exported

    Tell if this object/alias is implicitely exported by its parent.

  • is_kind

    Tell if this object is of the given kind.

  • is_public

    Whether this object is considered public.

  • member_is_exported

    Whether a member of this object is "exported".

  • mro

    Return a list of classes in order corresponding to Python's MRO.

  • resolve

    Resolve a name within this object's and parents' scope.

  • set_member

    Set a member with its name or path.

Attributes:

aliases instance-attribute ¤

aliases: dict[str, Alias] = {}

The aliases pointing to this object.

all_members property ¤

all_members: dict[str, Object | Alias]

All members (declared and inherited).

This method is part of the consumer API: do not use when producing Griffe trees!

attributes property ¤

attributes: dict[str, Attribute]

The attribute members.

This method is part of the consumer API: do not use when producing Griffe trees!

bases instance-attribute ¤

bases: list[Expr | str] = list(bases) if bases else []

The class bases.

canonical_path property ¤

canonical_path: str

The full dotted path of this object.

The canonical path is the path where the object was defined (not imported).

classes property ¤

classes: dict[str, Class]

The class members.

This method is part of the consumer API: do not use when producing Griffe trees!

decorators instance-attribute ¤

decorators: list[Decorator] = decorators or []

The class decorators.

docstring instance-attribute ¤

docstring: Docstring | None = docstring

The object docstring.

endlineno instance-attribute ¤

endlineno: int | None = endlineno

The ending line number of the object.

exports instance-attribute ¤

exports: set[str] | list[str | ExprName] | None = None

The names of the objects exported by this (module) object through the __all__ variable.

Exports can contain string (object names) or resolvable names, like other lists of exports coming from submodules:

from .submodule import __all__ as submodule_all

__all__ = ["hello", *submodule_all]

Exports get expanded by the loader before it expands wildcards and resolves aliases.

extra instance-attribute ¤

Namespaced dictionaries storing extra metadata for this object, used by extensions.

filepath property ¤

filepath: Path | list[Path]

The file path (or directory list for namespace packages) where this object was defined.

functions property ¤

functions: dict[str, Function]

The function members.

This method is part of the consumer API: do not use when producing Griffe trees!

has_docstring property ¤

has_docstring: bool

Whether this object has a docstring (empty or not).

has_docstrings property ¤

has_docstrings: bool

Whether this object or any of its members has a docstring (empty or not).

imports instance-attribute ¤

imports: dict[str, str] = {}

The other objects imported by this object.

Keys are the names within the object (from ... import ... as AS_NAME), while the values are the actual names of the objects (from ... import REAL_NAME as ...).

inherited class-attribute instance-attribute ¤

inherited: bool = False

Whether this object (alias) is inherited.

Objects can never be inherited, only aliases can.

inherited_members cached property ¤

inherited_members: dict[str, Alias]

Members that are inherited from base classes.

This method is part of the consumer API: do not use when producing Griffe trees!

is_alias class-attribute instance-attribute ¤

is_alias: bool = False

Whether this object is an alias.

is_attribute property ¤

is_attribute: bool

Whether this object is an attribute.

is_class property ¤

is_class: bool

Whether this object is a class.

is_collection class-attribute instance-attribute ¤

is_collection: bool = False

Whether this object is a (modules) collection.

is_explicitely_exported property ¤

is_explicitely_exported: bool

Whether this object/alias is explicitely exported by its parent.

is_function property ¤

is_function: bool

Whether this object is a function.

is_implicitely_exported property ¤

is_implicitely_exported: bool

Whether this object/alias is implicitely exported by its parent.

is_init_module property ¤

is_init_module: bool

Whether this object is an __init__.py module.

is_module property ¤

is_module: bool

Whether this object is a module.

is_namespace_package property ¤

is_namespace_package: bool

Whether this object is a namespace package (top folder, no __init__.py).

is_namespace_subpackage property ¤

is_namespace_subpackage: bool

Whether this object is a namespace subpackage.

is_package property ¤

is_package: bool

Whether this object is a package (top module).

is_subpackage property ¤

is_subpackage: bool

Whether this object is a subpackage.

kind class-attribute instance-attribute ¤

kind = CLASS

The object kind.

labels instance-attribute ¤

labels: set[str] = set()

The object labels (property, dataclass, etc.).

lineno instance-attribute ¤

lineno: int | None = lineno

The starting line number of the object.

lines property ¤

lines: list[str]

The lines containing the source of this object.

lines_collection property ¤

lines_collection: LinesCollection

The lines collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

members instance-attribute ¤

members: dict[str, Object | Alias] = {}

The object members (modules, classes, functions, attributes).

module property ¤

module: Module

The parent module of this object.

Raises:

  • ValueError

    When the object is not a module and does not have a parent.

modules property ¤

modules: dict[str, Module]

The module members.

This method is part of the consumer API: do not use when producing Griffe trees!

modules_collection property ¤

modules_collection: ModulesCollection

The modules collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

name instance-attribute ¤

name: str = name

The object name.

overloads instance-attribute ¤

overloads: dict[str, list[Function]] = defaultdict(list)

The overloaded signatures declared in this class.

package property ¤

package: Module

The absolute top module (the package) of this object.

parameters property ¤

parameters: Parameters

The parameters of this class' __init__ method, if any.

This property fetches inherited members, and therefore is part of the consumer API: do not use when producing Griffe trees!

parent instance-attribute ¤

parent: Module | Class | None = parent

The parent of the object (none if top module).

path property ¤

path: str

The dotted path of this object.

On regular objects (not aliases), the path is the canonical path.

public instance-attribute ¤

public: bool | None = None

Whether this object is public.

relative_filepath property ¤

relative_filepath: Path

The file path where this object was defined, relative to the current working directory.

If this object's file path is not relative to the current working directory, return its absolute path.

Raises:

  • ValueError

    When the relative path could not be computed.

relative_package_filepath property ¤

relative_package_filepath: Path

The file path where this object was defined, relative to the top module path.

Raises:

  • ValueError

    When the relative path could not be computed.

resolved_bases cached property ¤

resolved_bases: list[Object]

Resolved class bases.

This method is part of the consumer API: do not use when producing Griffe trees!

runtime instance-attribute ¤

runtime: bool = runtime

Whether this object is available at runtime.

Typically, type-guarded objects (under an if TYPE_CHECKING condition) are not available at runtime.

source property ¤

source: str

The source code of this object.

__delitem__ ¤

__delitem__(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]

__getitem__ ¤

__getitem__(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]

__setitem__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Parameters:

Examples:

>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux

as_dict ¤

as_dict(**kwargs: Any) -> dict[str, Any]

Return this class' data as a dictionary.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

as_json ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this object's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

del_member ¤

del_member(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))

filter_members ¤

filter_members(
    *predicates: Callable[[Object | Alias], bool]
) -> dict[str, Object | Alias]

Filter and return members based on predicates.

Parameters:

  • *predicates (Callable[[Object | Alias], bool], default: () ) –

    A list of predicates, i.e. callables accepting a member as argument and returning a boolean.

Returns:

from_json classmethod ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

get_member ¤

get_member(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]

has_labels ¤

has_labels(labels: set[str]) -> bool

Tell if this object has all the given labels.

Parameters:

  • labels (set[str]) –

    A set of labels.

Returns:

  • bool

    True or False.

is_exported ¤

is_exported(*, explicitely: bool = True) -> bool

Tell if this object/alias is implicitely exported by its parent.

Parameters:

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

is_kind ¤

is_kind(kind: str | Kind | set[str | Kind]) -> bool

Tell if this object is of the given kind.

Parameters:

  • kind (str | Kind | set[str | Kind]) –

    An instance or set of kinds (strings or enumerations).

Raises:

  • ValueError

    When an empty set is given as argument.

Returns:

  • bool

    True or False.

is_public ¤

is_public(
    *, strict: bool = False, check_name: bool = True
) -> bool

Whether this object is considered public.

In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.

Therefore, to decide whether an object is public, we follow this algorithm:

  • If the object's public attribute is set (boolean), return its value.
  • In strict mode, the object is public only if it is explicitely exported (listed in __all__). Strict mode should only be used for module members.
  • Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
  • Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
  • Otherwise, the object is public.

member_is_exported ¤

member_is_exported(
    member: Object | Alias, *, explicitely: bool = True
) -> bool

Whether a member of this object is "exported".

By exported, we mean that the object is included in the __all__ attribute of its parent module or class. When __all__ is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.

Parameters:

  • member (Object | Alias) –

    The member to verify.

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

mro ¤

mro() -> list[Class]

Return a list of classes in order corresponding to Python's MRO.

resolve ¤

resolve(name: str) -> str

Resolve a name within this object's and parents' scope.

Parameters:

  • name (str) –

    The name to resolve.

Raises:

Returns:

  • str

    The resolved name.

set_member ¤

set_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Parameters:

Examples:

>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)

Decorator ¤

Decorator(
    value: str | Expr,
    *,
    lineno: int | None,
    endlineno: int | None
)

This class represents decorators.

Parameters:

  • value (str | Expr) –

    The decorator code.

  • lineno (int | None) –

    The starting line number.

  • endlineno (int | None) –

    The ending line number.

Methods:

  • as_dict

    Return this decorator's data as a dictionary.

Attributes:

  • callable_path (str) –

    The path of the callable used as decorator.

  • endlineno (int | None) –

    The ending line number of the decorator.

  • lineno (int | None) –

    The starting line number of the decorator.

  • value (str | Expr) –

    The decorator value (as a Griffe expression or string).

callable_path property ¤

callable_path: str

The path of the callable used as decorator.

endlineno instance-attribute ¤

endlineno: int | None = endlineno

The ending line number of the decorator.

lineno instance-attribute ¤

lineno: int | None = lineno

The starting line number of the decorator.

value instance-attribute ¤

value: str | Expr = value

The decorator value (as a Griffe expression or string).

as_dict ¤

as_dict(**kwargs: Any) -> dict[str, Any]

Return this decorator's data as a dictionary.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

Docstring ¤

Docstring(
    value: str,
    *,
    lineno: int | None = None,
    endlineno: int | None = None,
    parent: Object | None = None,
    parser: (
        Literal["google", "numpy", "sphinx"] | Parser | None
    ) = None,
    parser_options: dict[str, Any] | None = None
)

This class represents docstrings.

Parameters:

  • value (str) –

    The docstring value.

  • lineno (int | None, default: None ) –

    The starting line number.

  • endlineno (int | None, default: None ) –

    The ending line number.

  • parent (Object | None, default: None ) –

    The parent object on which this docstring is attached.

  • parser (Literal['google', 'numpy', 'sphinx'] | Parser | None, default: None ) –

    The docstring parser to use. By default, no parsing is done.

  • parser_options (dict[str, Any] | None, default: None ) –

    Additional docstring parsing options.

Methods:

  • as_dict

    Return this docstring's data as a dictionary.

  • parse

    Parse the docstring into structured data.

Attributes:

endlineno instance-attribute ¤

endlineno: int | None = endlineno

The ending line number of the docstring.

lineno instance-attribute ¤

lineno: int | None = lineno

The starting line number of the docstring.

lines property ¤

lines: list[str]

The lines of the docstring.

parent instance-attribute ¤

parent: Object | None = parent

The object this docstring is attached to.

parsed cached property ¤

The docstring sections, parsed into structured data.

parser instance-attribute ¤

parser: (
    Literal["google", "numpy", "sphinx"] | Parser | None
) = parser

The selected docstring parser.

parser_options instance-attribute ¤

parser_options: dict[str, Any] = parser_options or {}

The configured parsing options.

value instance-attribute ¤

value: str = cleandoc(rstrip())

The original value of the docstring, cleaned by inspect.cleandoc.

as_dict ¤

as_dict(
    *,
    full: bool = False,
    docstring_parser: Parser | None = None,
    **kwargs: Any
) -> dict[str, Any]

Return this docstring's data as a dictionary.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • docstring_parser (Parser | None, default: None ) –

    Deprecated. The docstring parser to parse the docstring with. By default, no parsing is done.

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

parse ¤

parse(
    parser: (
        Literal["google", "numpy", "sphinx"] | Parser | None
    ) = None,
    **options: Any
) -> list[DocstringSection]

Parse the docstring into structured data.

Parameters:

  • parser (Literal['google', 'numpy', 'sphinx'] | Parser | None, default: None ) –

    The docstring parser to use. In order: use the given parser, or the self parser, or no parser (return a single text section).

  • **options (Any, default: {} ) –

    Additional docstring parsing options.

Returns:

Function ¤

Function(
    *args: Any,
    parameters: Parameters | None = None,
    returns: str | Expr | None = None,
    decorators: list[Decorator] | None = None,
    **kwargs: Any
)

          flowchart TD
          griffe.dataclasses.Function[Function]
          griffe.dataclasses.Object[Object]
          griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
          griffe.mixins.GetMembersMixin[GetMembersMixin]
          griffe.mixins.SetMembersMixin[SetMembersMixin]
          griffe.mixins.DelMembersMixin[DelMembersMixin]
          griffe.mixins.SerializationMixin[SerializationMixin]

                        griffe.dataclasses.Object --> griffe.dataclasses.Function
                            griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
                            griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
              




          click griffe.dataclasses.Function href "" "griffe.dataclasses.Function"
          click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
          click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
          click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
          click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
          click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
          click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
          

The class representing a Python function.

Parameters:

Methods:

  • __delitem__

    Delete a member with its name or path.

  • __getitem__

    Get a member with its name or path.

  • __setitem__

    Set a member with its name or path.

  • as_dict

    Return this function's data as a dictionary.

  • as_json

    Return this object's data as a JSON string.

  • del_member

    Delete a member with its name or path.

  • filter_members

    Filter and return members based on predicates.

  • from_json

    Create an instance of this class from a JSON string.

  • get_member

    Get a member with its name or path.

  • has_labels

    Tell if this object has all the given labels.

  • is_exported

    Tell if this object/alias is implicitely exported by its parent.

  • is_kind

    Tell if this object is of the given kind.

  • is_public

    Whether this object is considered public.

  • member_is_exported

    Whether a member of this object is "exported".

  • resolve

    Resolve a name within this object's and parents' scope.

  • set_member

    Set a member with its name or path.

Attributes:

aliases instance-attribute ¤

aliases: dict[str, Alias] = {}

The aliases pointing to this object.

all_members property ¤

all_members: dict[str, Object | Alias]

All members (declared and inherited).

This method is part of the consumer API: do not use when producing Griffe trees!

annotation property ¤

annotation: str | Expr | None

The type annotation of the returned value.

attributes property ¤

attributes: dict[str, Attribute]

The attribute members.

This method is part of the consumer API: do not use when producing Griffe trees!

canonical_path property ¤

canonical_path: str

The full dotted path of this object.

The canonical path is the path where the object was defined (not imported).

classes property ¤

classes: dict[str, Class]

The class members.

This method is part of the consumer API: do not use when producing Griffe trees!

decorators instance-attribute ¤

decorators: list[Decorator] = decorators or []

The function decorators.

deleter instance-attribute ¤

deleter: Function | None = None

The deleter linked to this function (property).

docstring instance-attribute ¤

docstring: Docstring | None = docstring

The object docstring.

endlineno instance-attribute ¤

endlineno: int | None = endlineno

The ending line number of the object.

exports instance-attribute ¤

exports: set[str] | list[str | ExprName] | None = None

The names of the objects exported by this (module) object through the __all__ variable.

Exports can contain string (object names) or resolvable names, like other lists of exports coming from submodules:

from .submodule import __all__ as submodule_all

__all__ = ["hello", *submodule_all]

Exports get expanded by the loader before it expands wildcards and resolves aliases.

extra instance-attribute ¤

Namespaced dictionaries storing extra metadata for this object, used by extensions.

filepath property ¤

filepath: Path | list[Path]

The file path (or directory list for namespace packages) where this object was defined.

functions property ¤

functions: dict[str, Function]

The function members.

This method is part of the consumer API: do not use when producing Griffe trees!

has_docstring property ¤

has_docstring: bool

Whether this object has a docstring (empty or not).

has_docstrings property ¤

has_docstrings: bool

Whether this object or any of its members has a docstring (empty or not).

imports instance-attribute ¤

imports: dict[str, str] = {}

The other objects imported by this object.

Keys are the names within the object (from ... import ... as AS_NAME), while the values are the actual names of the objects (from ... import REAL_NAME as ...).

inherited class-attribute instance-attribute ¤

inherited: bool = False

Whether this object (alias) is inherited.

Objects can never be inherited, only aliases can.

inherited_members cached property ¤

inherited_members: dict[str, Alias]

Members that are inherited from base classes.

This method is part of the consumer API: do not use when producing Griffe trees!

is_alias class-attribute instance-attribute ¤

is_alias: bool = False

Whether this object is an alias.

is_attribute property ¤

is_attribute: bool

Whether this object is an attribute.

is_class property ¤

is_class: bool

Whether this object is a class.

is_collection class-attribute instance-attribute ¤

is_collection: bool = False

Whether this object is a (modules) collection.

is_explicitely_exported property ¤

is_explicitely_exported: bool

Whether this object/alias is explicitely exported by its parent.

is_function property ¤

is_function: bool

Whether this object is a function.

is_implicitely_exported property ¤

is_implicitely_exported: bool

Whether this object/alias is implicitely exported by its parent.

is_init_module property ¤

is_init_module: bool

Whether this object is an __init__.py module.

is_module property ¤

is_module: bool

Whether this object is a module.

is_namespace_package property ¤

is_namespace_package: bool

Whether this object is a namespace package (top folder, no __init__.py).

is_namespace_subpackage property ¤

is_namespace_subpackage: bool

Whether this object is a namespace subpackage.

is_package property ¤

is_package: bool

Whether this object is a package (top module).

is_subpackage property ¤

is_subpackage: bool

Whether this object is a subpackage.

kind class-attribute instance-attribute ¤

kind = FUNCTION

The object kind.

labels instance-attribute ¤

labels: set[str] = set()

The object labels (property, dataclass, etc.).

lineno instance-attribute ¤

lineno: int | None = lineno

The starting line number of the object.

lines property ¤

lines: list[str]

The lines containing the source of this object.

lines_collection property ¤

lines_collection: LinesCollection

The lines collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

members instance-attribute ¤

members: dict[str, Object | Alias] = {}

The object members (modules, classes, functions, attributes).

module property ¤

module: Module

The parent module of this object.

Raises:

  • ValueError

    When the object is not a module and does not have a parent.

modules property ¤

modules: dict[str, Module]

The module members.

This method is part of the consumer API: do not use when producing Griffe trees!

modules_collection property ¤

modules_collection: ModulesCollection

The modules collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

name instance-attribute ¤

name: str = name

The object name.

overloads instance-attribute ¤

overloads: list[Function] | None = None

The overloaded signatures of this function.

package property ¤

package: Module

The absolute top module (the package) of this object.

parameters instance-attribute ¤

parameters: Parameters = parameters or Parameters()

The function parameters.

parent instance-attribute ¤

parent: Module | Class | None = parent

The parent of the object (none if top module).

path property ¤

path: str

The dotted path of this object.

On regular objects (not aliases), the path is the canonical path.

public instance-attribute ¤

public: bool | None = None

Whether this object is public.

relative_filepath property ¤

relative_filepath: Path

The file path where this object was defined, relative to the current working directory.

If this object's file path is not relative to the current working directory, return its absolute path.

Raises:

  • ValueError

    When the relative path could not be computed.

relative_package_filepath property ¤

relative_package_filepath: Path

The file path where this object was defined, relative to the top module path.

Raises:

  • ValueError

    When the relative path could not be computed.

returns instance-attribute ¤

returns: str | Expr | None = returns

The function return type annotation.

runtime instance-attribute ¤

runtime: bool = runtime

Whether this object is available at runtime.

Typically, type-guarded objects (under an if TYPE_CHECKING condition) are not available at runtime.

setter instance-attribute ¤

setter: Function | None = None

The setter linked to this function (property).

source property ¤

source: str

The source code of this object.

__delitem__ ¤

__delitem__(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]

__getitem__ ¤

__getitem__(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]

__setitem__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Parameters:

Examples:

>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux

as_dict ¤

as_dict(**kwargs: Any) -> dict[str, Any]

Return this function's data as a dictionary.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

as_json ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this object's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

del_member ¤

del_member(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))

filter_members ¤

filter_members(
    *predicates: Callable[[Object | Alias], bool]
) -> dict[str, Object | Alias]

Filter and return members based on predicates.

Parameters:

  • *predicates (Callable[[Object | Alias], bool], default: () ) –

    A list of predicates, i.e. callables accepting a member as argument and returning a boolean.

Returns:

from_json classmethod ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

get_member ¤

get_member(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]

has_labels ¤

has_labels(labels: set[str]) -> bool

Tell if this object has all the given labels.

Parameters:

  • labels (set[str]) –

    A set of labels.

Returns:

  • bool

    True or False.

is_exported ¤

is_exported(*, explicitely: bool = True) -> bool

Tell if this object/alias is implicitely exported by its parent.

Parameters:

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

is_kind ¤

is_kind(kind: str | Kind | set[str | Kind]) -> bool

Tell if this object is of the given kind.

Parameters:

  • kind (str | Kind | set[str | Kind]) –

    An instance or set of kinds (strings or enumerations).

Raises:

  • ValueError

    When an empty set is given as argument.

Returns:

  • bool

    True or False.

is_public ¤

is_public(
    *, strict: bool = False, check_name: bool = True
) -> bool

Whether this object is considered public.

In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.

Therefore, to decide whether an object is public, we follow this algorithm:

  • If the object's public attribute is set (boolean), return its value.
  • In strict mode, the object is public only if it is explicitely exported (listed in __all__). Strict mode should only be used for module members.
  • Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
  • Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
  • Otherwise, the object is public.

member_is_exported ¤

member_is_exported(
    member: Object | Alias, *, explicitely: bool = True
) -> bool

Whether a member of this object is "exported".

By exported, we mean that the object is included in the __all__ attribute of its parent module or class. When __all__ is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.

Parameters:

  • member (Object | Alias) –

    The member to verify.

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

resolve ¤

resolve(name: str) -> str

Resolve a name within this object's and parents' scope.

Parameters:

  • name (str) –

    The name to resolve.

Raises:

Returns:

  • str

    The resolved name.

set_member ¤

set_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Parameters:

Examples:

>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)

Kind ¤


          flowchart TD
          griffe.dataclasses.Kind[Kind]

          

          click griffe.dataclasses.Kind href "" "griffe.dataclasses.Kind"
          

Enumeration of the different object kinds.

Attributes:

ALIAS class-attribute instance-attribute ¤

ALIAS: str = 'alias'

Aliases (imported objects).

ATTRIBUTE class-attribute instance-attribute ¤

ATTRIBUTE: str = 'attribute'

Attributes and properties.

CLASS class-attribute instance-attribute ¤

CLASS: str = 'class'

Classes.

FUNCTION class-attribute instance-attribute ¤

FUNCTION: str = 'function'

Functions and methods.

MODULE class-attribute instance-attribute ¤

MODULE: str = 'module'

Modules.

Module ¤

Module(
    *args: Any,
    filepath: Path | list[Path] | None = None,
    **kwargs: Any
)

          flowchart TD
          griffe.dataclasses.Module[Module]
          griffe.dataclasses.Object[Object]
          griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
          griffe.mixins.GetMembersMixin[GetMembersMixin]
          griffe.mixins.SetMembersMixin[SetMembersMixin]
          griffe.mixins.DelMembersMixin[DelMembersMixin]
          griffe.mixins.SerializationMixin[SerializationMixin]

                        griffe.dataclasses.Object --> griffe.dataclasses.Module
                            griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
                            griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
              




          click griffe.dataclasses.Module href "" "griffe.dataclasses.Module"
          click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
          click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
          click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
          click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
          click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
          click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
          

The class representing a Python module.

Parameters:

Methods:

  • __delitem__

    Delete a member with its name or path.

  • __getitem__

    Get a member with its name or path.

  • __setitem__

    Set a member with its name or path.

  • as_dict

    Return this module's data as a dictionary.

  • as_json

    Return this object's data as a JSON string.

  • del_member

    Delete a member with its name or path.

  • filter_members

    Filter and return members based on predicates.

  • from_json

    Create an instance of this class from a JSON string.

  • get_member

    Get a member with its name or path.

  • has_labels

    Tell if this object has all the given labels.

  • is_exported

    Tell if this object/alias is implicitely exported by its parent.

  • is_kind

    Tell if this object is of the given kind.

  • is_public

    Whether this object is considered public.

  • member_is_exported

    Whether a member of this object is "exported".

  • resolve

    Resolve a name within this object's and parents' scope.

  • set_member

    Set a member with its name or path.

Attributes:

aliases instance-attribute ¤

aliases: dict[str, Alias] = {}

The aliases pointing to this object.

all_members property ¤

all_members: dict[str, Object | Alias]

All members (declared and inherited).

This method is part of the consumer API: do not use when producing Griffe trees!

attributes property ¤

attributes: dict[str, Attribute]

The attribute members.

This method is part of the consumer API: do not use when producing Griffe trees!

canonical_path property ¤

canonical_path: str

The full dotted path of this object.

The canonical path is the path where the object was defined (not imported).

classes property ¤

classes: dict[str, Class]

The class members.

This method is part of the consumer API: do not use when producing Griffe trees!

docstring instance-attribute ¤

docstring: Docstring | None = docstring

The object docstring.

endlineno instance-attribute ¤

endlineno: int | None = endlineno

The ending line number of the object.

exports instance-attribute ¤

exports: set[str] | list[str | ExprName] | None = None

The names of the objects exported by this (module) object through the __all__ variable.

Exports can contain string (object names) or resolvable names, like other lists of exports coming from submodules:

from .submodule import __all__ as submodule_all

__all__ = ["hello", *submodule_all]

Exports get expanded by the loader before it expands wildcards and resolves aliases.

extra instance-attribute ¤

Namespaced dictionaries storing extra metadata for this object, used by extensions.

filepath property ¤

filepath: Path | list[Path]

The file path of this module.

Raises:

functions property ¤

functions: dict[str, Function]

The function members.

This method is part of the consumer API: do not use when producing Griffe trees!

has_docstring property ¤

has_docstring: bool

Whether this object has a docstring (empty or not).

has_docstrings property ¤

has_docstrings: bool

Whether this object or any of its members has a docstring (empty or not).

imports instance-attribute ¤

imports: dict[str, str] = {}

The other objects imported by this object.

Keys are the names within the object (from ... import ... as AS_NAME), while the values are the actual names of the objects (from ... import REAL_NAME as ...).

imports_future_annotations property ¤

imports_future_annotations: bool

Whether this module import future annotations.

inherited class-attribute instance-attribute ¤

inherited: bool = False

Whether this object (alias) is inherited.

Objects can never be inherited, only aliases can.

inherited_members cached property ¤

inherited_members: dict[str, Alias]

Members that are inherited from base classes.

This method is part of the consumer API: do not use when producing Griffe trees!

is_alias class-attribute instance-attribute ¤

is_alias: bool = False

Whether this object is an alias.

is_attribute property ¤

is_attribute: bool

Whether this object is an attribute.

is_class property ¤

is_class: bool

Whether this object is a class.

is_collection class-attribute instance-attribute ¤

is_collection: bool = False

Whether this object is a (modules) collection.

is_explicitely_exported property ¤

is_explicitely_exported: bool

Whether this object/alias is explicitely exported by its parent.

is_function property ¤

is_function: bool

Whether this object is a function.

is_implicitely_exported property ¤

is_implicitely_exported: bool

Whether this object/alias is implicitely exported by its parent.

is_init_module property ¤

is_init_module: bool

Whether this module is an __init__.py module.

is_module property ¤

is_module: bool

Whether this object is a module.

is_namespace_package property ¤

is_namespace_package: bool

Whether this module is a namespace package (top folder, no __init__.py).

is_namespace_subpackage property ¤

is_namespace_subpackage: bool

Whether this module is a namespace subpackage.

is_package property ¤

is_package: bool

Whether this module is a package (top module).

is_subpackage property ¤

is_subpackage: bool

Whether this module is a subpackage.

kind class-attribute instance-attribute ¤

kind = MODULE

The object kind.

labels instance-attribute ¤

labels: set[str] = set()

The object labels (property, dataclass, etc.).

lineno instance-attribute ¤

lineno: int | None = lineno

The starting line number of the object.

lines property ¤

lines: list[str]

The lines containing the source of this object.

lines_collection property ¤

lines_collection: LinesCollection

The lines collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

members instance-attribute ¤

members: dict[str, Object | Alias] = {}

The object members (modules, classes, functions, attributes).

module property ¤

module: Module

The parent module of this object.

Raises:

  • ValueError

    When the object is not a module and does not have a parent.

modules property ¤

modules: dict[str, Module]

The module members.

This method is part of the consumer API: do not use when producing Griffe trees!

modules_collection property ¤

modules_collection: ModulesCollection

The modules collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

name instance-attribute ¤

name: str = name

The object name.

overloads instance-attribute ¤

overloads: dict[str, list[Function]] = defaultdict(list)

The overloaded signature declared in this module.

package property ¤

package: Module

The absolute top module (the package) of this object.

parent instance-attribute ¤

parent: Module | Class | None = parent

The parent of the object (none if top module).

path property ¤

path: str

The dotted path of this object.

On regular objects (not aliases), the path is the canonical path.

public instance-attribute ¤

public: bool | None = None

Whether this object is public.

relative_filepath property ¤

relative_filepath: Path

The file path where this object was defined, relative to the current working directory.

If this object's file path is not relative to the current working directory, return its absolute path.

Raises:

  • ValueError

    When the relative path could not be computed.

relative_package_filepath property ¤

relative_package_filepath: Path

The file path where this object was defined, relative to the top module path.

Raises:

  • ValueError

    When the relative path could not be computed.

runtime instance-attribute ¤

runtime: bool = runtime

Whether this object is available at runtime.

Typically, type-guarded objects (under an if TYPE_CHECKING condition) are not available at runtime.

source property ¤

source: str

The source code of this object.

__delitem__ ¤

__delitem__(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]

__getitem__ ¤

__getitem__(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]

__setitem__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Parameters:

Examples:

>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux

as_dict ¤

as_dict(**kwargs: Any) -> dict[str, Any]

Return this module's data as a dictionary.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

as_json ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this object's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

del_member ¤

del_member(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))

filter_members ¤

filter_members(
    *predicates: Callable[[Object | Alias], bool]
) -> dict[str, Object | Alias]

Filter and return members based on predicates.

Parameters:

  • *predicates (Callable[[Object | Alias], bool], default: () ) –

    A list of predicates, i.e. callables accepting a member as argument and returning a boolean.

Returns:

from_json classmethod ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

get_member ¤

get_member(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]

has_labels ¤

has_labels(labels: set[str]) -> bool

Tell if this object has all the given labels.

Parameters:

  • labels (set[str]) –

    A set of labels.

Returns:

  • bool

    True or False.

is_exported ¤

is_exported(*, explicitely: bool = True) -> bool

Tell if this object/alias is implicitely exported by its parent.

Parameters:

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

is_kind ¤

is_kind(kind: str | Kind | set[str | Kind]) -> bool

Tell if this object is of the given kind.

Parameters:

  • kind (str | Kind | set[str | Kind]) –

    An instance or set of kinds (strings or enumerations).

Raises:

  • ValueError

    When an empty set is given as argument.

Returns:

  • bool

    True or False.

is_public ¤

is_public(
    *, strict: bool = False, check_name: bool = True
) -> bool

Whether this object is considered public.

In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.

Therefore, to decide whether an object is public, we follow this algorithm:

  • If the object's public attribute is set (boolean), return its value.
  • In strict mode, the object is public only if it is explicitely exported (listed in __all__). Strict mode should only be used for module members.
  • Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
  • Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
  • Otherwise, the object is public.

member_is_exported ¤

member_is_exported(
    member: Object | Alias, *, explicitely: bool = True
) -> bool

Whether a member of this object is "exported".

By exported, we mean that the object is included in the __all__ attribute of its parent module or class. When __all__ is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.

Parameters:

  • member (Object | Alias) –

    The member to verify.

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

resolve ¤

resolve(name: str) -> str

Resolve a name within this object's and parents' scope.

Parameters:

  • name (str) –

    The name to resolve.

Raises:

Returns:

  • str

    The resolved name.

set_member ¤

set_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Parameters:

Examples:

>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)

Object ¤

Object(
    name: str,
    *,
    lineno: int | None = None,
    endlineno: int | None = None,
    runtime: bool = True,
    docstring: Docstring | None = None,
    parent: Module | Class | None = None,
    lines_collection: LinesCollection | None = None,
    modules_collection: ModulesCollection | None = None
)

          flowchart TD
          griffe.dataclasses.Object[Object]
          griffe.mixins.ObjectAliasMixin[ObjectAliasMixin]
          griffe.mixins.GetMembersMixin[GetMembersMixin]
          griffe.mixins.SetMembersMixin[SetMembersMixin]
          griffe.mixins.DelMembersMixin[DelMembersMixin]
          griffe.mixins.SerializationMixin[SerializationMixin]

                        griffe.mixins.ObjectAliasMixin --> griffe.dataclasses.Object
                            griffe.mixins.GetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SetMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.DelMembersMixin --> griffe.mixins.ObjectAliasMixin
              
              griffe.mixins.SerializationMixin --> griffe.mixins.ObjectAliasMixin
              



          click griffe.dataclasses.Object href "" "griffe.dataclasses.Object"
          click griffe.mixins.ObjectAliasMixin href "" "griffe.mixins.ObjectAliasMixin"
          click griffe.mixins.GetMembersMixin href "" "griffe.mixins.GetMembersMixin"
          click griffe.mixins.SetMembersMixin href "" "griffe.mixins.SetMembersMixin"
          click griffe.mixins.DelMembersMixin href "" "griffe.mixins.DelMembersMixin"
          click griffe.mixins.SerializationMixin href "" "griffe.mixins.SerializationMixin"
          

An abstract class representing a Python object.

Parameters:

  • name (str) –

    The object name, as declared in the code.

  • lineno (int | None, default: None ) –

    The object starting line, or None for modules. Lines start at 1.

  • endlineno (int | None, default: None ) –

    The object ending line (inclusive), or None for modules.

  • runtime (bool, default: True ) –

    Whether this object is present at runtime or not.

  • docstring (Docstring | None, default: None ) –

    The object docstring.

  • parent (Module | Class | None, default: None ) –

    The object parent.

  • lines_collection (LinesCollection | None, default: None ) –

    A collection of source code lines.

  • modules_collection (ModulesCollection | None, default: None ) –

    A collection of modules.

Methods:

  • __delitem__

    Delete a member with its name or path.

  • __getitem__

    Get a member with its name or path.

  • __setitem__

    Set a member with its name or path.

  • as_dict

    Return this object's data as a dictionary.

  • as_json

    Return this object's data as a JSON string.

  • del_member

    Delete a member with its name or path.

  • filter_members

    Filter and return members based on predicates.

  • from_json

    Create an instance of this class from a JSON string.

  • get_member

    Get a member with its name or path.

  • has_labels

    Tell if this object has all the given labels.

  • is_exported

    Tell if this object/alias is implicitely exported by its parent.

  • is_kind

    Tell if this object is of the given kind.

  • is_public

    Whether this object is considered public.

  • member_is_exported

    Whether a member of this object is "exported".

  • resolve

    Resolve a name within this object's and parents' scope.

  • set_member

    Set a member with its name or path.

Attributes:

aliases instance-attribute ¤

aliases: dict[str, Alias] = {}

The aliases pointing to this object.

all_members property ¤

all_members: dict[str, Object | Alias]

All members (declared and inherited).

This method is part of the consumer API: do not use when producing Griffe trees!

attributes property ¤

attributes: dict[str, Attribute]

The attribute members.

This method is part of the consumer API: do not use when producing Griffe trees!

canonical_path property ¤

canonical_path: str

The full dotted path of this object.

The canonical path is the path where the object was defined (not imported).

classes property ¤

classes: dict[str, Class]

The class members.

This method is part of the consumer API: do not use when producing Griffe trees!

docstring instance-attribute ¤

docstring: Docstring | None = docstring

The object docstring.

endlineno instance-attribute ¤

endlineno: int | None = endlineno

The ending line number of the object.

exports instance-attribute ¤

exports: set[str] | list[str | ExprName] | None = None

The names of the objects exported by this (module) object through the __all__ variable.

Exports can contain string (object names) or resolvable names, like other lists of exports coming from submodules:

from .submodule import __all__ as submodule_all

__all__ = ["hello", *submodule_all]

Exports get expanded by the loader before it expands wildcards and resolves aliases.

extra instance-attribute ¤

Namespaced dictionaries storing extra metadata for this object, used by extensions.

filepath property ¤

filepath: Path | list[Path]

The file path (or directory list for namespace packages) where this object was defined.

functions property ¤

functions: dict[str, Function]

The function members.

This method is part of the consumer API: do not use when producing Griffe trees!

has_docstring property ¤

has_docstring: bool

Whether this object has a docstring (empty or not).

has_docstrings property ¤

has_docstrings: bool

Whether this object or any of its members has a docstring (empty or not).

imports instance-attribute ¤

imports: dict[str, str] = {}

The other objects imported by this object.

Keys are the names within the object (from ... import ... as AS_NAME), while the values are the actual names of the objects (from ... import REAL_NAME as ...).

inherited class-attribute instance-attribute ¤

inherited: bool = False

Whether this object (alias) is inherited.

Objects can never be inherited, only aliases can.

inherited_members cached property ¤

inherited_members: dict[str, Alias]

Members that are inherited from base classes.

This method is part of the consumer API: do not use when producing Griffe trees!

is_alias class-attribute instance-attribute ¤

is_alias: bool = False

Whether this object is an alias.

is_attribute property ¤

is_attribute: bool

Whether this object is an attribute.

is_class property ¤

is_class: bool

Whether this object is a class.

is_collection class-attribute instance-attribute ¤

is_collection: bool = False

Whether this object is a (modules) collection.

is_explicitely_exported property ¤

is_explicitely_exported: bool

Whether this object/alias is explicitely exported by its parent.

is_function property ¤

is_function: bool

Whether this object is a function.

is_implicitely_exported property ¤

is_implicitely_exported: bool

Whether this object/alias is implicitely exported by its parent.

is_init_module property ¤

is_init_module: bool

Whether this object is an __init__.py module.

is_module property ¤

is_module: bool

Whether this object is a module.

is_namespace_package property ¤

is_namespace_package: bool

Whether this object is a namespace package (top folder, no __init__.py).

is_namespace_subpackage property ¤

is_namespace_subpackage: bool

Whether this object is a namespace subpackage.

is_package property ¤

is_package: bool

Whether this object is a package (top module).

is_subpackage property ¤

is_subpackage: bool

Whether this object is a subpackage.

kind instance-attribute ¤

kind: Kind

The object kind.

labels instance-attribute ¤

labels: set[str] = set()

The object labels (property, dataclass, etc.).

lineno instance-attribute ¤

lineno: int | None = lineno

The starting line number of the object.

lines property ¤

lines: list[str]

The lines containing the source of this object.

lines_collection property ¤

lines_collection: LinesCollection

The lines collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

members instance-attribute ¤

members: dict[str, Object | Alias] = {}

The object members (modules, classes, functions, attributes).

module property ¤

module: Module

The parent module of this object.

Raises:

  • ValueError

    When the object is not a module and does not have a parent.

modules property ¤

modules: dict[str, Module]

The module members.

This method is part of the consumer API: do not use when producing Griffe trees!

modules_collection property ¤

modules_collection: ModulesCollection

The modules collection attached to this object or its parents.

Raises:

  • ValueError

    When no modules collection can be found in the object or its parents.

name instance-attribute ¤

name: str = name

The object name.

package property ¤

package: Module

The absolute top module (the package) of this object.

parent instance-attribute ¤

parent: Module | Class | None = parent

The parent of the object (none if top module).

path property ¤

path: str

The dotted path of this object.

On regular objects (not aliases), the path is the canonical path.

public instance-attribute ¤

public: bool | None = None

Whether this object is public.

relative_filepath property ¤

relative_filepath: Path

The file path where this object was defined, relative to the current working directory.

If this object's file path is not relative to the current working directory, return its absolute path.

Raises:

  • ValueError

    When the relative path could not be computed.

relative_package_filepath property ¤

relative_package_filepath: Path

The file path where this object was defined, relative to the top module path.

Raises:

  • ValueError

    When the relative path could not be computed.

runtime instance-attribute ¤

runtime: bool = runtime

Whether this object is available at runtime.

Typically, type-guarded objects (under an if TYPE_CHECKING condition) are not available at runtime.

source property ¤

source: str

The source code of this object.

__delitem__ ¤

__delitem__(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> del griffe_object["foo"]
>>> del griffe_object["path.to.bar"]
>>> del griffe_object[("path", "to", "qux")]

__getitem__ ¤

__getitem__(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Members will be looked up in both declared members and inherited ones, triggering computation of the latter.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> qux = griffe_object[("path", "to", "qux")]

__setitem__ ¤

__setitem__(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the consumer API: do not use when producing Griffe trees!

Parameters:

Examples:

>>> griffe_object["foo"] = foo
>>> griffe_object["path.to.bar"] = bar
>>> griffe_object[("path", "to", "qux")] = qux

as_dict ¤

as_dict(
    *, full: bool = False, **kwargs: Any
) -> dict[str, Any]

Return this object's data as a dictionary.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

as_json ¤

as_json(*, full: bool = False, **kwargs: Any) -> str

Return this object's data as a JSON string.

Parameters:

  • full (bool, default: False ) –

    Whether to return full info, or just base info.

  • **kwargs (Any, default: {} ) –

    Additional serialization options passed to encoder.

Returns:

  • str

    A JSON string.

del_member ¤

del_member(key: str | Sequence[str]) -> None

Delete a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> griffe_object.del_member("foo")
>>> griffe_object.del_member("path.to.bar")
>>> griffe_object.del_member(("path", "to", "qux"))

filter_members ¤

filter_members(
    *predicates: Callable[[Object | Alias], bool]
) -> dict[str, Object | Alias]

Filter and return members based on predicates.

Parameters:

  • *predicates (Callable[[Object | Alias], bool], default: () ) –

    A list of predicates, i.e. callables accepting a member as argument and returning a boolean.

Returns:

from_json classmethod ¤

from_json(json_string: str, **kwargs: Any) -> _ObjType

Create an instance of this class from a JSON string.

Parameters:

  • json_string (str) –

    JSON to decode into Object.

  • **kwargs (Any, default: {} ) –

    Additional options passed to decoder.

Returns:

  • _ObjType

    An Object instance.

Raises:

  • TypeError

    When the json_string does not represent and object of the class from which this classmethod has been called.

get_member ¤

get_member(key: str | Sequence[str]) -> Any

Get a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Members will be looked up in declared members only, not inherited ones.

Parameters:

Examples:

>>> foo = griffe_object["foo"]
>>> bar = griffe_object["path.to.bar"]
>>> bar = griffe_object[("path", "to", "bar")]

has_labels ¤

has_labels(labels: set[str]) -> bool

Tell if this object has all the given labels.

Parameters:

  • labels (set[str]) –

    A set of labels.

Returns:

  • bool

    True or False.

is_exported ¤

is_exported(*, explicitely: bool = True) -> bool

Tell if this object/alias is implicitely exported by its parent.

Parameters:

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

is_kind ¤

is_kind(kind: str | Kind | set[str | Kind]) -> bool

Tell if this object is of the given kind.

Parameters:

  • kind (str | Kind | set[str | Kind]) –

    An instance or set of kinds (strings or enumerations).

Raises:

  • ValueError

    When an empty set is given as argument.

Returns:

  • bool

    True or False.

is_public ¤

is_public(
    *, strict: bool = False, check_name: bool = True
) -> bool

Whether this object is considered public.

In modules, developers can mark objects as public thanks to the __all__ variable. In classes however, there is no convention or standard to do so.

Therefore, to decide whether an object is public, we follow this algorithm:

  • If the object's public attribute is set (boolean), return its value.
  • In strict mode, the object is public only if it is explicitely exported (listed in __all__). Strict mode should only be used for module members.
  • Otherwise, if name checks are enabled, the object is private if its name starts with an underscore.
  • Otherwise, if the object is an alias, and is neither inherited from a base class, nor a member of a parent alias, it is not public.
  • Otherwise, the object is public.

member_is_exported ¤

member_is_exported(
    member: Object | Alias, *, explicitely: bool = True
) -> bool

Whether a member of this object is "exported".

By exported, we mean that the object is included in the __all__ attribute of its parent module or class. When __all__ is not defined, we consider the member to be implicitely exported, unless it's a module and it was not imported, and unless it's not defined at runtime.

Parameters:

  • member (Object | Alias) –

    The member to verify.

  • explicitely (bool, default: True ) –

    Whether to only return True when __all__ is defined.

Returns:

  • bool

    True or False.

resolve ¤

resolve(name: str) -> str

Resolve a name within this object's and parents' scope.

Parameters:

  • name (str) –

    The name to resolve.

Raises:

Returns:

  • str

    The resolved name.

set_member ¤

set_member(
    key: str | Sequence[str], value: Object | Alias
) -> None

Set a member with its name or path.

This method is part of the producer API: you can use it safely while building Griffe trees (for example in Griffe extensions).

Parameters:

Examples:

>>> griffe_object.set_member("foo", foo)
>>> griffe_object.set_member("path.to.bar", bar)
>>> griffe_object.set_member(("path", "to", "qux", qux)

Parameter ¤

Parameter(
    name: str,
    *,
    annotation: str | Expr | None = None,
    kind: ParameterKind | None = None,
    default: str | Expr | None = None
)

This class represent a function parameter.

Parameters:

  • name (str) –

    The parameter name.

  • annotation (str | Expr | None, default: None ) –

    The parameter annotation, if any.

  • kind (ParameterKind | None, default: None ) –

    The parameter kind.

  • default (str | Expr | None, default: None ) –

    The parameter default, if any.

Methods:

  • as_dict

    Return this parameter's data as a dictionary.

Attributes:

annotation instance-attribute ¤

annotation: str | Expr | None = annotation

The parameter type annotation.

default instance-attribute ¤

default: str | Expr | None = default

The parameter default value.

kind instance-attribute ¤

kind: ParameterKind | None = kind

The parameter kind.

name instance-attribute ¤

name: str = name

The parameter name.

required property ¤

required: bool

Whether this parameter is required.

as_dict ¤

as_dict(**kwargs: Any) -> dict[str, Any]

Return this parameter's data as a dictionary.

Parameters:

  • **kwargs (Any, default: {} ) –

    Additional serialization options.

Returns:

ParameterKind ¤


          flowchart TD
          griffe.dataclasses.ParameterKind[ParameterKind]

          

          click griffe.dataclasses.ParameterKind href "" "griffe.dataclasses.ParameterKind"
          

Enumeration of the different parameter kinds.

Attributes:

keyword_only class-attribute instance-attribute ¤

keyword_only: str = 'keyword-only'

Keyword-only parameter.

positional_only class-attribute instance-attribute ¤

positional_only: str = 'positional-only'

Positional-only parameter.

positional_or_keyword class-attribute instance-attribute ¤

positional_or_keyword: str = 'positional or keyword'

Positional or keyword parameter.

var_keyword class-attribute instance-attribute ¤

var_keyword: str = 'variadic keyword'

Variadic keyword parameter.

var_positional class-attribute instance-attribute ¤

var_positional: str = 'variadic positional'

Variadic positional parameter.

Parameters ¤

Parameters(*parameters: Parameter)

This class is a container for parameters.

It allows to get parameters using their position (index) or their name:

>>> parameters = Parameters(Parameter("hello"))
>>> parameters[0] is parameters["hello"]
True

Parameters:

  • *parameters (Parameter, default: () ) –

    The initial parameters to add to the container.

Methods:

  • add

    Add a parameter to the container.

add ¤

add(parameter: Parameter) -> None

Add a parameter to the container.

Parameters:

  • parameter (Parameter) –

    The function parameter to add.

Raises:

  • ValueError

    When a parameter with the same name is already present.