kerno.start module

Eko is the class used to start a Kerno application.

It works much like initial configuration of a Pyramid app.

class kerno.start.Eko(settings: Dict[str, Any] = {})[source]

Bases: object

At startup builds the Kerno instance for the app.

In the Esperanto language, Eko is a noun that means “a start”. And “eki” is a verb that means “to start”.

The Eko class can build an application core from multiple Python modules, much like the Configurator in Pyramid.

If the same module is included twice, Eko will raise kerno.start.ConfigurationError, helping you ensure your startup code stays clean.

Usage example:

from kerno.start import Eko
eko = Eko.from_ini('main_config.ini', 'production.ini')
eko.settings  # lets you access the merged settings from INI files
eko.kerno  # is the Kerno instance that will be the core of the app

eko.utilities.register('mailer', 'some.package:mailer_function')
# ...and later you can retrieve *mailer_function* by doing:
# kerno.utilities['mailer']

# This finds the function some.extension.package:eki() and runs it,
# passing it the eko configurator object:
eko.include('some.extension.package')

# For instance, here is how you can build a repository from 2 classes:
eko.include('kerno.repository')  # adds add_repository_mixin() to eko
eko.add_repository_mixin(
    'kerno.repository.sqlalchemy.BaseSQLAlchemyRepository')
eko.add_repository_mixin('my.package:MyRepoMixinClass')
# After this, the first time you access ``kerno.Repository``,
# the Repository class is assembled from the mixin classes,
# and stored for usage as kerno.Repository.

If you need to debug the order in which modules got included, you can:

print(*eko._included_modules, sep='\n')
classmethod from_ini(*config_files, encoding: str = 'utf-8')[source]

Return an instance after reading some INI file(s).

include(resource: Union[str, module, Callable], throw: bool = True) None[source]

Execute a configuration callable for imperative extension.

If the argument throw is True (which is the default) and resource does not have an eki() function, raise ConfigurationError. Otherwise, ignore the current module and return without an error.

include_many(resources: Iterable[Union[str, module, Callable]], throw: bool = True) None[source]

Initialize multiple app modules.