ControlAPI integration with the Client

Added in version 1.8.0: Feature introduced in the Client

This feature allows for easy usage of the ControlAPI directly in the Client. That means no credentials need to be supplied to the ControlAPI instance. Instead, the credentials will be sourced from the Service directly. Though the credentials defined in the Service never surface to the Client nor ControlAPI instance used in the Client.

For more details on ControlAPI itself, look here: Control API reference.

Note

In order to be able to use this feature, along with the Client module - the Service module must be installed.

Service configuration

In order to make use of the ControlAPI, there needs to be at least one device of type RADKit Service defined in the Service:

../_images/device-type-radkit-service.png

Note

Username and password in the “HTTP” section must point to the existing admin user.

Integration with the Client

In order to use the ControlAPI - one needs to use the create_control_api() function available in the Client without the need of importing it.

>>> control_api = create_control_api(service.inventory['radkit-service'])

>>> type(control_api)
<class 'radkit_service.control_api.ControlAPI'>

>>> dir(control_api)
# The output is truncated to show only the user-facing APIs
[..., 'change_password', 'create_admin', 'create_admins', 'create_device', 'create_device_template', 'create_devices',
'create_devices_csv', 'create_external_source', 'create_labels', 'create_remote_user', 'create_remote_users', 'delete_admin',
'delete_admins', 'delete_device', 'delete_devices', 'delete_labels', 'delete_remote_user', 'delete_remote_users',
'enroll_service', 'from_radkit_client_device', 'get_admin', 'get_device', 'get_remote_user', 'get_service_status',
'get_service_version', 'get_settings', 'get_support_package', 'import_devices', 'init_bootstrap_admin', 'list_admins',
'list_device_types', 'list_devices', 'list_devices_csv', 'list_labels', 'list_remote_users', 'set_settings', 'stop_service',
'stop_service_unauthenticated', 'system_reset_service', 'update_admin', 'update_admins', 'update_device', 'update_devices',
'update_labels', 'update_remote_user', 'update_remote_users']

# Now it's possible to use any of the ControlAPI methods
>>> control_api.list_devices()
[SUCCESS] APIResult[Union[list[StoredDeviceWithMetadata], list[StoredDevice]]](status='SUCCESS')
------  --------------------------------------------------------------------------------
result  [StoredDeviceWithMetadata(name=new-device-00000, uuid=77b78c55-a7e6-430d-8e18...
------  --------------------------------------------------------------------------------

>>> control_api.get_service_version()
[SUCCESS] APIResult[str](status='SUCCESS')
------  -----
result  1.8.0
------  -----

>>> control_api.get_support_package()
[SUCCESS] APIResult[ServiceSupportPackage](status='SUCCESS')
------  --------------------------------------------------------------------------------
result  {"basic_support_package":{"support_summary_created_at":"2025-02-05T11:17:28.1...
------  --------------------------------------------------------------------------------

# To get the actual results
>>> result = control_api.get_support_package()
>>> result.result
ServiceSupportPackage(basic_support_package=BasicSupportPackage(support_summary_created_at=datetime.date ...

# To get the status of the request
>>> result.status
<ControlAPIRequestStatus.SUCCESS: 'SUCCESS'>

When scripting - it’s possible to import create_control_api helper function like this:

from radkit_client import create_control_api

You can read more about the ControlAPI and it’s programmatic usage here: Control API reference.