Skip to content

Commit 7fab55f

Browse files
author
Dane Rigby
committed
ADD: Optional dataset to metadata.list_fields
1 parent 0a84db3 commit 7fab55f

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- Added support for `listing_id`, `issuer_id`, and `security_id` as `stype_in`
77
values for the security master and corporate actions reference data
88
endpoints, and `security_id` for the adjustment factors endpoint
9+
- Added a `dataset` parameter to `MetadataHttpAPI.list_fields()`. If not
10+
provided, the returned fields are for the latest DBN encoding version,
11+
which may not match a specific dataset's schema
912

1013
## 0.83.0 - 2026-08-04
1114

databento/historical/api/metadata.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def list_fields(
123123
self,
124124
schema: Schema | str,
125125
encoding: Encoding | str,
126+
dataset: Dataset | str | None = None,
126127
) -> list[dict[str, str]]:
127128
"""
128129
List all fields for a particular schema and encoding from Databento.
@@ -135,6 +136,10 @@ def list_fields(
135136
The data record schema for the request.
136137
encoding : Encoding or str {'dbn', 'csv', 'json'}
137138
The data encoding.
139+
dataset : Dataset or str, optional
140+
The dataset code (string identifier) used to determine which fields are relevant.
141+
If `None` then the fields for the latest DBN encoding version are returned,
142+
which may differ from a specific dataset's schema.
138143
139144
Returns
140145
-------
@@ -145,6 +150,10 @@ def list_fields(
145150
params: list[tuple[str, str | Any]] = [
146151
("schema", validate_enum(schema, Schema, "schema")),
147152
("encoding", validate_enum(encoding, Encoding, "encoding")),
153+
(
154+
"dataset",
155+
validate_semantic_string(dataset, "dataset") if dataset is not None else None,
156+
),
148157
]
149158

150159
response: Response = self._get(

tests/test_historical_metadata.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,42 @@ def test_list_fields_sends_expected_request(
9494
assert call["url"] == f"{historical_client.gateway}/v{db.API_VERSION}/metadata.list_fields"
9595
assert ("schema", "mbo") in call["params"]
9696
assert ("encoding", "dbn") in call["params"]
97+
assert ("dataset", None) in call["params"]
98+
assert sorted(call["headers"].keys()) == ["accept", "user-agent"]
99+
assert call["headers"]["accept"] == "application/json"
100+
assert all(v in call["headers"]["user-agent"] for v in ("Databento/", "Python/"))
101+
assert call["timeout"] == (100, 100)
102+
assert isinstance(call["auth"], requests.auth.HTTPBasicAuth)
103+
104+
105+
@pytest.mark.parametrize(
106+
"dataset",
107+
[
108+
"GLBX.MDP3",
109+
Dataset.GLBX_MDP3,
110+
],
111+
)
112+
def test_list_fields_with_dataset_sends_expected_request(
113+
monkeypatch: pytest.MonkeyPatch,
114+
historical_client: Historical,
115+
dataset: Dataset | str,
116+
) -> None:
117+
# Arrange
118+
monkeypatch.setattr(requests, "get", mocked_get := MagicMock())
119+
120+
# Act
121+
historical_client.metadata.list_fields(
122+
schema="mbo",
123+
encoding="dbn",
124+
dataset=dataset,
125+
)
126+
127+
# Assert
128+
call = mocked_get.call_args.kwargs
129+
assert call["url"] == f"{historical_client.gateway}/v{db.API_VERSION}/metadata.list_fields"
130+
assert ("schema", "mbo") in call["params"]
131+
assert ("encoding", "dbn") in call["params"]
132+
assert ("dataset", "GLBX.MDP3") in call["params"]
97133
assert sorted(call["headers"].keys()) == ["accept", "user-agent"]
98134
assert call["headers"]["accept"] == "application/json"
99135
assert all(v in call["headers"]["user-agent"] for v in ("Databento/", "Python/"))

0 commit comments

Comments
 (0)