cement.core.interface

Cement core interface module.

class cement.core.interface.Interface(**kw: Any)[source]

Bases: ABC, MetaMixin

Base interface class that all Cement Interfaces should subclass from.

class Meta[source]

Bases: object

Interface meta-data (can also be passed as keyword arguments to the parent class).

interface: str = NotImplemented

The string identifier of this interface.

_validate() None[source]

Perform any validation to ensure proper data, meta-data, etc.

class cement.core.interface.InterfaceManager(app: App)[source]

Bases: object

Manages the interface system to define, get, list interfaces with the Cement Framework.

define(ibc: Type[Interface]) None[source]

Define an ibc (interface base class).

Parameters:

ibc (Interface) – The abstract base class that defines the interface

Raises:

Example

app.interface.define(DatabaseInterface)
defined(interface: str) bool[source]

Test whether interface is defined.

Parameters:

interface (str) – The label of the interface (I.e. log, config, output, etc).

Returns:

True if the interface is defined, False otherwise

Return type:

bool

Example

app.interface.defined('log')
get(interface: str, fallback: Type[Interface] | None = None, **kwargs: Any) Type[Interface][source]

Get an interface class.

Parameters:
  • interface (str) – The interface label (i.e. output)

  • fallback (Handler) – A fallback value to return if interface doesn’t exist.

Returns:

An uninstantiated interface class

Return type:

Interface

Raises:

cement.core.exc.InterfaceError – If the interface does not exist.

Example

i = app.interface.get('output')
list() list[str][source]

Return a list of defined interfaces.

Returns:

Interface labels.

Return type:

list

Example

app.interface.list()