Pyth Client in Python
A Python library to retrieve data from Pyth account structures off the Solana blockchain.
NOTE: This library requires Python 3.7 or greater due to from __future__ import annotations.
Usage
Install the library:
pip install pythclient
You can then read the current Pyth price using the following:
from pythclient.pythclient import PythClient
from pythclient.pythaccounts import PythPriceAccount
from pythclient.utils import get_key
solana_network="devnet"
async with PythClient(
first_mapping_account_key=get_key(solana_network, "mapping"),
program_key=get_key(solana_network, "program") if use_program else None,
) as c:
await c.refresh_all_prices()
products = await c.get_products()
for p in products:
print(p.attrs)
prices = await p.get_prices()
for _, pr in prices.items():
print(
pr.price_type,
pr.aggregate_price_status,
pr.aggregate_price,
"p/m",
pr.aggregate_price_confidence_interval,
)
This code snippet lists the products on pyth and the price for each product. Sample output is:
{'symbol': 'Crypto.ETH/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'ETH/USD', 'generic_symbol': 'ETHUSD', 'base': 'ETH'}
PythPriceType.PRICE PythPriceStatus.TRADING 4390.286 p/m 2.4331
{'symbol': 'Crypto.SOL/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'SOL/USD', 'generic_symbol': 'SOLUSD', 'base': 'SOL'}
PythPriceType.PRICE PythPriceStatus.TRADING 192.27550000000002 p/m 0.0485
{'symbol': 'Crypto.SRM/USD', 'asset_type': 'Crypto', 'quote_currency': 'USD', 'description': 'SRM/USD', 'generic_symbol': 'SRMUSD', 'base': 'SRM'}
PythPriceType.PRICE PythPriceStatus.UNKNOWN None p/m None
...
The examples directory includes some example applications that demonstrate how to use this library:
examples/dump.pyis a detailed usage example that demonstrates the asynchronous API to update prices using a websocket subscription or account polling.examples/read_one_price_feed.pyshows how to read the price of a single price feed using its account key.
Developer Setup
Using python 3.7 or newer, create, and activate a virtual environment:
python3 -m venv ve
. ve/bin/activate
To install this library in editable mode with test dependencies:
pip install -e '.[testing]'
To run the unit tests:
pytest
If html based test coverage is more your jam:
pytest --cov-report=html
The coverage webpages will be in the htmlcov directory.
Distribution
To build the package for distribution to pypi, first install dependencies:
python3 -m pip install --upgrade twine build
Next, edit setup.py and bump the version field.
Then build the package by running:
python3 -m build
This command will produce packages in the dist/ directory.
Upload these packages to pypi by running:
python3 -m twine upload --repository pypi dist/*
This command will require you to log in to a pypi account.
Metadata
Release files for pythclient 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pythclient-0.2.2.tar.gz | 65.4 kB | Without provenance | Details for pythclient-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pythclient-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for pythclient-0.2.2-py3-none-any.whl |
Total release size: 100.1 kB
Release files / pythclient-0.2.2.tar.gz
| Download URL | pythclient-0.2.2.tar.gz |
|---|---|
| Size | 65.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11992c56870f07be347b55a290dd774c5ee35f592bfab065256b4aed2adff99c
|
|
BLAKE2b-256 checksum How to use checksums |
6b463c5a924a94ebfb750b05fdaf0741ec76c6fbe8a282ff2bdd27581d3d5243
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / pythclient-0.2.2-py3-none-any.whl
| Download URL | pythclient-0.2.2-py3-none-any.whl |
|---|---|
| Size | 34.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47f09a403b0caae5dd3ed6fda424ce93adeb2a26d59662a1c16c952343deda45
|
|
BLAKE2b-256 checksum How to use checksums |
6faf9cc9717007bb371119d4d316a044f28e528cec748c179d7bdae3d94e2ebb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for pythclient 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.