Skip to content

Commit 657cdda

Browse files
committed
MOD: Standardize Python client on os.PathLike
1 parent 828a7fd commit 657cdda

File tree

6 files changed

+48
-46
lines changed

6 files changed

+48
-46
lines changed

databento/common/dbnstore.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class FileDataSource(DataSource):
132132
The name of the file.
133133
nbytes : int
134134
The size of the data in bytes; equal to the file size.
135-
path : PathLike or str
135+
path : PathLike[str] or str
136136
The path of the file.
137137
reader : IO[bytes]
138138
A `BufferedReader` for this file-backed data.
@@ -634,7 +634,7 @@ def from_file(cls, path: PathLike[str] | str) -> DBNStore:
634634
635635
Parameters
636636
----------
637-
path : Path or str
637+
path : PathLike[str] or str
638638
The path to read from.
639639
640640
Returns
@@ -695,7 +695,7 @@ def replay(self, callback: Callable[[Any], None]) -> None:
695695
def request_full_definitions(
696696
self,
697697
client: Historical,
698-
path: Path | str | None = None,
698+
path: PathLike[str] | str | None = None,
699699
) -> DBNStore:
700700
"""
701701
Request full instrument definitions based on the metadata properties.
@@ -706,7 +706,7 @@ def request_full_definitions(
706706
----------
707707
client : Historical
708708
The historical client to use for the request (contains the API key).
709-
path : Path or str, optional
709+
path : PathLike[str] or str, optional
710710
The path to stream the data to on disk (will then return a `DBNStore`).
711711
712712
Returns
@@ -768,7 +768,7 @@ def request_symbology(self, client: Historical) -> dict[str, Any]:
768768

769769
def to_csv(
770770
self,
771-
path: Path | str,
771+
path: PathLike[str] | str,
772772
pretty_px: bool = True,
773773
pretty_ts: bool = True,
774774
map_symbols: bool = True,
@@ -780,7 +780,7 @@ def to_csv(
780780
781781
Parameters
782782
----------
783-
path : Path or str
783+
path : PathLike[str] or str
784784
The file path to write to.
785785
pretty_px : bool, default True
786786
If all price columns should be converted from `int` to `float` at
@@ -922,7 +922,7 @@ def to_df(
922922

923923
def to_parquet(
924924
self,
925-
path: Path | str,
925+
path: PathLike[str] | str,
926926
price_type: Literal["fixed", "float"] = "float",
927927
pretty_ts: bool = True,
928928
map_symbols: bool = True,
@@ -995,13 +995,13 @@ def to_parquet(
995995
if writer is not None:
996996
writer.close()
997997

998-
def to_file(self, path: Path | str) -> None:
998+
def to_file(self, path: PathLike[str] | str) -> None:
999999
"""
10001000
Write the data to a DBN file at the given path.
10011001
10021002
Parameters
10031003
----------
1004-
path : str
1004+
path : PathLike[str] or str
10051005
The file path to write to.
10061006
10071007
Raises
@@ -1021,7 +1021,7 @@ def to_file(self, path: Path | str) -> None:
10211021

