Skip to content

Commit 74e9443

Browse files
committed
FIX: Fix batch download range handling
1 parent 12a4781 commit 74e9443

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

databento/historical/api/batch.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def _download_file(
290290
]
291291

292292
headers: Dict[str, str] = self._headers.copy()
293+
mode = "wb"
293294

294295
# Check if file already exists in partially downloaded state
295296
if os.path.isfile(output_path):
@@ -298,6 +299,7 @@ def _download_file(
298299
# Make range request for partial download,
299300
# will be from next byte to end of file.
300301
headers["Range"] = f"bytes={existing_size}-{filesize - 1}"
302+
mode = "ab"
301303

302304
with requests.get(
303305
url=self._base_url + ".download",
@@ -309,6 +311,6 @@ def _download_file(
309311
) as response:
310312
check_http_error(response)
311313

312-
with open(output_path, mode="wb") as f:
314+
with open(output_path, mode=mode) as f:
313315
for chunk in response.iter_content():
314316
f.write(chunk)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pprint import pprint
2+
3+
import databento as db
4+
5+
6+
if __name__ == "__main__":
7+
db.log = "debug" # Optional debug logging
8+
9+
key = "YOUR_API_KEY"
10+
client = db.Historical(key=key)
11+
12+
response = client.batch.list_files(
13+
job_id="YOUR_JOB_ID", # <-- Discover this from `.list_jobs(...)`
14+
)
15+
16+
pprint(response)

0 commit comments

Comments
 (0)