Skip to content

Commit 5608b4d

Browse files
committed
Remove Actor.config
1 parent 3813ea3 commit 5608b4d

16 files changed

+75
-73
lines changed

docs/02_concepts/09_running_webserver.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The URL is available in the following places:
1313

1414
- In Apify Console, on the Actor run details page as the **Container URL** field.
1515
- In the API as the `container_url` property of the [Run object](https://docs.apify.com/api/v2#/reference/actors/run-object/get-run).
16-
- In the Actor as the `Actor.config.container_url` property.
16+
- In the Actor as the `Actor.configuration.container_url` property.
1717

18-
The web server running inside the container must listen at the port defined by the `Actor.config.container_port` property. When running Actors locally, the port defaults to `4321`, so the web server will be accessible at `http://localhost:4321`.
18+
The web server running inside the container must listen at the port defined by the `Actor.configuration.container_port` property. When running Actors locally, the port defaults to `4321`, so the web server will be accessible at `http://localhost:4321`.
1919

2020
## Example
2121

docs/02_concepts/code/07_webhook_preventing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async def main() -> None:
77
webhook = Webhook(
88
event_types=['ACTOR.RUN.FAILED'],
99
request_url='https://example.com/run-failed',
10-
idempotency_key=Actor.config.actor_run_id,
10+
idempotency_key=Actor.configuration.actor_run_id,
1111
)
1212

1313
# Add the webhook to the Actor.

docs/02_concepts/code/09_webserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def run_server() -> None:
2222
# and save a reference to the server.
2323
global http_server
2424
with ThreadingHTTPServer(
25-
('', Actor.config.web_server_port), RequestHandler
25+
('', Actor.configuration.web_server_port), RequestHandler
2626
) as server:
27-
Actor.log.info(f'Server running on {Actor.config.web_server_port}')
27+
Actor.log.info(f'Server running on {Actor.configuration.web_server_port}')
2828
http_server = server
2929
server.serve_forever()
3030

docs/02_concepts/code/conditional_actor_charge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ async def main() -> None:
1313
if Actor.get_charging_manager().get_pricing_info().is_pay_per_event:
1414
# highlight-end
1515
await Actor.push_data({'hello': 'world'}, 'dataset-item')
16-
elif charged_items < (Actor.config.max_paid_dataset_items or 0):
16+
elif charged_items < (Actor.configuration.max_paid_dataset_items or 0):
1717
await Actor.push_data({'hello': 'world'})
1818
charged_items += 1

docs/03_guides/code/03_playwright.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async def main() -> None:
4040
async with async_playwright() as playwright:
4141
# Configure the browser to launch in headless mode as per Actor configuration.
4242
browser = await playwright.chromium.launch(
43-
headless=Actor.config.headless,
43+
headless=Actor.configuration.headless,
4444
args=['--disable-gpu'],
4545
)
4646
context = await browser.new_context()

docs/03_guides/code/04_selenium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async def main() -> None:
4141
Actor.log.info('Launching Chrome WebDriver...')
4242
chrome_options = ChromeOptions()
4343

44-
if Actor.config.headless:
44+
if Actor.configuration.headless:
4545
chrome_options.add_argument('--headless')
4646

4747
chrome_options.add_argument('--no-sandbox')

docs/04_upgrading/upgrading_to_v3.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ Support for Python 3.9 has been dropped. The Apify Python SDK v3.x now requires
1515
- Services in `Actor` can't be changed after calling `Actor.init`, entering the `async with Actor` context manager or after requesting them from the `Actor`
1616
- Services in `Actor` can be different from services in Crawler
1717

18+
1819
**Now (v3.0):**
1920

2021
```python
2122
from crawlee.crawlers import BasicCrawler
22-
from crawlee.storage_clients import MemoryStorageClient, FileSystemStorageClient
23+
from crawlee.storage_clients import MemoryStorageClient
2324
from crawlee.configuration import Configuration
2425
from crawlee.events import LocalEventManager
2526
from apify import Actor
@@ -41,6 +42,9 @@ async def main():
4142
)
4243
```
4344

45+
## Removed Actor.config property
46+
- `Actor.config` property has been removed. Use `Actor.configuration` instead.
47+
4448
## Storages
4549

4650
<!-- TODO -->

src/apify/_actor.py

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,6 @@ def apify_client(self) -> ApifyClientAsync:
197197

198198
@property
199199
def configuration(self) -> Configuration:
200-
"""The Configuration instance the Actor instance uses. Deprecated."""
201-
return self.config
202-
203-
@property
204-
def config(self) -> Configuration:
205200
"""The Configuration instance the Actor instance uses."""
206201
if self._configuration:
207202
return self._configuration
@@ -225,7 +220,7 @@ def _finalize_implicit_configuration(self) -> Configuration:
225220
)
226221
# Use the configuration from the service locator
227222
self._configuration = Configuration.get_global_configuration()
228-
return self.config
223+
return self.configuration
229224