10221022
def to_json(
10231023
self,
1024-
path: Path | str,
1024+
path: PathLike[str] | str,
10251025
pretty_px: bool = True,
10261026
pretty_ts: bool = True,
10271027
map_symbols: bool = True,
@@ -1033,7 +1033,7 @@ def to_json(
10331033
10341034
Parameters
10351035
----------
1036-
path : Path or str
1036+
path : PathLike[str] or str
10371037
The file path to write to.
10381038
pretty_px : bool, default True
10391039
If all price columns should be converted from `int` to `float` at

databento/common/symbology.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class MappingInterval(NamedTuple):
4343

4444

4545
def _validate_path_pair(
46-
in_file: Path | PathLike[str] | str,
47-
out_file: Path | PathLike[str] | str | None,
46+
in_file: PathLike[str] | str,
47+
out_file: PathLike[str] | str | None,
4848
) -> tuple[Path, Path]:
4949
in_file_valid = Path(in_file)
5050

@@ -74,22 +74,22 @@ def _validate_path_pair(
7474

7575

7676
def map_symbols_csv(
77-
symbology_file: Path | PathLike[str] | str,
78-
csv_file: Path | PathLike[str] | str,
79-
out_file: Path | PathLike[str] | str | None = None,
77+
symbology_file: PathLike[str] | str,
78+
csv_file: PathLike[str] | str,
79+
out_file: PathLike[str] | str | None = None,
8080
) -> Path:
8181
"""
8282
Use a `symbology.json` file to map a symbols column onto an existing CSV
8383
file. The result is written to `out_file`.
8484
8585
Parameters
8686
----------
87-
symbology_file: Path | PathLike[str] | str
87+
symbology_file: PathLike[str] | str
8888
Path to a `symbology.json` file to use as a symbology source.
89-
csv_file: Path | PathLike[str] | str
89+
csv_file: PathLike[str] | str
9090
Path to a CSV file that contains encoded DBN data; must contain
9191
a `ts_recv` or `ts_event` and `instrument_id` column.
92-
out_file: Path | PathLike[str] | str (optional)
92+
out_file: PathLike[str] | str (optional)
9393
Path to a file to write results to. If unspecified, `_mapped` will be
9494
appended to the `csv_file` name.
9595
@@ -119,21 +119,21 @@ def map_symbols_csv(
119119

120120

121121
def map_symbols_json(
122-
symbology_file: Path | PathLike[str] | str,
123-
json_file: Path | PathLike[str] | str,
124-
out_file: Path | PathLike[str] | str | None = None,
122+
symbology_file: PathLike[str] | str,
123+
json_file: PathLike[str] | str,
124+
out_file: PathLike[str] | str | None = None,
125125
) -> Path:
126126
"""
127127
Use a `symbology.json` file to insert a symbols key into records of an
128128
existing JSON file. The result is written to `out_file`.
129129
130130
Parameters
131131
----------
132-
symbology_file: Path | PathLike[str] | str
132+
symbology_file: PathLike[str] | str
133133
Path to a `symbology.json` file to use as a symbology source.
134-
json_file: Path | PathLike[str] | str
134+
json_file: PathLike[str] | str
135135
Path to a JSON file that contains encoded DBN data.
136-
out_file: Path | PathLike[str] | str (optional)
136+
out_file: PathLike[str] | str (optional)
137137
Path to a file to write results to. If unspecified, `_mapped` will be
138138
appended to the `json_file` name.
139139
@@ -243,7 +243,9 @@ def insert_metadata(self, metadata: Metadata) -> None:
243243
return
244244

245245
stype_in = SType(metadata.stype_in) if metadata.stype_in is not None else None
246-
stype_out = SType(metadata.stype_out) if metadata.stype_out is not None else None
246+
stype_out = (
247+
SType(metadata.stype_out) if metadata.stype_out is not None else None
248+
)
247249

248250
for symbol_in, entries in metadata.mappings.items():
249251
for entry in entries:
@@ -395,19 +397,19 @@ def insert_json(
395397

396398
def map_symbols_csv(
397399
self,
398-
csv_file: Path | PathLike[str] | str,
399-
out_file: Path | PathLike[str] | str | None = None,
400+
csv_file: PathLike[str] | str,
401+
out_file: PathLike[str] | str | None = None,
400402
) -> Path:
401403
"""
402404
Use the loaded symbology data to map a symbols column onto an existing
403405
CSV file. The result is written to `out_file`.
404406
405407
Parameters
406408
----------
407-
csv_file: Path | PathLike[str] | str
409+
csv_file: PathLike[str] | str
408410
Path to a CSV file that contains encoded DBN data; must contain
409411
a `ts_recv` or `ts_event` and `instrument_id` column.
410-
out_file: Path | PathLike[str] | str (optional)
412+
out_file: PathLike[str] | str (optional)
411413
Path to a file to write results to. If unspecified, `_mapped` will be
412414
appended to the `csv_file` name.
413415
@@ -474,18 +476,18 @@ def map_symbols_csv(
474476

475477
def map_symbols_json(
476478
self,
477-
json_file: Path | PathLike[str] | str,
478-
out_file: Path | PathLike[str] | str | None = None,
479+
json_file: PathLike[str] | str,
480+
out_file: PathLike[str] | str | None = None,
479481
) -> Path:
480482
"""
481483
Use the loaded symbology data to insert a symbols key into records of
482484
an existing JSON file. The result is written to `out_file`.
483485
484486
Parameters
485487
----------
486-
json_file: Path | PathLike[str] | str
488+
json_file: PathLike[str] | str
487489
Path to a JSON file that contains encoded DBN data.
488-
out_file: Path | PathLike[str] | str (optional)
490+
out_file: PathLike[str] | str (optional)
489491
Path to a file to write results to. If unspecified, `_mapped` will be
490492
appended to the `json_file` name.
491493

databento/common/validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def validate_path(value: PathLike[str] | str, param: str) -> Path:
1818
1919
Parameters
2020
----------
21-
value: PathLike or str
21+
value: PathLike[str] or str
2222
The value to validate.
2323
param : str
2424
The name of the parameter being validated (for any error message).
@@ -49,7 +49,7 @@ def validate_file_write_path(value: PathLike[str] | str, param: str) -> Path:
4949
5050
Parameters
5151
----------
52-
value: PathLike or str
52+
value: PathLike[str] or str
5353
The value to validate.
5454
param : str
5555
The name of the parameter being validated (for any error message).

databento/historical/api/batch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def download(
253253
254254
Parameters
255255
----------
256-
output_dir: PathLike or str
256+
output_dir: PathLike[str] or str
257257
The directory to download the file(s) to.
258258
job_id : str
259259
The batch job identifier.
@@ -397,7 +397,7 @@ async def download_async(
397397
398398
Parameters
399399
----------
400-
output_dir: PathLike or str
400+
output_dir: PathLike[str] or str
401401
The directory to download the file(s) to.
402402
job_id : str
403403
The batch job identifier.

databento/historical/api/timeseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_range(
8080
The output symbology type to resolve to.
8181
limit : int, optional
8282
The maximum number of records to return. If `None` then no limit.
83-
path : PathLike or str, optional
83+
path : PathLike[str] or str, optional
8484
The file path to stream the data to on disk (will then return a `DBNStore`).
8585
8686
Returns
@@ -177,7 +177,7 @@ async def get_range_async(
177177
The output symbology type to resolve to.
178178
limit : int, optional
179179
The maximum number of records to return. If `None` then no limit.
180-
path : PathLike or str, optional
180+
path : PathLike[str] or str, optional
181181
The file path to stream the data to on disk (will then return a `DBNStore`).
182182
183183
Returns

tests/mock_live_server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from concurrent import futures
1616
from functools import singledispatchmethod
1717
from io import BytesIO
18+
from os import PathLike
1819
from typing import Callable, NewType, TypeVar
1920

2021
import zstandard
@@ -80,7 +81,7 @@ def __init__(
8081
version: str,
8182
user_api_keys: dict[str, str],
8283
message_queue: MessageQueue,
83-
dbn_path: pathlib.Path,
84+
dbn_path: PathLike[str],
8485
mode: MockLiveMode = MockLiveMode.REPLAY,
8586
) -> None:
8687
self.__transport: asyncio.Transport
@@ -99,7 +100,7 @@ def __init__(
99100
self._is_streaming: bool = False
100101
self._repeater_tasks: set[asyncio.Task[None]] = set()
101102

102-
self._dbn_path = dbn_path
103+
self._dbn_path = pathlib.Path(dbn_path)
103104
self._user_api_keys = user_api_keys
104105

105106
@property
@@ -392,7 +393,6 @@ def _(self, message: AuthenticationRequest) -> None:
392393
)
393394
self.__transport.write(bytes(auth_success))
394395

395-
396396
@handle_client_message.register(SubscriptionRequest)
397397
def _(self, message: SubscriptionRequest) -> None:
398398
logger.info("received subscription request: %s", str(message).strip())
@@ -548,7 +548,7 @@ def _protocol_factory(
548548
user_api_keys: dict[str, str],
549549
message_queue: MessageQueue,
550550
version: str,
551-
dbn_path: pathlib.Path,
551+
dbn_path: PathLike[str],
552552
mode: MockLiveMode,
553553
) -> Callable[[], MockLiveServerProtocol]:
554554
def factory() -> MockLiveServerProtocol:
@@ -567,7 +567,7 @@ async def create(
567567
cls,
568568
host: str = "localhost",
569569
port: int = 0,
570-
dbn_path: pathlib.Path = pathlib.Path.cwd(),
570+
dbn_path: PathLike[str] = pathlib.Path.cwd(),
571571
mode: MockLiveMode = MockLiveMode.REPLAY,
572572
) -> MockLiveServer:
573573
"""
@@ -582,7 +582,7 @@ async def create(
582582
port : int
583583
The port to bind for the mock server.
584584
Defaults to 0 which will bind to an open port.
585-
dbn_path : pathlib.Path (default: cwd)
585+
dbn_path : PathLike[str] (default: cwd)
586586
A path to DBN files for streaming.
587587
The files must contain the schema name and end with
588588
`.dbn.zst`.

0 commit comments

Comments
 (0)