remotion-lambda 4.0.534__tar.gz → 4.0.536__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/PKG-INFO +1 -1
  2. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda/__init__.py +4 -0
  3. remotion_lambda-4.0.536/remotion_lambda/asyncremotionclient.py +111 -0
  4. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda/models.py +80 -0
  5. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda/remotionclient.py +12 -1
  6. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda/version.py +1 -1
  7. remotion_lambda-4.0.536/remotion_lambda/webhook.py +62 -0
  8. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda.egg-info/PKG-INFO +1 -1
  9. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda.egg-info/SOURCES.txt +2 -0
  10. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/LICENSE +0 -0
  11. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/README.md +0 -0
  12. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda/exception.py +0 -0
  13. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda.egg-info/dependency_links.txt +0 -0
  14. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda.egg-info/requires.txt +0 -0
  15. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/remotion_lambda.egg-info/top_level.txt +0 -0
  16. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/setup.cfg +0 -0
  17. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/setup.py +0 -0
  18. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/__init__.py +0 -0
  19. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/conftest.py +0 -0
  20. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/constants.py +0 -0
  21. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/test_get_render_progress_client.py +0 -0
  22. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/test_large_payload_compression.py +0 -0
  23. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/test_remotion_client.py +0 -0
  24. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/test_render_client_render_media.py +0 -0
  25. {remotion_lambda-4.0.534 → remotion_lambda-4.0.536}/tests/test_render_client_render_still.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: remotion_lambda
3
- Version: 4.0.534
3
+ Version: 4.0.536
4
4
  Summary: Remotion Lambda client
5
5
  Home-page: https://github.com/remotion-dev/remotion/tree/main/packages/lambda-python
6
6
  Author: Jonny Burger
@@ -1,5 +1,7 @@
1
1
  # pylint: disable=missing-module-docstring
