Python Client API Examples

The examples provided below detail common actions that can be performed using the Python Client API.

The Python Client API can be downloaded from the downloads section on the Keyframe Pro main page.

Hello World

The following example demonstrates how to connect with and initialize Keyframe Pro for communication using the client API.

After the initialization has been completed successufully all of the commands in the Python Client API are available for use in scripts.

from keyframe_pro.keyframe_pro_client import KeyframeProClient

kpro_client = KeyframeProClient()
if kpro_client.connect():
    if kpro_client.initialize():
        print(kpro_client.echo("Hello World!"))
    else:
        print("Failed to initialize Keyframe Pro.")
else:
    print("Failed to connect to Keyframe Pro.")

Importing a Source

The following example creates a new empty project and imports a single source file.

from keyframe_pro.keyframe_pro_client import KeyframeProClient

kpro_client = KeyframeProClient()
if kpro_client.connect() and kpro_client.initialize():
    kpro_client.new_project(empty=True)
    kpro_client.import_file('D:/big_buck_bunny_720p_h264.mov')

Constructing a Timeline

The following example creates a new empty project and imports three source files. It then adds a new timeline to the project and inserts each source into the timeline. Finally, the new timeline is set active in the primary viewer.

from keyframe_pro.keyframe_pro_client import KeyframeProClient

kpro_client = KeyframeProClient()
if kpro_client.connect() and kpro_client.initialize():

    kpro_client.new_project(empty=True)

    paths = [
        'D:/clip_000.mov',
        'D:/clip_001.mov',
        'D:/clip_002.mov',
    ]

    # Import sources
    sources = []
    for path in paths:
        sources.append(kpro_client.import_file(path))

    # Create a new timeline
    timeline = kpro_client.add_timeline('My Timeline')
    for source in sources:
        kpro_client.insert_element_in_timeline(source['id'], timeline['id'])

    # Make the timeline active in viewer A
    kpro_client.set_active_in_viewer(timeline['id'], 0)

Related Links