Skip to content

Commit d94c61e

Browse files
authored
Replace base_url with api_url in the client constructor (#53)
On the platform, we have only the API server URL without the version suffix available as environment variables in the actor, so you can't supply them directly to the client. This splits it so that users can supply just the API url to the client constructor, and the API version suffix gets appended internally (the utilized API version is an internal thing of this client, it shouldn't be passed from the outside in the first place).
1 parent 9a847c0 commit d94c61e

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Changelog
22
=========
33

4+
[0.2.0](../../releases/tag/v0.2.0) - 2021-08-09
5+
-----------------------------------------------
6+
7+
### Changed
8+
9+
- replaced `base_url` with `api_url` in the client constructor
10+
to enable easier passing of the API server url from environment variables availabl to actors on the Apify platform
11+
412
[0.1.0](../../releases/tag/v0.1.0) - 2021-08-02
513
-----------------------------------------------
614

docs/docs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,15 @@ The Apify API client.
167167

168168
***
169169

170-
#### [](#apifyclient-__init__) `ApifyClient.__init__(token=None, *, base_url='https://api.apify.com/v2', max_retries=8, min_delay_between_retries_millis=500)`
170+
#### [](#apifyclient-__init__) `ApifyClient.__init__(token=None, *, api_url=None, max_retries=8, min_delay_between_retries_millis=500)`
171171

172172
Initialize the Apify API Client.
173173

174174
* **Parameters**
175175

176176
* **token** (`str`, *optional*) – The Apify API token
177177

178-
* **base_url** (`str`, *optional*) – The URL of the Apify API server to which to connect to. Defaults to [https://api.apify.com/v2](https://api.apify.com/v2)
178+
* **api_url** (`str`, *optional*) – The URL of the Apify API server to which to connect to. Defaults to [https://api.apify.com](https://api.apify.com)
179179

180180
* **max_retries** (`int`, *optional*) – How many times to retry a failed request at most
181181

src/apify_client/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.0'
1+
__version__ = '0.2.0'

src/apify_client/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
WebhookDispatchCollectionClient,
2727
)
2828

29-
DEFAULT_BASE_API_URL = 'https://api.apify.com/v2'
29+
DEFAULT_API_URL = 'https://api.apify.com'
30+
API_VERSION = 'v2'
3031

3132

3233
class ApifyClient:
@@ -36,21 +37,22 @@ def __init__(
3637
self,
3738
token: Optional[str] = None,
3839
*,
39-
base_url: str = DEFAULT_BASE_API_URL,
40+
api_url: Optional[str] = None,
4041
max_retries: int = 8,
4142
min_delay_between_retries_millis: int = 500,
4243
):
4344
"""Initialize the Apify API Client.
4445
4546
Args:
4647
token (str, optional): The Apify API token
47-
base_url (str, optional): The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com/v2
48+
api_url (str, optional): The URL of the Apify API server to which to connect to. Defaults to https://api.apify.com
4849
max_retries (int, optional): How many times to retry a failed request at most
4950
min_delay_between_retries_millis (int, optional): How long will the client wait between retrying requests
5051
(increases exponentially from this value)
5152
"""
5253
self.token = token
53-
self.base_url = base_url
54+
api_url = (api_url or DEFAULT_API_URL).rstrip('/')
55+
self.base_url = f'{api_url}/{API_VERSION}'
5456
self.max_retries = max_retries
5557
self.min_delay_between_retries_millis = min_delay_between_retries_millis
5658

0 commit comments

Comments
 (0)