Concepts

These concepts can be used to extend and interact with precept applications.

Events

Generic asyncio event consumer system.

The Precept instance and services both comes with an event dispatcher (events member). You can subscribe to events and handle them when they happen.

Subscribe to events

Subscribe to events that are dispatched.

app.events.subscribe('cli_started', lambda e: print('Started'))

Dispatch events

Send events with optional payload as keyword arguments.

app.events.dispatch('my_events', something='foo')

cli events

These events are available when starting the application with start.

Cli events

Event

Description

before_cli_start

Called before everything else.

cli_parsed

Called after parsing the arguments and before the command start, payload with the arguments.

cli_started

The command has started, this is called at the same time.

cli_stopped

The command has stopped and the application will quit after.

Services

Service’s runs alongside the precept application, they are started and stopped at the same time when calling start().

Service events

Services comes with three auto events starting with the service name. If a service is called dummy, it will get:

  • dummy_setup, called with the running application before starting.

  • dummy_start, started before the application.

  • dummy_stop, stopped after the application.

Note

If the application is not started with start, you need to call the services methods:

  • setup_services

  • start_services

  • stop_services

See also

Plugins

Plugins automatically connect to precept applications during initialisation.

They have one method, setup(), which takes the application as argument you can use to set variables.

To add a plugin, you need to set it in setup.py, the entrypoint key needs to be the snake cased version of prog_name variable of the precept application.

from setuptools import setup

setup(
    entry_points={
        'precept_app.plugins': ['my_plugin = plug:plugin']
    }
)

See also