Skip to content

API Documentation

Dan edited this page Nov 30, 2025 · 4 revisions

Control Interface

class

osmoctrl.CtrlInterface(server: str, port: int, timeout=10)

This class represents the Osmocom Control Interface connection, and is used to GET and SET vars.

Parameters:

  • server (str) - The IP address of the Osmocom Control Interface host.
  • port (int) - The port of the Osmocom Control Interface.
  • timeout (int | 10) - The maximum time to wait for a response to a message. Defaults to 10 seconds.

Properties:

  • TRAPS (list) - A list of TRAP messages received over the lifetime of the CtrlInterface() object.

Note: Retrieval of TRAP messages is handled by popping all messages out of the TRAPS list. This means that the list is functionally a queue, and is emptied when called.

Usage Example:

ctrl = CtrlInterface('127.0.0.1', 4259)

method

get(var: str, parse_val = PARSE_VAL_DEFAULT)

Get a variable via the Osmocom Control Interface.

Parameters:

  • var (str) - The variable to retrieve.
  • parse_val (bool | True) - Should the returned value be parsed? Defaults to True.

Note: When parse_val is True, pyosmoctrl attempts to parse the response value from the CTRL interface into a dict.

Given the non-standard responses returned by the CTRL interface, this may sometimes fail. This option is provided so that the raw unparsed string response can be returned, if required.

Usage Example:

ctrl = CtrlInterface('127.0.0.1', 4259)

ctrl.get('subscriber.by-id-1.info-all')

method

set(var: str, val: str, parse_val = PARSE_VAL_DEFAULT)

Set a variable via the Osmocom Control Interface.

Parameters:

  • var (str) - The variable to set.
  • val (str) - The new value of the variable.
  • parse_val (bool | True) - Should the returned value be parsed? Defaults to True.

Note: When parse_val is True, pyosmoctrl attempts to parse the response value from the CTRL interface into a dict.

Given the non-standard responses returned by the CTRL interface, this may sometimes fail. This option is provided so that the raw unparsed string response can be returned, if required.

Usage Example:

ctrl = CtrlInterface('127.0.0.1', 4259)

ctrl.set('subscriber.by-id-1.msisdn', '123')

Exceptions

exception

osmoctrl.CtrlError(Exception)

Raised when the control interface returns an error.

Arguments:

  • decoded_ctrl_msg['outcome'] (str) - The returned "operation".
  • decoded_ctrl_msg['reason'] (str) - The error reason text, if available.
  • decoded_ctrl_msg (dict) - The full returned message.

Example:

pyosmoctrl.osmoctrl.CtrlError: ('ERROR', 'No such subscriber.', {'outcome': 'ERROR', 'cmd_id': '2753991230658678373', 'reason': 'No such subscriber.'})