230225
def _finalize_implicit_local_storage_client(self) -> StorageClient:
231226
"""Set implicit local storage client in the actor and return it.
@@ -256,13 +251,13 @@ def event_manager(self) -> EventManager:
256251
"""The EventManager instance the Actor instance uses."""
257252
return (
258253
ApifyEventManager(
259-
configuration=self.config,
260-
persist_state_interval=self.config.persist_state_interval,
254+
configuration=self.configuration,
255+
persist_state_interval=self.configuration.persist_state_interval,
261256
)
262257
if self.is_at_home()
263258
else LocalEventManager(
264-
system_info_interval=self.config.system_info_interval,
265-
persist_state_interval=self.config.persist_state_interval,
259+
system_info_interval=self.configuration.system_info_interval,
260+
persist_state_interval=self.configuration.persist_state_interval,
266261
)
267262
)
268263

@@ -285,7 +280,7 @@ def _raise_if_cloud_requested_but_not_configured(self, *, force_cloud: bool) ->
285280
if not force_cloud:
286281
return
287282

288-
if not self.is_at_home() and self.config.token is None:
283+
if not self.is_at_home() and self.configuration.token is None:
289284
raise RuntimeError(
290285
'In order to use the Apify cloud storage from your computer, '
291286
'you need to provide an Apify token using the APIFY_TOKEN environment variable.'
@@ -304,7 +299,7 @@ async def init(self) -> None:
304299
"""
305300
if self._configuration:
306301
# Set explicitly the configuration in the service locator
307-
service_locator.set_configuration(self.config)
302+
service_locator.set_configuration(self.configuration)
308303
else:
309304
self._finalize_implicit_configuration()
310305

