@@ -198,6 +198,7 @@ def __call__(
198
198
main_func : Callable | None = None ,
199
199
main_py : str | None = None ,
200
200
source_files : Mapping [str , str | bytes ] | None = None ,
201
+ additional_requirements : list [str ] | None = None ,
201
202
) -> Awaitable [ActorClientAsync ]:
202
203
"""Create a temporary Actor from the given main function or source files.
203
204
@@ -211,6 +212,7 @@ def __call__(
211
212
main_func: The main function of the Actor.
212
213
main_py: The `src/main.py` file of the Actor.
213
214
source_files: A dictionary of the source files of the Actor.
215
+ additional_requirements: A list of additional requirements to be added to the `requirements.txt`.
214
216
215
217
Returns:
216
218
A resource client for the created Actor.
@@ -235,6 +237,7 @@ async def _make_actor(
235
237
main_func : Callable | None = None ,
236
238
main_py : str | None = None ,
237
239
source_files : Mapping [str , str | bytes ] | None = None ,
240
+ additional_requirements : list [str ] | None = None ,
238
241
) -> ActorClientAsync :
239
242
if not (main_func or main_py or source_files ):
240
243
raise TypeError ('One of `main_func`, `main_py` or `source_files` arguments must be specified' )
@@ -270,6 +273,16 @@ async def _make_actor(
270
273
actor_source_files = actor_base_source_files .copy ()
271
274
actor_source_files .update (source_files )
272
275
276
+ if additional_requirements :
277
+ # Get the current requirements.txt content (as a string).
278
+ req_content = actor_source_files .get ('requirements.txt' , '' )
279
+ if isinstance (req_content , bytes ):
280
+ req_content = req_content .decode ('utf-8' )
281
+ # Append the additional requirements, each on a new line.
282
+ additional_reqs = '\n ' .join (additional_requirements )
283
+ req_content = req_content .strip () + '\n ' + additional_reqs + '\n '
284
+ actor_source_files ['requirements.txt' ] = req_content
285
+
273
286
# Reformat the source files in a format that the Apify API understands.
274
287
source_files_for_api = []
275
288
for file_name , file_contents in actor_source_files .items ():
0 commit comments