Triggering renders from Python
available from v4.0.15
EXPERIMENTAL
This feature is new. Please report any issues you encounter.
To trigger a Lambda render using Python, install the remotion-lambda
package using pip
, by executing pip install remotion-lambda
from your python project. Use the same version as the remotion
version you are using from NPM, e.g. pip install remotion-lambda==4.0.15
(see newest version).
Breaking changes
4.0.82
- The
data
field is nowinput_props
. RenderParams
has been renamed toRenderMediaParams
.RenderProgress
has been renamed toRenderMediaProgress
.RenderResponse
is nowRenderMediaResponse
, and its fields have been updated:renderId
is nowrender_id
, andbucketName
has been changed tobucket_name
.- The following types have been added:
CostsInfo
,Privacy
,ValidStillImageFormats
,LogLevel
,OpenGlRenderer
,ChromiumOptions
,CustomCredentialsWithoutSensitiveData
,CustomCredentials
,OutNameInputObject
,PlayInBrowser
,Download
,DeleteAfter
. These can be used for the fields onRenderMediaParams
andRenderStillParams
.
Note the following before continuing:
- You first need to complete the Lambda setup.
- Sending large input props (>200KB) is not supported with Python at the moment.
Rendering a video
Below is a snippet showing how to initiate a render request and get its status.
render_media.pypython
from remotion_lambda import RenderMediaParams, Privacy, ValidStillImageFormatsfrom remotion_lambda import RemotionClientimport osfrom dotenv import load_dotenvload_dotenv()# Load env variablesREMOTION_APP_REGION = os.getenv('REMOTION_APP_REGION')if not REMOTION_APP_REGION:raise Exception("REMOTION_APP_REGION is not set")REMOTION_APP_FUNCTION_NAME = os.getenv('REMOTION_APP_FUNCTION_NAME')if not REMOTION_APP_FUNCTION_NAME:raise Exception("REMOTION_APP_FUNCTION_NAME is not set")REMOTION_APP_SERVE_URL = os.getenv('REMOTION_APP_SERVE_URL')if not REMOTION_APP_SERVE_URL:raise Exception("REMOTION_APP_SERVE_URL is not set")# Construct clientclient = RemotionClient(region=REMOTION_APP_REGION,serve_url=REMOTION_APP_SERVE_URL,function_name=REMOTION_APP_FUNCTION_NAME)# Set render requestrender_params = RenderMediaParams(composition="react-svg",privacy=Privacy.PUBLIC,image_format=ValidStillImageFormats.JPEG,input_props={'hi': 'there'},)render_response = client.render_media_on_lambda(render_params)if render_response:# Execute render requestprint("Render ID:", render_response.render_id)print("Bucket name:", render_response.bucket_name)# Execute progress requestprogress_response = client.get_render_progress(render_id=render_response.render_id, bucket_name=render_response.bucket_name)while progress_response and not progress_response.done:print("Overall progress")print(str(progress_response.overallProgress * 100) + "%")progress_response = client.get_render_progress(render_id=render_response.render_id, bucket_name=render_response.bucket_name)print("Render done!", progress_response.outputFile)
render_media.pypython
from remotion_lambda import RenderMediaParams, Privacy, ValidStillImageFormatsfrom remotion_lambda import RemotionClientimport osfrom dotenv import load_dotenvload_dotenv()# Load env variablesREMOTION_APP_REGION = os.getenv('REMOTION_APP_REGION')if not REMOTION_APP_REGION:raise Exception("REMOTION_APP_REGION is not set")REMOTION_APP_FUNCTION_NAME = os.getenv('REMOTION_APP_FUNCTION_NAME')if not REMOTION_APP_FUNCTION_NAME:raise Exception("REMOTION_APP_FUNCTION_NAME is not set")REMOTION_APP_SERVE_URL = os.getenv('REMOTION_APP_SERVE_URL')if not REMOTION_APP_SERVE_URL:raise Exception("REMOTION_APP_SERVE_URL is not set")# Construct clientclient = RemotionClient(region=REMOTION_APP_REGION,serve_url=REMOTION_APP_SERVE_URL,function_name=REMOTION_APP_FUNCTION_NAME)# Set render requestrender_params = RenderMediaParams(composition="react-svg",privacy=Privacy.PUBLIC,image_format=ValidStillImageFormats.JPEG,input_props={'hi': 'there'},)render_response = client.render_media_on_lambda(render_params)if render_response:# Execute render requestprint("Render ID:", render_response.render_id)print("Bucket name:", render_response.bucket_name)# Execute progress requestprogress_response = client.get_render_progress(render_id=render_response.render_id, bucket_name=render_response.bucket_name)while progress_response and not progress_response.done:print("Overall progress")print(str(progress_response.overallProgress * 100) + "%")progress_response = client.get_render_progress(render_id=render_response.render_id, bucket_name=render_response.bucket_name)print("Render done!", progress_response.outputFile)
Rendering an image
Below is a snippet showing how to initiate a still image render. Note that it does not require monitoring the render progress.
render_still.pypython
from remotion_lambda import RenderStillParams, Privacy, ValidStillImageFormatsfrom remotion_lambda import RemotionClientimport osfrom dotenv import load_dotenvload_dotenv()# Load env variablesREMOTION_APP_REGION = os.getenv('REMOTION_APP_REGION')if not REMOTION_APP_REGION:raise Exception("REMOTION_APP_REGION is not set")REMOTION_APP_FUNCTION_NAME = os.getenv('REMOTION_APP_FUNCTION_NAME')if not REMOTION_APP_FUNCTION_NAME:raise Exception("REMOTION_APP_FUNCTION_NAME is not set")REMOTION_APP_SERVE_URL = os.getenv('REMOTION_APP_SERVE_URL')if not REMOTION_APP_SERVE_URL:raise Exception("REMOTION_APP_SERVE_URL is not set")# Construct clientclient = RemotionClient(region=REMOTION_APP_REGION,serve_url=REMOTION_APP_SERVE_URL,function_name=REMOTION_APP_FUNCTION_NAME)# Set render still requestrender_params = RenderStillParams(composition="still-helloworld",privacy=Privacy.PUBLIC,image_format=ValidStillImageFormats.JPEG,input_props={'message': 'Hello from props!'},)render_response = client.render_still_on_lambda(render_params)if render_response:# Execute render requestprint("Render ID:", render_response.render_id)print("Bucket name:", render_response.bucket_name)print("Render done! File at ", render_response.url)
render_still.pypython
from remotion_lambda import RenderStillParams, Privacy, ValidStillImageFormatsfrom remotion_lambda import RemotionClientimport osfrom dotenv import load_dotenvload_dotenv()# Load env variablesREMOTION_APP_REGION = os.getenv('REMOTION_APP_REGION')if not REMOTION_APP_REGION:raise Exception("REMOTION_APP_REGION is not set")REMOTION_APP_FUNCTION_NAME = os.getenv('REMOTION_APP_FUNCTION_NAME')if not REMOTION_APP_FUNCTION_NAME:raise Exception("REMOTION_APP_FUNCTION_NAME is not set")REMOTION_APP_SERVE_URL = os.getenv('REMOTION_APP_SERVE_URL')if not REMOTION_APP_SERVE_URL:raise Exception("REMOTION_APP_SERVE_URL is not set")# Construct clientclient = RemotionClient(region=REMOTION_APP_REGION,serve_url=REMOTION_APP_SERVE_URL,function_name=REMOTION_APP_FUNCTION_NAME)# Set render still requestrender_params = RenderStillParams(composition="still-helloworld",privacy=Privacy.PUBLIC,image_format=ValidStillImageFormats.JPEG,input_props={'message': 'Hello from props!'},)render_response = client.render_still_on_lambda(render_params)if render_response:# Execute render requestprint("Render ID:", render_response.render_id)print("Bucket name:", render_response.bucket_name)print("Render done! File at ", render_response.url)