Databento Python Client
The official Python client library for Databento, providing fast, lightweight access to both live and historical market data from multiple venues and asset classes. It supports various schemas like MBO, MBP, OHLCV, and trades, and features an efficient Databento Binary Encoding (DBN) for data storage. The library is actively maintained with frequent releases, currently at version 0.75.0, offering consistent message schemas across live and historical data.
Warnings
- breaking `ts_out` field on record types is now permanent, and `__dict__` attribute has been removed from all Python record classes.
- gotcha A memory leak of approximately 64 bytes per record object was present in Python bindings due to a `pyo3` 0.28 regression.
- breaking The `DBNRecord` union type was moved from `databento.common.types` to `databento_dbn.DBNRecord`.
- breaking Multiple API and client library changes affected symbology types (stype) and field renaming. `product_id` was renamed to `instrument_id`. The `smart` stype was split into `parent` and `continuous`. The `native` stype was renamed to `raw_symbol`. The `product_id` stype was renamed to `instrument_id`.
- breaking The Databento Binary Encoding (DBN) format changed from `dbz` to `dbn`, and the `timeseries.stream` endpoint was renamed to `timeseries.get_range`.
- deprecated The `mode` parameter in `metadata.get_cost` has been deprecated and will be removed in a future release.
- breaking Support for Python 3.9 was removed due to its end-of-life status.
Install
-
pip install -U databento
Imports
- databento
import databento as db
- DBNRecord
from databento_dbn import DBNRecord
Quickstart
import databento as db
import os
api_key = os.environ.get('DATABENTO_API_KEY', 'YOUR_API_KEY')
if api_key == 'YOUR_API_KEY':
print("Warning: DATABENTO_API_KEY environment variable not set. Using placeholder.")
client = db.Historical(api_key)
try:
data = client.timeseries.get_range(
dataset="GLBX.MDP3",
schema="trades",
symbols=["ES.FUT"],
stype_in="parent",
start="2023-01-01T00:00",
end="2023-01-01T01:00",
limit=100
)
df = data.to_df()
print(df.head())
except Exception as e:
print(f"An error occurred: {e}")