Skip to content

🎥 Make videos programmatically with React

[WIP] add python sdk client

Alex Fernandez6dd14de63800
diff --git a/.gitignore b/.gitignore
index b15e210608..186d112d6f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@ packages/renderer/target
packages/example/sa-key.json
packages/example/public/pts-framermp4withoutfileextension.mp4
packages/it-tests/packages/example/out/element-2.png
+packages/lambda-python/src/lambda-python/__pycache__
diff --git a/.vscode/settings.json b/.vscode/settings.json
index a6efe8fa72..b6ea939d93 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -7,5 +7,9 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
- }
+ },
+ "[python]": {
+ "editor.defaultFormatter": "ms-python.autopep8"
+ },
+ "python.formatting.provider": "none"
}
diff --git a/packages/lambda-python/.gitignore b/packages/lambda-python/.gitignore
new file mode 100644
index 0000000000..e2e6a10e33
--- /dev/null
+++ b/packages/lambda-python/.gitignore
@@ -0,0 +1,13 @@
+# Binaries for programs and plugins
+*.exe
+*.exe~
+*.dll
+*.so
+*.dylib
+
+# Test binary, built with `go test -c`
+*.test
+
+# Output of the go coverage tool, specifically when used with LiteIDE
+*.out
+
diff --git a/packages/lambda-python/.pylintrc b/packages/lambda-python/.pylintrc
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/packages/lambda-python/LICENSE b/packages/lambda-python/LICENSE
new file mode 100644
index 0000000000..60896cf848
--- /dev/null
+++ b/packages/lambda-python/LICENSE
@@ -0,0 +1,41 @@
+# Remotion License
+
+Depending on the type of your legal entity, you are granted permission to use Remotion for your project. Individuals and small companies are allowed to use Remotion to create videos for free (even commercial), while a company license is required for for-profit organizations of a certain size. This two-tier system was designed to ensure funding for this project while still allowing the source code to be available and the program to be free for most. Read below for the exact terms of use.
+
+- [Free license](#free-license)
+- [Company license](#company-license)
+
+## Free license
+
+Copyright © 2023 [Remotion](https://www.remotion.dev/)
+
+### Eligibility
+
+You are eligible to use Remotion for free if you are:
+
+- an individual
+- a for-profit organization with up to 3 employees
+- a non-profit or not-for-profit organization
+- evaluating whether Remotion is a good fit, and are not yet using it in a commercial way
+
+### Allowed use cases
+
+Permission is hereby granted, free of charge, to any person eligible for the "Free license", to use the software non-commercially or commercially for the purpose of creating videos and images and to modify the software to their own liking, for the purpose of fulfilling their custom use case or to contribute bug fixes or improvements back to Remotion.
+
+### Disallowed use cases
+
+It is not allowed to copy or modify Remotion code for the purpose of selling, renting, licensing, relicensing, or sublicensing your own derivate of Remotion.
+
+### Warranty notice
+
+The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the author or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.
+
+### Support
+
+Support is provided on a best-we-can-do basis via GitHub Issues and Discord.
+
+## Company license
+
+You are required to obtain a company license to use Remotion if you are not within the group of entities eligible for a free license. This license will enable you to use Remotion for the allowed use cases specified in the free license, and give you access to prioritized support (read the [Support Policy](/docs/support)).
+
+Visit [companies.remotion.dev](https://companies.remotion.dev) for pricing and to buy a license.
diff --git a/packages/lambda-python/README.md b/packages/lambda-python/README.md
new file mode 100644
index 0000000000..ad9ff9a35f
--- /dev/null
+++ b/packages/lambda-python/README.md
@@ -0,0 +1,5 @@
+# Example Package
+
+This is a simple example package. You can use
+[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
+to write your content.
diff --git a/packages/lambda-python/build.mjs b/packages/lambda-python/build.mjs
new file mode 100644
index 0000000000..a8dc16255a
--- /dev/null
+++ b/packages/lambda-python/build.mjs
@@ -0,0 +1,20 @@
+import { execSync } from "child_process";
+
+const where = process.platform === "win32" ? "where" : "which";
+
+const hasPython = () => {
+ try {
+ execSync(`${where} python`);
+ return true;
+ } catch (err) {
+ console.log(err);
+ return false;
+ }
+};
+
+if (!hasPython()) {
+ console.log("Environment has no Python. Skipping...");
+ process.exit(0);
+}
+execSync("pylint ./src", { stdio: "inherit" });
+console.log("Linted python lint!");
diff --git a/packages/lambda-python/package.json b/packages/lambda-python/package.json
new file mode 100644
index 0000000000..79085e5fd5
--- /dev/null
+++ b/packages/lambda-python/package.json
@@ -0,0 +1,12 @@
+{
+ "name": "@remotion/lambda-python",
+ "private": true,
+ "version": "4.0.4",
+ "scripts": {
+ "lint": "node build.mjs",
+ "publish": "node publish.mjs"
+ },
+ "devDependencies": {
+ "remotion": "workspace:*"
+ }
+}
diff --git a/packages/lambda-python/publish.mjs b/packages/lambda-python/publish.mjs
new file mode 100644
index 0000000000..2de6d2842a
--- /dev/null
+++ b/packages/lambda-python/publish.mjs
@@ -0,0 +1,15 @@
+import { VERSION } from "remotion/version";
+import { execSync } from "node:child_process";
+import {
+ copyFileSync,
+ mkdirSync,
+ cpSync,
+ existsSync,
+ rmSync,
+ writeFileSync,
+ readdirSync,
+} from "node:fs";
+import { tmpdir } from "node:os";
+import path from "node:path";
+
+const tmpDir = tmpdir();
diff --git a/packages/lambda-python/pyproject.toml b/packages/lambda-python/pyproject.toml
new file mode 100644
index 0000000000..b3fca0ee33
--- /dev/null
+++ b/packages/lambda-python/pyproject.toml
@@ -0,0 +1,19 @@
+[build-system]
+requires = ["setuptools>=61.0"]
+build-backend = "setuptools.build_meta"
+
+[project]
+name = "lambda-python-remotion"
+version = "0.0.1"
+authors = [
+ { name="Jonny Burger", email="[email protected]" },
+]
+description = "Remotion Python Client"
+readme = "README.md"
+requires-python = ">=3.11"
+classifiers = [
+]
+
+[project.urls]
+"Homepage" = "https://remotion.dev/"
+"Bug Tracker" = "https://github.com/remotion-dev/remotion/issues"
\ No newline at end of file
diff --git a/packages/lambda-python/src/__init__.py b/packages/lambda-python/src/__init__.py
new file mode 100644
index 0000000000..ace9da7092
--- /dev/null
+++ b/packages/lambda-python/src/__init__.py
@@ -0,0 +1 @@
+# pylint: disable-all
diff --git a/packages/lambda-python/src/__pycache__/RenderParams.cpython-311.pyc b/packages/lambda-python/src/__pycache__/RenderParams.cpython-311.pyc
new file mode 100644
index 0000000000..c3aa2254e0
Binary files /dev/null and b/packages/lambda-python/src/__pycache__/RenderParams.cpython-311.pyc differ
diff --git a/packages/lambda-python/src/__pycache__/version.cpython-311.pyc b/packages/lambda-python/src/__pycache__/version.cpython-311.pyc
new file mode 100644
index 0000000000..144712115c
Binary files /dev/null and b/packages/lambda-python/src/__pycache__/version.cpython-311.pyc differ
diff --git a/packages/lambda-python/src/client.py b/packages/lambda-python/src/client.py
new file mode 100644
index 0000000000..49d231b7ad
--- /dev/null
+++ b/packages/lambda-python/src/client.py
@@ -0,0 +1,51 @@
+import boto3
+
+from renderparams import RenderParams
+
+
+class Client:
+ def __init__(self, access_key=None, secret_key=None, region_name="ap-southeast-2", session=None):
+ self.access_key = access_key
+ self.secret_key = secret_key
+ self.region_name = region_name
+ self.session = session
+ self.client = self.create_lambda_client()
+
+ def create_lambda_client(self):
+ if self.session:
+ return self.session.client('lambda', region_name=self.region_name)
+ elif self.access_key and self.secret_key:
+ return boto3.client('lambda',
+ aws_access_key_id=self.access_key,
+ aws_secret_access_key=self.secret_key,
+ region_name=self.region_name)
+ else:
+ return boto3.client('lambda')
+
+ def invoke_lambda(self, function_name, payload):
+ try:
+ response = self.client.invoke(
+ FunctionName=function_name, Payload=payload)
+ result = response['Payload'].read().decode('utf-8')
+ print("Lambda function invoked successfully.")
+ print("Response:", result)
+ except Exception as e:
+ print(f"Failed to invoke Lambda function: {str(e)}")
+
+ def renderMediaOnLambda(self, render_params: RenderParams):
+ print(render_params.serializeParams())
+ # Function body
+
+
+access_key = 'your_access_key'
+secret_key = 'your_secret_key'
+region_name = 'ap-southeast-2' # Replace with your desired region name
+function_name = 'your_lambda_function_name'
+payload = '{"key": "value"}'
+
+lambda_client = Client(access_key, secret_key, region_name)
+
+
+render_params = RenderParams() # Instantiate a RenderParams object
+# Pass the object to renderMediaOnLambda
+lambda_client.renderMediaOnLambda(render_params)
diff --git a/packages/lambda-python/src/renderparams.py b/packages/lambda-python/src/renderparams.py
new file mode 100644
index 0000000000..240cb9fb1a
--- /dev/null
+++ b/packages/lambda-python/src/renderparams.py
@@ -0,0 +1,95 @@
+from typing import Optional, List, Dict
+from dataclasses import dataclass, field
+from version import VERSION
+
+
+@dataclass
+class RenderParams:
+ data: Optional[List] = None
+ bucketName: Optional[str] = None
+ region: Optional[str] = None
+ outName: Optional[str] = None
+ composition: Optional[str] = 'main'
+ serverUrl: Optional[str] = None
+ framesPerLambda: Optional[int] = None
+ inputProps: Optional[Dict] = None
+ codec: str = 'h264'
+ version: str = ""
+ imageFormat: str = 'jpeg'
+ crf: Optional[int] = None
+ envVariables: Optional[List] = None
+ quality: Optional[int] = None
+ maxRetries: int = 1
+ privacy: str = 'private'
+ logLevel: str = 'info'
+ frameRange: Optional[str] = None
+ timeoutInMilliseconds: Optional[int] = 30000
+ chromiumOptions: Optional[Dict] = None
+ scale: Optional[int] = 1
+ everyNthFrame: Optional[int] = 1
+ numberOfGifLoops: Optional[int] = 0
+ concurrencyPerLambda: Optional[int] = 1
+ downloadBehavior: Dict = field(default_factory=lambda: {
+ 'type': 'play-in-browser'})
+ muted: bool = False
+ overwrite: bool = False
+ audioBitrate: Optional[int] = None
+ videoBitrate: Optional[int] = None
+ webhook: Optional[str] = None
+ forceHeight: Optional[int] = None
+ forceWidth: Optional[int] = None
+ audioCodec: Optional[str] = None
+ rendererFunctionName: Optional[str] = None
+ proResProfile: Optional[str] = None
+ pixelFormat: Optional[str] = None
+
+ def serializeParams(self) -> Dict:
+ parameters = {
+ 'rendererFunctionName': self.rendererFunctionName,
+ 'framesPerLambda': self.framesPerLambda,
+ 'composition': self.composition,
+ 'serveUrl': self.serverUrl,
+ 'inputProps': self.inputProps,
+ 'codec': self.codec,
+ 'imageFormat': self.imageFormat,
+ 'maxRetries': self.maxRetries,
+ 'privacy': self.privacy,
+ 'logLevel': self.logLevel,
+ 'frameRange': self.frameRange,
+ 'outName': self.outName,
+ 'timeoutInMilliseconds': self.timeoutInMilliseconds,
+ 'chromiumOptions': self.chromiumOptions if self.chromiumOptions is not None else {},
+ 'scale': self.scale,
+ 'everyNthFrame': self.everyNthFrame,
+ 'numberOfGifLoops': self.numberOfGifLoops,
+ 'concurrencyPerLambda': self.concurrencyPerLambda,
+ 'downloadBehavior': self.downloadBehavior,
+ 'muted': self.muted,
+ 'version': VERSION,
+ 'overwrite': self.overwrite,
+ 'audioBitrate': self.audioBitrate,
+ 'videoBitrate': self.videoBitrate,
+ 'webhook': self.webhook,
+ 'forceHeight': self.forceHeight,
+ 'forceWidth': self.forceWidth,
+ 'bucketName': self.bucketName,
+ 'audioCodec': self.audioCodec,
+ 'type': 'start'
+ }
+
+ if self.crf is not None:
+ parameters['crf'] = self.crf
+
+ if self.envVariables is not None:
+ parameters['envVariables'] = self.envVariables
+
+ if self.pixelFormat is not None:
+ parameters['pixelFormat'] = self.pixelFormat
+
+ if self.proResProfile is not None:
+ parameters['proResProfile'] = self.proResProfile
+
+ if self.quality is not None:
+ parameters['quality'] = self.quality
+
+ return parameters
diff --git a/packages/lambda-python/src/version.py b/packages/lambda-python/src/version.py
new file mode 100644
index 0000000000..da4d80bd33
--- /dev/null
+++ b/packages/lambda-python/src/version.py
@@ -0,0 +1,2 @@
+VERSION = "4.0.4"
+# pylint: disable-all
diff --git a/packages/lambda-python/tests/test_client_with_unittest.py b/packages/lambda-python/tests/test_client_with_unittest.py
new file mode 100644
index 0000000000..9c73023f1b
--- /dev/null
+++ b/packages/lambda-python/tests/test_client_with_unittest.py
@@ -0,0 +1,11 @@
+# test_with_unittest.py
+
+from unittest import TestCase
+
+
+class TestRemotionClient(TestCase):
+ def test_always_passes(self):
+ self.assertTrue(True)
+
+ def test_always_fails(self):
+ self.assertTrue(False)