Services

These pages provide reference information for services provided by Craft Application.

Service factory API documentation

class craft_application.services.ServiceFactory

Factory class for lazy-loading service classes.

This class and its subclasses allow a craft application to only load the relevant services for the command that is being run.

This factory is intended to be extended with various additional service classes and possibly have its existing service classes overridden.

__init__(app: AppMetadata, **kwargs: type[services.AppService] | None) None
classmethod register(name: str, service_class: type[AppService] | str, *, module: str | None = None) None

Register a service class with a given name.

Parameters:
  • name – the name to call the service class.

  • service_class – either a service class or a string that names the service class.

  • module – If service_class is a string, the module from which to import the service class.

classmethod reset() None

Reset the registered services.

update_kwargs(service: str, **kwargs: Any) None

Update the keyword arguments to pass to a particular service class.

This works like dict.update(), overwriting already-set values.

Parameters:
  • service – the name of the service. For example, “lifecycle”.

  • kwargs – keyword arguments to set.

classmethod get_class(name: Literal['build_plan', 'BuildPlanService', 'BuildPlanClass']) type[BuildPlanService]
classmethod get_class(name: Literal['config', 'ConfigService', 'ConfigClass']) type[ConfigService]
classmethod get_class(name: Literal['fetch', 'FetchService', 'FetchClass']) type[FetchService]
classmethod get_class(name: Literal['init', 'InitService', 'InitClass']) type[InitService]
classmethod get_class(name: Literal['lifecycle', 'LifecycleService', 'LifecycleClass']) type[LifecycleService]
classmethod get_class(name: Literal['package', 'PackageService', 'PackageClass']) type[PackageService]
classmethod get_class(name: Literal['provider', 'ProviderService', 'ProviderClass']) type[ProviderService]
classmethod get_class(name: Literal['proxy', 'ProxyService', 'ProxyClass']) type[ProxyService]
classmethod get_class(name: Literal['remote_build', 'RemoteBuildService', 'RemoteBuildClass']) type[RemoteBuildService]
classmethod get_class(name: Literal['request', 'RequestService', 'RequestClass']) type[RequestService]
classmethod get_class(name: Literal['state', 'StateService', 'StateClass']) type[StateService]
classmethod get_class(name: Literal['testing', 'TestingService', 'TestingClass']) type[TestingService]
classmethod get_class(name: str) type[AppService]

Get the class for a service by its name.

get(service: Literal['build_plan']) BuildPlanService
get(service: Literal['config']) ConfigService
get(service: Literal['fetch']) FetchService
get(service: Literal['init']) InitService
get(service: Literal['package']) PackageService
get(service: Literal['lifecycle']) LifecycleService
get(service: Literal['project']) ProjectService
get(service: Literal['provider']) ProviderService
get(service: Literal['proxy']) ProxyService
get(service: Literal['remote_build']) RemoteBuildService
get(service: Literal['request']) RequestService
get(service: Literal['state']) StateService
get(service: Literal['testing']) TestingService
get(service: str) AppService

Get a service by name.

Also caches the service so as to provide a single service instance per ServiceFactory.

Parameters:

service – the name of the service. For example, “config”.

Returns:

An instantiated and setup service class.