Skip to content

Commit 4fa1c42

Browse files
committed
v3.2.0
1 parent fdaaa0d commit 4fa1c42

File tree

10 files changed

+313
-107
lines changed

10 files changed

+313
-107
lines changed

docs/additional_info/changelog.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,26 @@
33
Changelog
44
=========
55

6+
3.2.0 (17-Feb-2025)
7+
-------------------
8+
9+
* Add support for `async file downloads <https://developers.lokalise.com/reference/download-files-async>`_:
10+
11+
.. code-block:: python
12+
13+
process = client.download_files_async(PROJECT_ID, {
14+
"format": "json",
15+
"original_filenames": True,
16+
"replace_breaks": False
17+
})
18+
19+
process_info = client.queued_process(
20+
PROJECT_ID,
21+
process.process_id
22+
)
23+
24+
process_info.status # => 'finished'
25+
626
3.1.1 (30-Jan-2025)
727
-------------------
828

docs/api/files.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,37 @@ Example:
7070
})
7171
response['bundle_url'] # => "https://s3-eu-west-1.amazonaws.com/path/to/bundle.zip"
7272
73+
74+
Download files async
75+
--------------------
76+
77+
.. py:function:: download_files_async(project_id, params)
78+
79+
:param str project_id: ID of the project to download file from
80+
:param dict params: Download params
81+
:return: Queued process model
82+
83+
Please note that the async file download will be performed in the background, and this method will
84+
return a :ref:`QueuedProcess <queued-process>` with a process ID.
85+
86+
Example:
87+
88+
.. code-block:: python
89+
90+
process = client.download_files_async(PROJECT_ID, {
91+
"format": "json",
92+
"original_filenames": True,
93+
"replace_breaks": False
94+
})
95+
96+
process_info = client.queued_process(
97+
PROJECT_ID,
98+
process.process_id
99+
)
100+
101+
process_info.status # => 'finished'
102+
103+
73104
Delete file
74105
-----------
75106

