# 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
- Message
- Listeners
- Broadcast Manager

## Utilities

Utilities and configuration file parsing.

`can.util.``choose_socketcan_implementation`()

  Set the best version of SocketCAN for this system.

  Parameters: | config – The can.rc configuration dictionary
  Raises: | Exception – If the system doesn’t support SocketCAN

`can.util.``load_config`(path=None, config=None)

  Returns a dict with configuration details which is loaded from (in this order):

  - config
  - can.rc
  - Environment variables CAN_INTERFACE, CAN_CHANNEL, CAN_BITRATE
  - Config files `/etc/can.conf` or `~/.can` or `~/.canrc` where the latter may add or replace values of the former.

  Interface can be any of the strings from `can.VALID_INTERFACES` for example: kvaser, socketcan, pcan, usb2can, ixxat, nican, virtual.

  Note

  If you pass `"socketcan"` this automatically selects between the native and ctypes version.

  Parameters:

  - path – Optional path to config file.
  - config – A dict which may set the ‘interface’, and/or the ‘channel’, or neither.

  Returns:

  A config dictionary that should contain ‘interface’ & ‘channel’:

      {
          'interface': 'python-can backend interface to use',
          'channel': 'default channel to use',
      }

  Note `None` will be used if all the options are exhausted without finding a value.

`can.util.``load_environment_config`()

  Loads config dict from environmental variables (if set):

  - CAN_INTERFACE
  - CAN_CHANNEL
  - CAN_BITRATE

`can.util.``load_file_config`(path=None)

  Loads configuration from file with following content:

      [default]
      interface = socketcan
      channel = can0

  Parameters: | path – path to config file. If not specified, several sensible default locations are tried depending on platform.

`can.util.``set_logging_level`(level_name=None)

  Set the logging level for the “can” logger. Expects one of: ‘critical’, ‘error’, ‘warning’, ‘info’, ‘debug’, ‘subdebug’

## Notifier

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

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

    Exception raised in thread

  `stop`()

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