Python API to control Motif recording systems
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Python API for Motif Recording Systems

This library allows you to control cameras and recording on loopbio motif recording systems.

Getting Started

  • this library works out of the box on Python2 and Python3 and has no dependencies outside of the standard library
  • to control a motif recording system you need to know it's IP address and an API key.
    • the IP address is that which you browse to inorder to control the recording software using your web browser
    • the API key is specific to the installation of the recording software and secures the API from unauthorized access. To find the API key for the recording system you wish to control, SSH into the machine (or request your sysadmin to) and execute the following command recnode-apikey
  • this library wraps the REST+JSON API and handles sending and parsing the responses


Set up the connection to the machine

from motifapi import MotifApi

API_KEY = 'abcdef123456abcdef123456abcdef12'

api = MotifApi(IP_ADDRESS, API_KEY)
# check the client is connected'version')

To start recording on all cameras with the predefined compression settings named 'high' (see the web UI for the names of your configured compression formats). The recording will run for 5 seconds and will have have the following metadata attached.'recording/start',
         metadata={'foo': 1, 'bar': 'bob'})

To stop all recordings on all cameras'recording/stop')

To configure one camera and start recording on it alone'camera/FAKE0/configure', Gain=0))'camera/FAKE0/recording/start', codec='low')

Cameras are identified by their serial number ('FAKE0' in the example above). To find the serial numbers of connected cameras do'cameras')

To find the status of a camera (is it recording, uploading, etc) do'camera/FAKE0')

See examples/*.py for further examples of API usage


The API also supports defining scheduled tasks, this allows for example, to schedule recordings and their subsequent copy to storage to occur at specific times.

Task scheduling re-uses Cron syntax with some extensions. Specifically it utilises the Cronex library and supports the formats mentioned there (including monotonic tasks with % markup). All times are in local-time of the machine running the recording software. We recommend using the corntab website to validate your cron expressions.

To list currently scheduled tasks (and the current machine time)


The API for scheduling tasks is very similar to that of other tasks - API endpoints are prefixed with schedule/VERB and require passing two compulsory additional parameters, task_name and cron_expression. For example, to schedule a 30 minute recording as configured above to be executed every-hour-on-the-hour between 9am and 4pm, make the following API call'schedule/recording/start', task_name='record_video', cron_expression='0 06-16 * * *',
                                     codec='low', duration=30*60)

See examples/ for more information