2
2
  from .models import (
3
+ RenderFramesParams,
4
+ ImageSequenceOutputPrefix,
3
5
  RenderMediaParams,
4
6
  RenderMediaProgress,
5
7
  RenderMediaResponse,
@@ -21,4 +23,6 @@ from .models import (
21
23
  Webhook,
22
24
  )
23
25
  from .remotionclient import RemotionClient
26
+ from .asyncremotionclient import AsyncRemotionClient
24
27
  from .version import VERSION
28
+ from .webhook import validate_webhook_signature
@@ -0,0 +1,111 @@
1
+ # pylint: disable=too-many-arguments, too-many-positional-arguments
2
+ """Awaitable client for rendering with Remotion Lambda."""
3
+ import asyncio
4
+ from typing import Optional, Union
5
+
6
+ from boto3.session import Session
7
+ from botocore.config import Config
8
+
9
+ from .models import (
10
+ CustomCredentials,
11
+ RenderMediaParams,
12
+ RenderMediaProgress,
13
+ RenderMediaResponse,
14
+ RenderStillParams,
15
+ RenderStillResponse,
16
+ RenderType,
17
+ )
18
+ from .remotionclient import RemotionClient
19
+
20
+
21
+ class AsyncRemotionClient:
22
+ """Run RemotionClient operations without blocking the asyncio event loop."""
23
+
24
+ def __init__(
25
+ self,
26
+ region: str,
27
+ serve_url: str,
28
+ function_name: str,
29
+ access_key: Optional[str] = None,
30
+ secret_key: Optional[str] = None,
31
+ force_path_style: bool = False,
32
+ session: Optional[Session] = None,
33
+ config: Optional[Config] = None,
34
+ ):
35
+ """Accept the same configuration and credentials as RemotionClient."""
36
+ self._client = RemotionClient(
37
+ region=region,
38
+ serve_url=serve_url,
39
+ function_name=function_name,
40
+ access_key=access_key,
41
+ secret_key=secret_key,
42
+ force_path_style=force_path_style,
43
+ session=session,
44
+ config=config,
45
+ )
46
+
47
+ async def construct_render_request(
48
+ self,
49
+ render_params: Union[RenderMediaParams, RenderStillParams],
50
+ render_type: RenderType,
51
+ ) -> str:
52
+ """Construct a render request, including any required S3 uploads."""
53
+ return await asyncio.get_running_loop().run_in_executor(
54
+ None, self._client.construct_render_request, render_params, render_type
55
+ )
56
+
57
+ async def construct_render_progress_request(
58
+ self,
59
+ render_id: str,
60
+ bucket_name: str,
61
+ log_level: str = "info",
62
+ s3_output_provider: Optional[CustomCredentials] = None,
63
+ ) -> str:
64
+ """Construct a render progress request in JSON format."""
65
+ return await asyncio.get_running_loop().run_in_executor(
66
+ None,
67
+ self._client.construct_render_progress_request,
68
+ render_id,
69
+ bucket_name,
70
+ log_level,
71
+ s3_output_provider,
72
+ )
73
+
74
+ async def render_media_on_lambda(
75
+ self, render_params: RenderMediaParams
76
+ ) -> Optional[RenderMediaResponse]:
77
+ """Start a media render and return its render ID and bucket name."""
78
+ return await asyncio.get_running_loop().run_in_executor(
79
+ None, self._client.render_media_on_lambda, render_params
80
+ )
81
+
82
+ async def render_still_on_lambda(
83
+ self, render_params: RenderStillParams
84
+ ) -> Optional[RenderStillResponse]:
85
+ """Render a still and return its output information."""
86
+ return await asyncio.get_running_loop().run_in_executor(
87
+ None, self._client.render_still_on_lambda, render_params
88
+ )
89
+
90
+ async def get_render_progress(
91
+ self,
92
+ render_id: str,
93
+ bucket_name: str,
94
+ log_level: str = "info",
95
+ s3_output_provider: Optional[CustomCredentials] = None,
96
+ ) -> Optional[RenderMediaProgress]:
97
+ """Get the progress of a media render."""
98
+ return await asyncio.get_running_loop().run_in_executor(
99
+ None,
100
+ self._client.get_render_progress,
101
+ render_id,
102
+ bucket_name,
103
+ log_level,
104
+ s3_output_provider,
105
+ )
106
+
107
+ async def cancel_render_on_lambda(self, render_id: str, bucket_name: str) -> None:
108
+ """Cancel a render started with enable_cancellation=True."""
109
+ await asyncio.get_running_loop().run_in_executor(
110
+ None, self._client.cancel_render_on_lambda, render_id, bucket_name
111
+ )
@@ -156,6 +156,18 @@ class OutNameInputObject:
156
156
  key: str
157
157
  s3_output_provider: Optional[CustomCredentials] = None
158
158
 
159
+ def serialize_params(self) -> Dict:
160
+ """Serialize the output destination and any custom storage credentials."""
161
+ return {
162
+ 'bucketName': self.bucketName,
163
+ 'key': self.key,
164
+ 's3OutputProvider': (
165
+ self.s3_output_provider.serialize_params()
166
+ if self.s3_output_provider is not None
167
+ else None
168
+ ),
169
+ }
170
+
159
171
 
160
172
  class DeleteAfter(Enum):
161
173
  """
@@ -338,6 +350,7 @@ class RenderMediaParams:
338
350
  is_production: Optional[bool] = None
339
351
  sample_rate: int = 48000
340
352
  disable_shared_memory_capture: bool = False
353
+ separate_audio_to: Optional[Union[str, OutNameInputObject]] = None
341
354
 
342
355
  def serialize_params(self) -> Dict:
343
356
  """
@@ -363,6 +376,11 @@ class RenderMediaParams:
363
376
  'logLevel': self.log_level,
364
377
  'frameRange': self.frame_range,
365
378
  'outName': self.out_name,
379
+ 'separateAudioTo': (
380
+ self.separate_audio_to.serialize_params()
381
+ if isinstance(self.separate_audio_to, OutNameInputObject)
382
+ else self.separate_audio_to
383
+ ),
366
384
  'preferLossless': self.prefer_lossless,
367
385
  'sampleRate': self.sample_rate,
368
386
  'timeoutInMilliseconds': self.timeout_in_milliseconds,
@@ -402,6 +420,7 @@ class RenderMediaParams:
402
420
  'encodingMaxRate': self.encoding_max_rate,
403
421
  'isProduction': self.is_production,
404
422
  'type': 'start',
423
+ 'output': {'type': 'media'},
405
424
  }
406
425
 
407
426
  if self.crf is not None:
@@ -435,6 +454,64 @@ class RenderMediaParams:
435
454
  return parameters
436
455
 
437
456
 
