@@ -13,48 +13,97 @@ class Configuration:
13
13
14
14
_default_instance : Optional ['Configuration' ] = None
15
15
16
- def __init__ (self ) -> None :
17
- """Create a `Configuration` instance."""
16
+ def __init__ (
17
+ self ,
18
+ * ,
19
+ api_base_url : Optional [str ] = None ,
20
+ api_public_base_url : Optional [str ] = None ,
21
+ container_port : Optional [int ] = None ,
22
+ container_url : Optional [str ] = None ,
23
+ default_dataset_id : Optional [str ] = None ,
24
+ default_key_value_store_id : Optional [str ] = None ,
25
+ default_request_queue_id : Optional [str ] = None ,
26
+ input_key : Optional [str ] = None ,
27
+ max_used_cpu_ratio : Optional [float ] = None ,
28
+ metamorph_after_sleep_millis : Optional [int ] = None ,
29
+ persist_state_interval_millis : Optional [int ] = None ,
30
+ persist_storage : Optional [bool ] = None ,
31
+ proxy_hostname : Optional [str ] = None ,
32
+ proxy_password : Optional [str ] = None ,
33
+ proxy_port : Optional [int ] = None ,
34
+ proxy_status_url : Optional [str ] = None ,
35
+ purge_on_start : Optional [bool ] = None ,
36
+ token : Optional [str ] = None ,
37
+ system_info_interval_millis : Optional [int ] = None ,
38
+ ) -> None :
39
+ """Create a `Configuration` instance.
40
+
41
+ All the parameters are loaded by default from environment variables when running on the Apify platform.
42
+ You can override them here in the Configuration constructor, which might be useful for local testing of your actors.
43
+
44
+ Args:
45
+ api_base_url (str, optional): The URL of the Apify API.
46
+ This is the URL actually used for connecting to the API, so it can contain an IP address when running in a container on the platform.
47
+ api_public_base_url (str, optional): The public URL of the Apify API.
48
+ This will always contain the public URL of the API, even when running in a container on the platform.
49
+ Useful for generating shareable URLs to key-value store records or datasets.
50
+ container_port (int, optional): The port on which the container can listen for HTTP requests.
51
+ container_url (str, optional): The URL on which the container can listen for HTTP requests.
52
+ default_dataset_id (str, optional): The ID of the default dataset for the actor.
53
+ default_key_value_store_id (str, optional): The ID of the default key-value store for the actor.
54
+ default_request_queue_id (str, optional): The ID of the default request queue for the actor.
55
+ input_key (str, optional): The key of the input record in the actor's default key-value store
56
+ max_used_cpu_ratio (float, optional): The CPU usage above which the SYSTEM_INFO event will report the CPU is overloaded.
57
+ metamorph_after_sleep_millis (int, optional): How long should the actor sleep after calling metamorph.
58
+ persist_state_interval_millis (int, optional): How often should the actor emit the PERSIST_STATE event.
59
+ persist_storage (bool, optional): Whether the actor should persist its used storages to the filesystem when running locally.
60
+ proxy_hostname (str, optional): The hostname of Apify Proxy.
61
+ proxy_password (str, optional): The password for Apify Proxy.
62
+ proxy_port (str, optional): The port of Apify Proxy.
63
+ proxy_status_url (str, optional): The URL on which the Apify Proxy status page is available.
64
+ purge_on_start (str, optional): Whether the actor should purge its default storages on startup, when running locally.
65
+ token (str, optional): The API token for the Apify API this actor should use.
66
+ system_info_interval_millis (str, optional): How often should the actor emit the SYSTEM_INFO event when running locally.
67
+ """
18
68
self .actor_build_id = _fetch_and_parse_env_var (ApifyEnvVars .ACTOR_BUILD_ID )
19
69
self .actor_build_number = _fetch_and_parse_env_var (ApifyEnvVars .ACTOR_BUILD_NUMBER )
20
70
self .actor_events_ws_url = _fetch_and_parse_env_var (ApifyEnvVars .ACTOR_EVENTS_WS_URL )
21
71
self .actor_id = _fetch_and_parse_env_var (ApifyEnvVars .ACTOR_ID )
22
72
self .actor_run_id = _fetch_and_parse_env_var (ApifyEnvVars .ACTOR_RUN_ID )
23
73
self .actor_task_id = _fetch_and_parse_env_var (ApifyEnvVars .ACTOR_TASK_ID )
24
- self .api_base_url = _fetch_and_parse_env_var (ApifyEnvVars .API_BASE_URL , 'https://api.apify.com' )
25
- self .api_public_base_url = _fetch_and_parse_env_var (ApifyEnvVars .API_PUBLIC_BASE_URL , 'https://api.apify.com' )
74
+ self .api_base_url = api_base_url or _fetch_and_parse_env_var (ApifyEnvVars .API_BASE_URL , 'https://api.apify.com' )
75
+ self .api_public_base_url = api_public_base_url or _fetch_and_parse_env_var (ApifyEnvVars .API_PUBLIC_BASE_URL , 'https://api.apify.com' )
26
76
self .chrome_executable_path = _fetch_and_parse_env_var (ApifyEnvVars .CHROME_EXECUTABLE_PATH )
27
- self .container_port = _fetch_and_parse_env_var (ApifyEnvVars .CONTAINER_PORT , 4321 )
28
- self .container_url = _fetch_and_parse_env_var (ApifyEnvVars .CONTAINER_URL , 'http://localhost:4321' )
77
+ self .container_port = container_port or _fetch_and_parse_env_var (ApifyEnvVars .CONTAINER_PORT , 4321 )
78
+ self .container_url = container_url or _fetch_and_parse_env_var (ApifyEnvVars .CONTAINER_URL , 'http://localhost:4321' )
29
79
self .dedicated_cpus = _fetch_and_parse_env_var (ApifyEnvVars .DEDICATED_CPUS )
30
80
self .default_browser_path = _fetch_and_parse_env_var (ApifyEnvVars .DEFAULT_BROWSER_PATH )
31
- self .default_dataset_id = _fetch_and_parse_env_var (ApifyEnvVars .DEFAULT_DATASET_ID , 'default' )
32
- self .default_key_value_store_id = _fetch_and_parse_env_var (ApifyEnvVars .DEFAULT_KEY_VALUE_STORE_ID , 'default' )
33
- self .default_request_queue_id = _fetch_and_parse_env_var (ApifyEnvVars .DEFAULT_REQUEST_QUEUE_ID , 'default' )
81
+ self .default_dataset_id = default_dataset_id or _fetch_and_parse_env_var (ApifyEnvVars .DEFAULT_DATASET_ID , 'default' )
82
+ self .default_key_value_store_id = default_key_value_store_id or _fetch_and_parse_env_var (ApifyEnvVars .DEFAULT_KEY_VALUE_STORE_ID , 'default' )
83
+ self .default_request_queue_id = default_request_queue_id or _fetch_and_parse_env_var (ApifyEnvVars .DEFAULT_REQUEST_QUEUE_ID , 'default' )
34
84
self .disable_browser_sandbox = _fetch_and_parse_env_var (ApifyEnvVars .DISABLE_BROWSER_SANDBOX , False )
35
85
self .headless = _fetch_and_parse_env_var (ApifyEnvVars .HEADLESS , True )
36
- self .input_key = _fetch_and_parse_env_var (ApifyEnvVars .INPUT_KEY , 'INPUT' )
86
+ self .input_key = input_key or _fetch_and_parse_env_var (ApifyEnvVars .INPUT_KEY , 'INPUT' )
37
87
self .input_secrets_private_key_file = _fetch_and_parse_env_var (ApifyEnvVars .INPUT_SECRETS_PRIVATE_KEY_FILE )
38
88
self .input_secrets_private_key_passphrase = _fetch_and_parse_env_var (ApifyEnvVars .INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE )
39
89
self .is_at_home = _fetch_and_parse_env_var (ApifyEnvVars .IS_AT_HOME , False )
90
+ self .max_used_cpu_ratio = max_used_cpu_ratio or _fetch_and_parse_env_var (ApifyEnvVars .MAX_USED_CPU_RATIO , 0.95 )
40
91
self .memory_mbytes = _fetch_and_parse_env_var (ApifyEnvVars .MEMORY_MBYTES )
41
92
self .meta_origin = _fetch_and_parse_env_var (ApifyEnvVars .META_ORIGIN )
42
- self .metamorph_after_sleep_millis = _fetch_and_parse_env_var (ApifyEnvVars .METAMORPH_AFTER_SLEEP_MILLIS , 300000 )
43
- self .persist_state_interval_millis = _fetch_and_parse_env_var (ApifyEnvVars .PERSIST_STATE_INTERVAL_MILLIS , 60000 )
44
- self .persist_storage = _fetch_and_parse_env_var (ApifyEnvVars .PERSIST_STORAGE )
45
- self .proxy_hostname = _fetch_and_parse_env_var (ApifyEnvVars .PROXY_HOSTNAME , 'proxy.apify.com' )
46
- self .proxy_password = _fetch_and_parse_env_var (ApifyEnvVars .PROXY_PASSWORD )
47
- self .proxy_port = _fetch_and_parse_env_var (ApifyEnvVars .PROXY_PORT , 8000 )
48
- self .proxy_status_url = _fetch_and_parse_env_var (ApifyEnvVars .PROXY_STATUS_URL , 'http://proxy.apify.com' )
49
- self .purge_on_start = _fetch_and_parse_env_var (ApifyEnvVars .PURGE_ON_START , True )
93
+ self .metamorph_after_sleep_millis = metamorph_after_sleep_millis or _fetch_and_parse_env_var (ApifyEnvVars .METAMORPH_AFTER_SLEEP_MILLIS , 300000 ) # noqa: E501
94
+ self .persist_state_interval_millis = persist_state_interval_millis or _fetch_and_parse_env_var (ApifyEnvVars .PERSIST_STATE_INTERVAL_MILLIS , 60000 ) # noqa: E501
95
+ self .persist_storage = persist_storage or _fetch_and_parse_env_var (ApifyEnvVars .PERSIST_STORAGE )
96
+ self .proxy_hostname = proxy_hostname or _fetch_and_parse_env_var (ApifyEnvVars .PROXY_HOSTNAME , 'proxy.apify.com' )
97
+ self .proxy_password = proxy_password or _fetch_and_parse_env_var (ApifyEnvVars .PROXY_PASSWORD )
98
+ self .proxy_port = proxy_port or _fetch_and_parse_env_var (ApifyEnvVars .PROXY_PORT , 8000 )
99
+ self .proxy_status_url = proxy_status_url or _fetch_and_parse_env_var (ApifyEnvVars .PROXY_STATUS_URL , 'http://proxy.apify.com' )
100
+ self .purge_on_start = purge_on_start or _fetch_and_parse_env_var (ApifyEnvVars .PURGE_ON_START , True )
50
101
self .started_at = _fetch_and_parse_env_var (ApifyEnvVars .STARTED_AT )
51
102
self .timeout_at = _fetch_and_parse_env_var (ApifyEnvVars .TIMEOUT_AT )
52
- self .token = _fetch_and_parse_env_var (ApifyEnvVars .TOKEN )
103
+ self .token = token or _fetch_and_parse_env_var (ApifyEnvVars .TOKEN )
53
104
self .user_id = _fetch_and_parse_env_var (ApifyEnvVars .USER_ID )
54
105
self .xvfb = _fetch_and_parse_env_var (ApifyEnvVars .XVFB , False )
55
- self .system_info_interval_millis = _fetch_and_parse_env_var (ApifyEnvVars .SYSTEM_INFO_INTERVAL_MILLIS , 60000 )
56
-
57
- self .max_used_cpu_ratio = 0.95
106
+ self .system_info_interval_millis = system_info_interval_millis or _fetch_and_parse_env_var (ApifyEnvVars .SYSTEM_INFO_INTERVAL_MILLIS , 60000 )
58
107
59
108
@classmethod
60
109
def _get_default_instance (cls ) -> 'Configuration' :
0 commit comments