lokalise/client_methods/files.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ def download_files(self, project_id: str,
5151
download(params=params, parent_id=project_id)
5252
return response
5353

54+
def download_files_async(self, project_id: str,
55+
params: Dict[str, Any]) -> QueuedProcessModel:
56+
"""Downloads files from the given project asynchronously.
57+
58+
:param str project_id: ID of the project to download file from
59+
:param dict params: Download params
60+
:return: Queued process model
61+
"""
62+
raw_process = self.get_endpoint("files"). \
63+
download_async(params=params, parent_id=project_id)
64+
return QueuedProcessModel(raw_process)
65+
5466
def delete_file(self, project_id: str,
5567
file_id: Union[str, int]) -> Dict:
5668
"""Deletes a file and it's associated keys from the project.

lokalise/endpoints/files_endpoint.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,14 @@ def download(self, params: Dict[str, Any],
3434
"""
3535
path = self.path_with_params(**ids)
3636
return request.post(self.client, path + 'download', params)
37+
38+
def download_async(self, params: Dict[str, Any],
39+
**ids: Optional[Union[str, int]]) -> Dict:
40+
"""Downloads files from the project asynchronously.
41+
42+
:param dict params: Upload parameters
43+
:param ids: Identifiers for path generation
44+
:rtype dict:
45+
"""
46+
path = self.path_with_params(**ids)
47+
return request.post(self.client, path + 'async-download', params)

poetry.lock

Lines changed: 101 additions & 106 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "python-lokalise-api"
3-
version = "3.1.1"
3+
version = "3.2.0"
44
description = "Official Python interface for the Lokalise API v2"
55
authors = [
66
{name = "Ilya Krukowski", email = "golosizpru@gmail.com"}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
interactions:
2+
- request:
3+
body: '{"format": "json", "original_filenames": true, "replace_breaks": false}'
4+
headers:
5+
Accept:
6+
- application/json
7+
Connection:
8+
- keep-alive
9+
Content-Length:
10+
- '71'
11+
User-Agent:
12+
- python-lokalise-api plugin/3.1.0
13+
x-api-token:
14+
- FILTERED
15+
method: POST
16+
uri: https://api.lokalise.com/api2/projects/6504960967ab53d45e0ed7.15877499/files/async-download
17+
response:
18+
body:
19+
string: '{"process_id":"1efed4e6-461a-6d6e-a779-dea3ae8b7e9e"}'
20+
headers:
21+
Cache-Control:
22+
- max-age=0, must-revalidate, private
23+
Connection:
24+
- keep-alive
25+
Content-Type:
26+
- application/json
27+
Date:
28+
- Mon, 17 Feb 2025 16:44:01 GMT
29+
Expires:
30+
- Mon, 17 Feb 2025 16:44:01 GMT
31+
Referrer-Policy:
32+
- origin
33+
Set-Cookie:
34+
- PHPSESSID=deleted; expires=Sun, 18-Feb-2024 16:44:00 GMT; Max-Age=0; path=/;
35+
httponly
36+
Strict-Transport-Security:
37+
- max-age=31536000
38+
Transfer-Encoding:
39+
- chunked
40+
Vary:
41+
- Accept-Encoding
42+
X-Content-Type-Options:
43+
- nosniff
44+
X-Frame-Options:
45+
- deny
46+
X-Lokalise-Process-Id:
47+
- 108b4847-b35e-403a-9cf0-dbaf286ae1c2
48+
X-XSS-Protection:
49+
- 1; mode=block
50+
status:
51+
code: 200
52+
message: OK
53+
version: 1
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- application/json
7+
Connection:
8+
- keep-alive
9+
User-Agent:
10+
- python-lokalise-api plugin/3.1.0
11+
x-api-token:
12+
- FILTERED
13+
method: GET
14+
uri: https://api.lokalise.com/api2/projects/6504960967ab53d45e0ed7.15877499/processes/1efed4e6-461a-6d6e-a779-dea3ae8b7e9e
15+
response:
16+
body:
17+
string: '{"process":{"process_id":"1efed4e6-461a-6d6e-a779-dea3ae8b7e9e","type":"async-export","status":"finished","message":null,"created_by":20181,"created_at":"2025-02-17
18+
17:44:02 (Europe\/Berlin)","created_at_timestamp":1739810642,"details":{"file_size_kb":1,"total_number_of_keys":4,"download_url":"https:\/\/lokalise-live-lok-s3-fss-export.s3.eu-central-1.amazonaws.com\/export\/176692\/6504960967ab53d45e0ed7.15877499\/export\/d28ed227-ee26-49a3-8630-4f00e7629d2b?X-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v7i2Lc0I5VhWzdHIWVfvp2aGLeCvo4cQYiqX%2BmkOyeGZV0N9Z2LhLqbKKqUPAilzDxwH3jrKP%2BCiGUy0FhPjSDziufoPQuqtz67%2BHYjc68rHXKTKvvKI3lpP8oQFnMd6LmenBK75uus9A6IHsiqYtBJ%2Fjw4oM7pre8BF8ySI0ws87NvQY6mgEVModVeG44pcxxXH9b1CAOe9sVdtURWYTUg6yy%2FU%2FXpK2IE1xQbm3c1kWd998MRxIsaea%2Fo7PIuxhu9UBgFehIE2lB9BFMrGp%2Fv1RqcmATVwv6BdsWJ6s9BYl1uKJoufqJ3vwx9%2FeziarO%2FS5On67OXAvbjxQNBNlo%2BehGvNcNloAtogmRso5%2BYW0%2BwFR4Iq2kxICjx5tk8Uzc&X-Amz-Signature=7e7efee586bdcd34d3288002df2255d23ff6d24f35b1e1c1569d9ed1648c55b7&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject"}}}'
19+
headers:
20+
Cache-Control:
21+
- max-age=0, must-revalidate, no-cache, no-store, private
22+
Connection:
23+
- keep-alive
24+
Content-Type:
25+
- application/json
26+
Date:
27+
- Mon, 17 Feb 2025 16:46:09 GMT
28+
Expires:
29+
- Mon, 17 Feb 2025 16:46:09 GMT
30+
Pragma:
31+
- no-cache
32+
Referrer-Policy:
33+
- origin
34+
Set-Cookie:
35+
- PHPSESSID=deleted; expires=Sun, 18-Feb-2024 16:46:08 GMT; Max-Age=0; path=/;
36+
httponly
37+
Strict-Transport-Security:
38+
- max-age=31536000
39+
Transfer-Encoding:
40+
- chunked
41+
Vary:
42+
- Accept-Encoding
43+
X-Content-Type-Options:
44+
- nosniff
45+
X-Frame-Options:
46+
- deny
47+
X-Lokalise-Process-Id:
48+
- f2a1f9b1-4c9f-4305-bc1a-dbb0d2067f87
49+
X-XSS-Protection:
50+
- 1; mode=block
51+
status:
52+
code: 200
53+
message: OK
54+
version: 1

tests/client/files_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ def test_download_files(client):
6767
assert r"amazonaws.com" in response['bundle_url']
6868

6969

70+
@pytest.mark.vcr
71+
def test_download_files_async(client):
72+
"""Tests async files downloading
73+
"""
74+
process = client.download_files_async("6504960967ab53d45e0ed7.15877499", {
75+
"format": "json",
76+
"original_filenames": True,
77+
"replace_breaks": False
78+
})
79+
80+
assert process.process_id == "1efed4e6-461a-6d6e-a779-dea3ae8b7e9e"
81+
82+
7083
@pytest.mark.vcr
7184
def test_delete_file(client):
7285
"""Tests file deletion

tests/client/queued_processes_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,20 @@ def test_queued_process(client):
3838
assert process.created_at_timestamp == 1592566922
3939
assert process.details['files'][0]['status'] == 'finished'
4040
assert process.details['files'][0]['name_original'] == 'en.json'
41+
42+
43+
@pytest.mark.vcr
44+
def test_queued_process_async_download(client):
45+
"""Tests fetching of a queued process for an async download
46+
"""
47+
project_id = "6504960967ab53d45e0ed7.15877499"
48+
process_id = "1efed4e6-461a-6d6e-a779-dea3ae8b7e9e"
49+
process = client.queued_process(
50+
project_id,
51+
process_id
52+
)
53+
54+
assert process.process_id == process_id
55+
assert process.type == 'async-export'
56+
assert process.status == 'finished'
57+
assert 'https://lokalise-live-lok-s3-fss-export' in process.details['download_url']

0 commit comments

Comments
 (0)