# Library API

The main objects are the `BusABC` and the `Message`. A form of CAN interface is also required.

Hint

Check the backend specific documentation for any implementation specific details.

- Bus
- Thread safe bus
- Message
- Listeners
- Asyncio support
- Broadcast Manager
- Internal API

## Utilities

## Notifier

The Notifier object is used as a message distributor for a bus.

class `can.``Notifier`(bus, listeners, timeout=1.0, loop=None)

  Bases: `object`

  Manages the distribution of `can.Message` instances to listeners.

  Supports multiple buses and listeners.

  Note

  Remember to call stop() after all messages are received as many listeners carry out flush operations to persist data.

  Parameters:

  - bus (can.BusABC) – A Bus or a list of buses to listen to.
  - listeners (list) – An iterable of `Listener`
  - timeout (float) – An optional maximum number of seconds to wait for any message.
  - loop (asyncio.AbstractEventLoop) – An `asyncio` event loop to schedule listeners in.

  `add_bus`(bus)

    Add a bus for notification.

    Parameters: | bus (can.BusABC) – CAN bus instance.

  `add_listener`(listener)

    Add new Listener to the notification list. If it is already present, it will be called two times each time a message arrives.

    Parameters: | listener (can.Listener) – Listener to be added to the list to be notified

  `exception` = None

    Exception raised in thread

  `remove_listener`(listener)

    Remove a listener from the notification list. This method trows an exception if the given listener is not part of the stored listeners.

    Parameters: | listener (can.Listener) – Listener to be removed from the list to be notified
    Raises: | ValueError – if listener was never added to this notifier

  `stop`(timeout=5)

    Stop notifying Listeners when new `Message` objects arrive and call `stop()` on each Listener.

    Parameters: | timeout (float) – Max time in seconds to wait for receive threads to finish. Should be longer than timeout given at instantiation.

## Errors

class `can.``CanError`

  Bases: `OSError`

  Indicates an error with the CAN network.