How to Create Videos using Python?

To create video using Python, you need an API capable of rendering dynamic video. A typical use case is generating video from dynamic, real-time, or user-generated data. Think about creating thousands of data-driven videos for video personalization, social media marketing, or data visualization. Here's how to do it in Python:

Input Code
import requests

json = {
 # The ID of the template that you created in the online editor.
 'template_id': '58c1163e-f250-49df-b98d-e8c4aad01a2d',

 # Inserting dynamic data into the template.
 'modifications': {
  'Text': 'Your Text And Video Here',
  'Video': 'https://cdn.creatomate.com/demo/drone.mp4'
 }
}

response = requests.post(
 'https://api.creatomate.com/v1/renders',
 headers={
  # Find your API key under 'Project Settings' in your account:
  # https://creatomate.com/docs/api/rest-api/authentication
  'Authorization': 'Bearer Your-API-Key',
  'Content-Type': 'application/json',
 },
 json=json
)

# Wait a minute, then visit the URL provided in the response:
print(response.json())

Output Video

How it works: All that is required is the "requests" library that comes bundled with every Python installation. Using this package, we will be able to send a POST request to Creatomate, which is an API for generating videos in the cloud. In response to this API request, a URL is returned where the generated video can be accessed for further use by our Python application.

This example shows you how to create a video from a template. This is by far the easiest way to start creating videos programmatically. To do this, we need to make a video template in our Creatomate account, which we can do with the online template editor. Once the template is set up, we can programmatically insert data into the template using the "modifications" parameters as shown in the example above. The parameters allow us to edit any aspect of the video, such as the text, video footage, data, or colors.

Another approach for creating videos with Python is to give the API instructions for editing videos based on scratch, rather than using a template. This method allows you to perform any type of video editing task directly from your Python script, such as stitching, merging, cropping, overlaying text, and more. You can check out the related example further down this page to see how this works.

To get started, follow this quick tutorial or check out the API documentation.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your Python application to create any kind of video – completely through code.

Related Python Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free