Client¶
PythPandas — core HTTP client dataclass with DataFrame preprocessing.
The client targets the Pyth Pro Router (Pyth Lazer) REST API. Endpoint methods live in mixins; this class provides transport, authentication, DataFrame preprocessing, and shared infrastructure.
- class pyth_pandas.client.PythPandas(base_url='https://pyth-lazer.dourolabs.app/v1/', timeout=30, api_key=None, use_tqdm=True, tqdm_description='', numeric_columns=('price', 'bestBidPrice', 'bestAskPrice', 'confidence', 'emaPrice', 'emaConfidence', 'fundingRate', 'exponent', 'publisherCount', 'fundingRateInterval', 'priceFeedId'), str_datetime_columns=(), int_datetime_columns=(), ms_int_datetime_columns=(), us_int_datetime_columns=('timestampUs', 'feedUpdateTimestamp', 'fundingTimestamp'), bool_columns=(), drop_columns=(), json_columns=())[source]¶
Bases:
PricesMixin,GovernanceMixinHTTP client for the Pyth Pro Router that returns pandas DataFrames.
Endpoint methods live in the mixins. This class provides the HTTP transport, bearer-token authentication, DataFrame preprocessing, and error-mapping infrastructure. Use as a context manager so the underlying connection pool is closed deterministically.
- Parameters:
base_url (str) – Pyth Pro Router base URL. Pyth runs multiple endpoints (numbered 0/1/2) for redundancy; supply whichever you have been onboarded onto.
timeout (int) – Per-request timeout in seconds.
api_key (str | None) – Bearer access token. Falls back to
PYTH_API_KEYfrom the environment (after anyload_dotenv()call).use_tqdm (bool) – Whether progress bars are enabled for any future paginated helpers.
tqdm_description (str)
numeric_columns (tuple)
str_datetime_columns (tuple)
int_datetime_columns (tuple)
ms_int_datetime_columns (tuple)
us_int_datetime_columns (tuple)
bool_columns (tuple)
drop_columns (tuple)
json_columns (tuple)
Example
>>> from pyth_pandas import PythPandas >>> with PythPandas() as client: ... df = client.fetch_latest_prices( ... symbols=["Crypto.BTC/USD"], ... properties=["price", "confidence", "exponent"], ... )
- API_VERSION: ClassVar[str] = '1.0.0'¶
Upstream API version this client targets (from the OpenAPI spec).
- SUPPORTED_API_VERSIONS: ClassVar[tuple[str, ...]] = ('1.0.0',)¶
Upstream API versions this client is known to be compatible with.
- numeric_columns: tuple = ('price', 'bestBidPrice', 'bestAskPrice', 'confidence', 'emaPrice', 'emaConfidence', 'fundingRate', 'exponent', 'publisherCount', 'fundingRateInterval', 'priceFeedId')¶
Price-fetching endpoints (/latest_price, /price, /reduce_price).
- class pyth_pandas.mixins._prices.PricesMixin[source]¶
Bases:
objectPrice fetch endpoints that return one row per requested feed.
Each
fetch_*method returns aDataFrameof parsed feeds. The accompanying on-chain payloads (EVM, Solana, …) and the update timestamp are attached asdf.attrs. For the rawJsonUpdateresponse, use the matching*_rawvariant.- fetch_latest_prices(*, properties, formats=None, channel='real_time', price_feed_ids=None, symbols=None, json_binary_encoding='hex')[source]¶
Fetch the latest update and return it as a parsed-feed DataFrame.
Same arguments as
fetch_latest_prices_raw(). The returned DataFrame has one row per feed; the on-chain payloads andtimestampUsare attached ondf.attrs.- Parameters:
formats (list[str] | None) – On-chain payload formats. Defaults to
[](parsed only).channel (str) – Update channel.
price_feed_ids (list[int] | None) – Numeric feed IDs (mutually exclusive with
symbols).symbols (list[str] | None) – Feed symbols (e.g.
["Crypto.BTC/USD"]).json_binary_encoding (str | None) –
"hex"or"base64".
- Returns:
DataFrame conforming to
ParsedFeedSchema.- Return type:
DataFrame[ParsedFeedSchema]
- fetch_latest_prices_raw(*, properties, formats, channel='real_time', price_feed_ids=None, symbols=None, parsed=True, json_binary_encoding='hex')[source]¶
Fetch the latest available update for the requested feeds.
- Parameters:
properties (list[str]) – Feed properties to include (
price,confidence,exponent, …).formats (list[str]) – On-chain payload formats to include (
evm,solana,leEcdsa,leUnsigned).channel (str) – Update channel —
real_timeorfixed_rate@*.price_feed_ids (list[int] | None) – Numeric feed IDs. Mutually exclusive with
symbols.symbols (list[str] | None) – Feed symbols (e.g.
["Crypto.BTC/USD"]).parsed (bool) – Include the
parsedblock in the response.json_binary_encoding (str | None) –
"hex"or"base64"for binary payloads.
- Returns:
The raw
JsonUpdatedict.- Raises:
PythAPIError – For any non-2xx response from the upstream API.
- Return type:
- fetch_prices(*, timestamp, properties, formats=None, channel='real_time', price_feed_ids=None, symbols=None, json_binary_encoding='hex')[source]¶
DataFrame variant of
fetch_prices_raw().- Returns:
DataFrame conforming to
ParsedFeedSchema.- Parameters:
- Return type:
DataFrame[ParsedFeedSchema]
- fetch_prices_raw(*, timestamp, properties, formats, channel='real_time', price_feed_ids=None, symbols=None, parsed=True, json_binary_encoding='hex')[source]¶
Fetch updates issued at a specific point in time.
- Parameters:
timestamp (int | float | str | Timestamp) – Microsecond-resolution Unix timestamp. Accepts an int (interpreted as µs if >= 10**14, else seconds), a
pd.Timestamp, or an ISO-8601 string.channel (str) – Update channel.
parsed (bool) – Include parsed block.
json_binary_encoding (str | None) – Binary payload encoding.
- Returns:
The raw
JsonUpdatedict.- Return type:
- reduce_price(*, payload, price_feed_ids)[source]¶
DataFrame variant of
reduce_price_raw().- Parameters:
payload (JsonUpdate)
- Return type:
DataFrame[ParsedFeedSchema]
- reduce_price_raw(*, payload, price_feed_ids)[source]¶
Reduce an existing on-chain payload to only the listed feeds.
- Parameters:
payload (JsonUpdate) – A
JsonUpdatepreviously received fromfetch_latest_prices_raw,fetch_prices_raw, or the WebSocket stream.
- Returns:
A new
JsonUpdatecontaining only the requested feeds.- Return type:
Governance endpoints (/guardian_set_upgrade).
- class pyth_pandas.mixins._governance.GovernanceMixin[source]¶
Bases:
objectWormhole-related governance endpoints exposed by the Pyth Pro Router.
- get_guardian_set_upgrade()[source]¶
Get the signed Wormhole guardian set upgrade VAA body, if any.
Active when both the current and next guardian sets are present in router state, indicating that a guardian set upgrade is in progress. Returns
Nonewhen no upgrade is in progress.- Returns:
The signed upgrade dict, or
Noneif not in progress.- Return type:
SignedGuardianSetUpgrade | None