457
+ @dataclass
458
+ class ImageSequenceOutputPrefix:
459
+ """Destination bucket and prefix for an image sequence."""
460
+
461
+ bucket_name: str
462
+ key_prefix: str
463
+ s3_output_provider: Optional[CustomCredentials] = None
464
+
465
+ def serialize_params(self) -> Dict:
466
+ """Convert the destination to the Lambda payload format."""
467
+ return {
468
+ 'bucketName': self.bucket_name,
469
+ 'keyPrefix': self.key_prefix,
470
+ 's3OutputProvider': (
471
+ self.s3_output_provider.serialize_params()
472
+ if self.s3_output_provider is not None else None
473
+ ),
474
+ }
475
+
476
+
477
+ @dataclass
478
+ class RenderFramesParams(RenderMediaParams):
479
+ """Parameters for rendering a PNG or JPEG image sequence."""
480
+
481
+ codec: Optional[str] = None
482
+ image_format: Literal['png', 'jpeg'] = 'png'
483
+ jpeg_quality: Optional[int] = None
484
+ frame_range: Optional[Union[int, List[int]]] = None
485
+ output_prefix: Optional[Union[str, ImageSequenceOutputPrefix]] = None
486
+ image_sequence_pattern: Optional[str] = None
487
+
488
+ def serialize_params(self) -> Dict:
489
+ """Convert the sequence parameters to the Lambda payload format."""
490
+ if self.image_format not in ('png', 'jpeg'):
491
+ raise ValueError('image_format must be "png" or "jpeg".')
492
+ if self.jpeg_quality is not None and self.image_format != 'jpeg':
493
+ raise ValueError('jpeg_quality can only be passed with image_format="jpeg".')
494
+
495
+ parameters = super().serialize_params()
496
+ parameters.update({
497
+ 'codec': None,
498
+ 'muted': True,
499
+ 'outName': None,
500
+ 'numberOfGifLoops': None,
501
+ 'jpegQuality': self.jpeg_quality if self.jpeg_quality is not None else 80,
502
+ 'output': {
503
+ 'type': 'sequence',
504
+ 'outputPrefix': (
505
+ self.output_prefix.serialize_params()
506
+ if isinstance(self.output_prefix, ImageSequenceOutputPrefix)
507
+ else self.output_prefix
508
+ ),
509
+ 'imageSequencePattern': self.image_sequence_pattern,
510
+ },
511
+ })
512
+ return parameters
513
+
514
+
438
515
  @dataclass
439
516
  class RenderStillParams:
