Build Video Applications with Python

The Shotstack Python video SDK makes it easy to build sophisticated video applications and workflows using Python. Perfect for data scientists, machine learning engineers, and Python developers who need to integrate video editing into their projects.

The open-source Python video editing library connects directly to Shotstack's managed video editing API, eliminating the need to install FFmpeg, manage servers, or handle complex video processing infrastructure.

Access all of Shotstack's powerful video editing features including trimming, concatenation, transitions, filters, effects, and the ability to merge videos, images, text and audio—all using clean, Pythonic code.

Getting Started

Installation

The Shotstack Python video editing library is available via PyPI or can be downloaded directly from GitHub.

pip install shotstack-sdk

Usage

1. Import the library

Import the Shotstack SDK and required classes.

import shotstack_sdk as shotstack
from shotstack_sdk.api import edit_api
from shotstack_sdk.model.edit import Edit
2. Configure the API client

Set the host and API key for your environment.

configuration = shotstack.Configuration(
    host="https://api.shotstack.io/stage"
)
configuration.api_key['DeveloperKey'] = "YOUR_API_KEY"
3. Create a video asset

Define the video asset with source URL and trim settings.

video_asset = shotstack.VideoAsset(
    src="https://shotstack-assets.s3.amazonaws.com/footage/skater.mp4",
    trim=3
)
4. Build the edit structure

Create clips, tracks, timeline and output configuration.

clip = shotstack.Clip(
    asset=video_asset,
    start=0,
    length=8
)

track = shotstack.Track(clips=[clip])
timeline = shotstack.Timeline(tracks=[track])

output = shotstack.Output(
    format="mp4",
    resolution="sd"
)

edit = Edit(
    timeline=timeline,
    output=output
)
5. Submit the edit

Send the edit to the API for rendering.

with shotstack.ApiClient(configuration) as api_client:
    api_instance = edit_api.EditApi(api_client)

    try:
        response = api_instance.post_render(edit)
        render_id = response['response']['id']
        print(f"Render ID: {render_id}")
    except Exception as e:
        print(f"Exception: {e}")

Output

The Python code above creates a JSON specification for trimming a video, sends it to the Shotstack API, and produces the edited video output.

EXPLORE

Check our Python video editing examples and demos on GitHub

DISCOVER

See what the Shotstack API and Python can do

More to do