@@ -448,8 +443,8 @@ def new_client(
448443
(increases exponentially from this value).
449444
timeout: The socket timeout of the HTTP requests sent to the Apify API.
450445
"""
451-
token = token or self.config.token
452-
api_url = api_url or self.config.api_base_url
446+
token = token or self.configuration.token
447+
api_url = api_url or self.configuration.api_base_url
453448
return ApifyClientAsync(
454449
token=token,
455450
api_url=api_url,
@@ -496,7 +491,7 @@ async def open_dataset(
496491
id=id,
497492
alias=alias,
498493
name=name,
499-
configuration=self.config,
494+
configuration=self.configuration,
500495
storage_client=storage_client,
501496
)
502497

@@ -534,7 +529,7 @@ async def open_key_value_store(
534529
id=id,
535530
alias=alias,
536531
name=name,
537-
configuration=self.config,
532+
configuration=self.configuration,
538533
storage_client=storage_client,
539534
)
540535

@@ -575,7 +570,7 @@ async def open_request_queue(
575570
id=id,
576571
alias=alias,
577572
name=name,
578-
configuration=self.config,
573+
configuration=self.configuration,
579574
storage_client=storage_client,
580575
)
581576

@@ -624,9 +619,9 @@ async def get_input(self) -> Any:
624619
"""Get the Actor input value from the default key-value store associated with the current Actor run."""
625620
self._raise_if_not_initialized()
626621

627-
input_value = await self.get_value(self.config.input_key)
628-
input_secrets_private_key = self.config.input_secrets_private_key_file
629-
input_secrets_key_passphrase = self.config.input_secrets_private_key_passphrase
622+
input_value = await self.get_value(self.configuration.input_key)
623+
input_secrets_private_key = self.configuration.input_secrets_private_key_file
624+
input_secrets_key_passphrase = self.configuration.input_secrets_private_key_passphrase
630625
if input_secrets_private_key and input_secrets_key_passphrase:
631626
private_key = load_private_key(
632627
input_secrets_private_key,
@@ -674,7 +669,7 @@ def get_charging_manager(self) -> ChargingManager:
674669

675670
@cached_property
676671
def charging_manager_implementation(self) -> ChargingManagerImplementation:
677-
return ChargingManagerImplementation(self.config, self.apify_client)
672+
return ChargingManagerImplementation(self.configuration, self.apify_client)
678673

679674
async def charge(self, event_name: str, count: int = 1) -> ChargeResult:
680675
"""Charge for a specified number of events - sub-operations of the Actor.
@@ -767,7 +762,7 @@ def off(self, event_name: Event, listener: Callable | None = None) -> None:
767762

768763
def is_at_home(self) -> bool:
769764
"""Return `True` when the Actor is running on the Apify platform, and `False` otherwise (e.g. local run)."""
770-
return self.config.is_at_home
765+
return self.configuration.is_at_home
771766

772767
def get_env(self) -> dict:
773768
"""Return a dictionary with information parsed from all the `APIFY_XXX` environment variables.
@@ -793,7 +788,7 @@ def get_env(self) -> dict:
793788
aliases = [field_name]
794789

795790
for alias in aliases:
796-
config[alias] = getattr(self.config, field_name)
791+
config[alias] = getattr(self.configuration, field_name)
797792

798793
env_vars = {env_var.value.lower(): env_var.name.lower() for env_var in [*ActorEnvVars, *ApifyEnvVars]}
799794
return {option_name: config[env_var] for env_var, option_name in env_vars.items() if env_var in config}
@@ -870,13 +865,13 @@ async def start(
870865

871866
def _get_remaining_time(self) -> timedelta | None:
872867
"""Get time remaining from the actor timeout. Returns `None` if not on an Apify platform."""
873-
if self.is_at_home() and self.config.timeout_at:
874-
return self.config.timeout_at - datetime.now(tz=timezone.utc)
868+
if self.is_at_home() and self.configuration.timeout_at:
869+
return self.configuration.timeout_at - datetime.now(tz=timezone.utc)
875870

876871
self.log.warning(
877872
'Returning `None` instead of remaining time. Using `RemainingTime` argument is only possible when the Actor'
878873
' is running on the Apify platform and when the timeout for the Actor run is set. '
879-
f'{self.is_at_home()=}, {self.config.timeout_at=}'
874+
f'{self.is_at_home()=}, {self.configuration.timeout_at=}'
880875
)
881876
return None
882877

@@ -1081,13 +1076,13 @@ async def metamorph(
10811076
return
10821077

10831078
if not custom_after_sleep:
1084-
custom_after_sleep = self.config.metamorph_after_sleep
1079+
custom_after_sleep = self.configuration.metamorph_after_sleep
10851080

10861081
# If is_at_home() is True, config.actor_run_id is always set
1087-
if not self.config.actor_run_id:
1082+
if not self.configuration.actor_run_id:
10881083
raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.')
10891084

1090-
await self.apify_client.run(self.config.actor_run_id).metamorph(
1085+
await self.apify_client.run(self.configuration.actor_run_id).metamorph(
10911086
target_actor_id=target_actor_id,
10921087
run_input=run_input,
10931088
target_actor_build=target_actor_build,
@@ -1124,7 +1119,7 @@ async def reboot(
11241119
_ActorType._is_rebooting = True
11251120

11261121
if not custom_after_sleep:
1127-
custom_after_sleep = self.config.metamorph_after_sleep
1122+
custom_after_sleep = self.configuration.metamorph_after_sleep
11281123

11291124
# Call all the listeners for the PERSIST_STATE and MIGRATING events, and wait for them to finish.
11301125
# PERSIST_STATE listeners are called to allow the Actor to persist its state before the reboot.
@@ -1144,10 +1139,10 @@ async def reboot(
11441139
*[listener(EventMigratingData()) for listener in migrating_listeners],
11451140
)
11461141

1147-
if not self.config.actor_run_id:
1142+
if not self.configuration.actor_run_id:
11481143
raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.')
11491144

1150-
await self.apify_client.run(self.config.actor_run_id).reboot()
1145+
await self.apify_client.run(self.configuration.actor_run_id).reboot()
11511146

11521147
if custom_after_sleep:
11531148
await asyncio.sleep(custom_after_sleep.total_seconds())
@@ -1186,11 +1181,11 @@ async def add_webhook(
11861181
return
11871182

11881183
# If is_at_home() is True, config.actor_run_id is always set
1189-
if not self.config.actor_run_id:
1184+
if not self.configuration.actor_run_id:
11901185
raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.')
11911186

11921187
await self.apify_client.webhooks().create(
1193-
actor_run_id=self.config.actor_run_id,
1188+
actor_run_id=self.configuration.actor_run_id,
11941189
event_types=webhook.event_types,
11951190
request_url=webhook.request_url,
11961191
payload_template=webhook.payload_template,
@@ -1222,10 +1217,10 @@ async def set_status_message(
12221217
return None
12231218

12241219
# If is_at_home() is True, config.actor_run_id is always set
1225-
if not self.config.actor_run_id:
1220+
if not self.configuration.actor_run_id:
12261221
raise RuntimeError('actor_run_id cannot be None when running on the Apify platform.')
12271222

1228-
api_result = await self.apify_client.run(self.config.actor_run_id).update(
1223+
api_result = await self.apify_client.run(self.configuration.actor_run_id).update(
12291224
status_message=status_message, is_status_message_terminal=is_terminal
12301225
)
12311226

@@ -1280,7 +1275,7 @@ async def create_proxy_configuration(
12801275
country_code=country_code,
12811276
proxy_urls=proxy_urls,
12821277
new_url_function=new_url_function,
1283-
_actor_config=self.config,
1278+
_actor_config=self.configuration,
12841279
_apify_client=self._apify_client,
12851280
)
12861281

tests/integration/test_actor_call_timeouts.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async def main() -> None:
3030

3131
# Start another run of this actor with timeout set to the time remaining in this actor run
3232
other_run_data = await Actor.call(
33-
actor_id=Actor.config.actor_id or '',
33+
actor_id=Actor.configuration.actor_id or '',
3434
run_input={'called_from_another_actor': True},
3535
timeout='RemainingTime',
3636
)
@@ -39,13 +39,13 @@ async def main() -> None:
3939
# To make sure that the actor is started
4040
await asyncio.sleep(5)
4141
assert other_run_data.options is not None
42-
assert Actor.config.timeout_at is not None
43-
assert Actor.config.started_at is not None
42+
assert Actor.configuration.timeout_at is not None
43+
assert Actor.configuration.started_at is not None
4444

45-
remaining_time_after_actor_start = Actor.config.timeout_at - datetime.now(tz=timezone.utc)
45+
remaining_time_after_actor_start = Actor.configuration.timeout_at - datetime.now(tz=timezone.utc)
4646

4747
assert other_run_data.options.timeout > remaining_time_after_actor_start
48-
assert other_run_data.options.timeout < Actor.config.timeout_at - Actor.config.started_at
48+
assert other_run_data.options.timeout < Actor.configuration.timeout_at - Actor.configuration.started_at
4949
finally:
5050
# Make sure the other actor run is aborted
5151
await Actor.apify_client.run(other_run_data.id).abort()
@@ -77,7 +77,7 @@ async def main() -> None:
7777

7878
# Start another run of this actor with timeout set to the time remaining in this actor run
7979
other_run_data = await Actor.call(
80-
actor_id=Actor.config.actor_id or '',
80+
actor_id=Actor.configuration.actor_id or '',
8181
run_input={'called_from_another_actor': True},
8282
timeout='RemainingTime',
8383
)
@@ -88,13 +88,13 @@ async def main() -> None:
8888
await asyncio.sleep(5)
8989

9090
assert other_run_data.options is not None
91-
assert Actor.config.timeout_at is not None
92-
assert Actor.config.started_at is not None
91+
assert Actor.configuration.timeout_at is not None
92+
assert Actor.configuration.started_at is not None
9393

94-
remaining_time_after_actor_start = Actor.config.timeout_at - datetime.now(tz=timezone.utc)
94+
remaining_time_after_actor_start = Actor.configuration.timeout_at - datetime.now(tz=timezone.utc)
9595

9696
assert other_run_data.options.timeout > remaining_time_after_actor_start
97-
assert other_run_data.options.timeout < Actor.config.timeout_at - Actor.config.started_at
97+
assert other_run_data.options.timeout < Actor.configuration.timeout_at - Actor.configuration.started_at
9898
finally:
9999
# Make sure the other actor run is aborted
100100
await Actor.apify_client.run(other_run_data.id).abort()

tests/integration/test_actor_create_proxy_configuration.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ async def test_create_proxy_configuration_with_groups_and_country(
4040
async def main() -> None:
4141
await Actor.init()
4242

43-
proxy_url_suffix = f'{Actor.config.proxy_password}@{Actor.config.proxy_hostname}:{Actor.config.proxy_port}'
43+
proxy_url_suffix = (
44+
f'{Actor.configuration.proxy_password}@{Actor.configuration.proxy_hostname}:'
45+
f'{Actor.configuration.proxy_port}'
46+
)
4447
proxy_configuration = await Actor.create_proxy_configuration(actor_proxy_input={'useApifyProxy': True})
4548

4649
assert proxy_configuration is not None

0 commit comments

Comments
 (0)