440
517
  """
@@ -589,3 +666,6 @@ class RenderMediaProgress:
589
666
  outputSizeInBytes: Optional[int] = None
590
667
  lambdasInvoked: int = 0
591
668
  framesRendered: Optional[int] = None
669
+ framesUploaded: Optional[int] = None
670
+ outputSequence: Optional[Dict[str, Any]] = None
671
+ separateAudio: Optional[Dict[str, Any]] = None
@@ -6,6 +6,7 @@ import json
6
6
  import hashlib
7
7
  import time
8
8
  from math import ceil
9
+ from threading import Lock
9
10
  from typing import Optional, Union, List, Dict, Any
10
11
  from enum import Enum
11
12
  import warnings
@@ -17,6 +18,7 @@ from botocore.response import StreamingBody # For Lambda payload
17
18
  from .models import (
18
19
  CostsInfo,
19
20
  CustomCredentials,
21
+ RenderFramesParams,
20
22
  RenderMediaParams,
21
23
  RenderMediaProgress,
22
24
  RenderMediaResponse,
@@ -213,6 +215,7 @@ class RemotionClient:
213
215
  self.function_name = function_name.strip()
214
216
  self.force_path_style = force_path_style
215
217
  self.config = config or Config() # Provide default empty config
218
+ self._session_lock = Lock()
216
219
 
217
220
  def _generate_hash(self, payload: str) -> str: # Added type hints
218
221
  """Generate a hash for the payload."""
@@ -257,7 +260,9 @@ class RemotionClient:
257
260
  if current_config:
258
261
  client_kwargs['config'] = current_config
259
262
 
260
- return self.session.client(service_name, **client_kwargs) # type: ignore[call-overload]
263
+ # boto3 sessions cannot create clients concurrently across threads.
264
+ with self._session_lock:
265
+ return self.session.client(service_name, **client_kwargs) # type: ignore[call-overload]
261
266
 
262
267
  def _create_s3_client(self) -> Any: # Returns an S3 client type
263
268
  """Creates and returns a boto3 S3 client."""
@@ -627,6 +632,12 @@ class RemotionClient:
627
632
 
628
633
  return None
629
634
 
635
+ def render_frames_on_lambda(
636
+ self, render_params: RenderFramesParams
637
+ ) -> Optional[RenderMediaResponse]:
638
+ """Start an image sequence render and track it with get_render_progress()."""
639
+ return self.render_media_on_lambda(render_params)
640
+
630
641
  def cancel_render_on_lambda(self, render_id: str, bucket_name: str) -> None:
631
642
  """Cancel a render started with ``enable_cancellation=True``."""
632
643
  s3_client = self._create_s3_client()
@@ -1,2 +1,2 @@
1
1
  # pylint: disable=missing-module-docstring, missing-final-newline
2
- VERSION = "4.0.534"
2
+ VERSION = "4.0.536"
@@ -0,0 +1,62 @@
1
+ # pylint: disable=missing-module-docstring
2
+ import hashlib
3
+ import hmac
4
+ from typing import Union
5
+
6
+ from .exception import RemotionException, RemotionInvalidArgumentException
7
+
8
+
9
+ def validate_webhook_signature(
10
+ secret: str,
11
+ body: Union[str, bytes],
12
+ signature_header: str,
13
+ ) -> None:
14
+ """
15
+ Validate that an incoming webhook request was sent by Remotion and that its
16
+ body was not modified in transit.
17
+
18
+ Pass the webhook secret that was configured when the render was started, the
19
+ raw request body exactly as it was received, and the value of the
20
+ ``X-Remotion-Signature`` header. The function raises an exception if the
21
+ request cannot be verified and returns ``None`` if it is authentic.
22
+
23
+ The signature covers the raw JSON bytes, so pass the body as it arrived
24
+ (``request.get_data()`` in Flask, ``request.body`` in Django) and decode it
25
+ only after this function returns. Decoding and re-encoding first can change
26
+ key order and whitespace, which would break the comparison even for a
27
+ genuine request.
28
+
29
+ This mirrors ``validateWebhookSignature()`` from ``@remotion/lambda/client``
30
+ and uses the same scheme: ``"sha512="`` followed by the hex digest of an
31
+ HMAC-SHA512 over the request body, keyed with the webhook secret.
32
+ """
33
+ if not secret:
34
+ raise RemotionInvalidArgumentException(
35
+ "No 'secret' was provided to validate_webhook_signature()."
36
+ )
37
+
38
+ if body is None or body == '' or body == b'':
39
+ raise RemotionInvalidArgumentException(
40
+ "No 'body' was provided to validate_webhook_signature()."
41
+ )
42
+
43
+ if not signature_header or signature_header == 'NO_SECRET_PROVIDED':
44
+ raise RemotionException('No webhook signature was provided')
45
+
46
+ body_bytes = body.encode('utf-8') if isinstance(body, str) else body
47
+
48
+ expected = (
49
+ 'sha512='
50
+ + hmac.new(
51
+ secret.encode('utf-8'), body_bytes, hashlib.sha512
52
+ ).hexdigest()
53
+ )
54
+
55
+ # Compare as bytes: `compare_digest()` rejects two `str` values when either
56
+ # side contains non-ASCII characters, and the signature header is
57
+ # attacker-controlled, so a non-ASCII value must fail the check with a
58
+ # `RemotionException` instead of raising an uncaught `TypeError`.
59
+ if not hmac.compare_digest(
60
+ expected.encode('utf-8'), signature_header.encode('utf-8')
61
+ ):
62
+ raise RemotionException('Signatures do not match')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: remotion-lambda
3
- Version: 4.0.534
3
+ Version: 4.0.536
4
4
  Summary: Remotion Lambda client
5
5
  Home-page: https://github.com/remotion-dev/remotion/tree/main/packages/lambda-python
6
6
  Author: Jonny Burger
@@ -2,10 +2,12 @@ LICENSE
2
2
  README.md
3
3
  setup.py
4
4
  remotion_lambda/__init__.py
5
+ remotion_lambda/asyncremotionclient.py
5
6
  remotion_lambda/exception.py
6
7
  remotion_lambda/models.py
7
8
  remotion_lambda/remotionclient.py
8
9
  remotion_lambda/version.py
10
+ remotion_lambda/webhook.py
9
11
  remotion_lambda.egg-info/PKG-INFO
10
12
  remotion_lambda.egg-info/SOURCES.txt
11
13
  remotion_lambda.egg-info/dependency_links.txt