pyth-hermes 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ # Static checks run once on a single modern interpreter. mypy targets 3.10
10
+ # (its config floor); ruff is interpreter-independent.
11
+ lint:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.12"
18
+ - name: Install
19
+ run: |
20
+ python -m pip install --upgrade pip
21
+ pip install -e ".[dev]"
22
+ - name: Ruff
23
+ run: ruff check .
24
+ - name: Mypy (strict)
25
+ run: mypy
26
+
27
+ # Runtime tests run on every supported interpreter, including 3.9, to verify
28
+ # true 3.9 compatibility (requires-python >= 3.9).
29
+ test:
30
+ runs-on: ubuntu-latest
31
+ strategy:
32
+ fail-fast: false
33
+ matrix:
34
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
35
+ steps:
36
+ - uses: actions/checkout@v4
37
+ - name: Set up Python ${{ matrix.python-version }}
38
+ uses: actions/setup-python@v5
39
+ with:
40
+ python-version: ${{ matrix.python-version }}
41
+ - name: Install
42
+ run: |
43
+ python -m pip install --upgrade pip
44
+ pip install -e ".[dev]"
45
+ - name: Pytest
46
+ run: pytest -q
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Robert Ruben
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,171 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyth-hermes
3
+ Version: 0.1.0
4
+ Summary: Python client for the Pyth Network Hermes price-oracle API (sync + async, SSE streaming).
5
+ Project-URL: Homepage, https://github.com/robertruben98/pyth-hermes
6
+ Project-URL: Repository, https://github.com/robertruben98/pyth-hermes
7
+ Project-URL: Documentation, https://docs.pyth.network/price-feeds/core/how-pyth-works/hermes
8
+ Project-URL: Issues, https://github.com/robertruben98/pyth-hermes/issues
9
+ Author: Robert Ruben
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: defi,hermes,oracle,price-feed,pyth,solana
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.9
24
+ Requires-Dist: httpx-sse>=0.4
25
+ Requires-Dist: httpx>=0.27
26
+ Requires-Dist: pydantic>=2.6
27
+ Provides-Extra: dev
28
+ Requires-Dist: mypy>=1.10; extra == 'dev'
29
+ Requires-Dist: pandas-stubs; extra == 'dev'
30
+ Requires-Dist: pandas>=2.0; extra == 'dev'
31
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
32
+ Requires-Dist: pytest>=8.0; extra == 'dev'
33
+ Requires-Dist: respx>=0.21; extra == 'dev'
34
+ Requires-Dist: ruff>=0.5; extra == 'dev'
35
+ Provides-Extra: pandas
36
+ Requires-Dist: pandas>=2.0; extra == 'pandas'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # pyth-hermes
40
+
41
+ A typed Python client for the [Pyth Network](https://pyth.network) **Hermes** price-oracle API. Sync **and** async clients, Pydantic v2 models, Server-Sent-Events price streaming with auto-reconnect, and a `Decimal` price helper.
42
+
43
+ - Sync (`HermesClient`) and async (`AsyncHermesClient`) APIs over `httpx`
44
+ - SSE streaming with reconnect + backoff
45
+ - Graceful 429 rate-limit handling (retries that respect the 60s window)
46
+ - Configurable `base_url` (production, beta, or paid providers) and optional API key from day one
47
+ - `mypy --strict` clean, fully type-hinted, ships `py.typed`
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install pyth-hermes
53
+ # with the optional pandas helper:
54
+ pip install "pyth-hermes[pandas]"
55
+ ```
56
+
57
+ ## Quickstart — BTC/USD price in under 5 lines
58
+
59
+ ```python
60
+ from pyth_hermes import HermesClient
61
+
62
+ client = HermesClient()
63
+ feed_id = client.get_feed_id("Crypto.BTC/USD") # exact-symbol lookup
64
+ print(client.get_price_decimal(feed_id)) # -> Decimal("63952.82...")
65
+ ```
66
+
67
+ ### Async + streaming
68
+
69
+ ```python
70
+ import asyncio
71
+ from pyth_hermes import AsyncHermesClient
72
+
73
+ BTC = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
74
+
75
+ async def main():
76
+ async with AsyncHermesClient() as client:
77
+ async for update in client.stream_prices([BTC]):
78
+ print(update.parsed[0].to_decimal())
79
+
80
+ asyncio.run(main())
81
+ ```
82
+
83
+ ### Historical price
84
+
85
+ ```python
86
+ resp = client.get_price_at(1718900000, [BTC]) # unix timestamp
87
+ print(resp.parsed[0].to_decimal())
88
+ ```
89
+
90
+ ### pandas
91
+
92
+ ```python
93
+ from pyth_hermes.pandas import updates_to_dataframe
94
+ df = updates_to_dataframe([client.get_latest_price([BTC])])
95
+ ```
96
+
97
+ ## Prices and exponents
98
+
99
+ Pyth returns integer prices plus an exponent. The real value is `price * 10**expo`, computed exactly as a `Decimal`:
100
+
101
+ ```python
102
+ from pyth_hermes import price_to_decimal
103
+ price_to_decimal(6395282153102, -8) # Decimal("63952.82153102")
104
+ ```
105
+
106
+ `RpcPrice.to_decimal()` and `ParsedPriceUpdate.to_decimal()` are convenience wrappers.
107
+
108
+ ## Finding feed ids — use the EXACT symbol
109
+
110
+ `/v2/price_feeds?query=btc` returns **deprecated / variant** feeds (e.g. `MBTC`, `XBTC`) *before* the canonical one and matches substrings. `get_feed_id()` therefore matches on exact `attributes.symbol`:
111
+
112
+ ```python
113
+ client.get_feed_id("Crypto.BTC/USD")
114
+ # -> "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
115
+ ```
116
+
117
+ ## 🔴 Authentication (changes 2026-07-31)
118
+
119
+ Today the public endpoint needs **no** API key. **From 2026-07-31 an API key becomes mandatory.** This client accepts one from day one — pass it now to be ready:
120
+
121
+ ```python
122
+ client = HermesClient(api_key="YOUR_KEY") # default: Authorization: Bearer YOUR_KEY
123
+ ```
124
+
125
+ The exact header is not finalized publicly, so both the header name and scheme are configurable:
126
+
127
+ ```python
128
+ HermesClient(api_key="KEY", api_key_header="X-Api-Key", api_key_scheme="") # -> X-Api-Key: KEY
129
+ ```
130
+
131
+ ## Endpoints / base URLs
132
+
133
+ ```python
134
+ from pyth_hermes import HermesClient
135
+
136
+ HermesClient() # production: https://hermes.pyth.network
137
+ HermesClient(base_url="https://hermes-beta.pyth.network") # beta
138
+ HermesClient(base_url="https://your-paid-provider.example") # Triton / P2P / extrnode / Liquify
139
+ ```
140
+
141
+ You may also inject your own preconfigured `httpx.Client` / `httpx.AsyncClient` via `client=...` (e.g. for custom transports, proxies, or connection pools). In that case the request host is taken from **your** client, so set `base_url` on the client itself — passing both `base_url=` and `client=` raises a `UserWarning` because the constructor's `base_url` would be a no-op. The `api_key` is still applied per-request, so it works with an injected client.
142
+
143
+ ```python
144
+ import httpx
145
+ from pyth_hermes import HermesClient
146
+
147
+ http = httpx.Client(base_url="https://your-paid-provider.example", proxy="http://localhost:8080")
148
+ client = HermesClient(api_key="KEY", client=http) # base_url comes from `http`
149
+ ```
150
+
151
+ ## Rate limits
152
+
153
+ The public endpoint allows **10 requests / 10 seconds per IP**. Exceeding it returns HTTP 429 for the next 60 seconds. The client retries 429 and 5xx responses with exponential backoff + jitter, honoring any `Retry-After` header and never exceeding the 60s rate-limit window per delay. Tune via `max_retries`, `backoff_base`, `backoff_cap`.
154
+
155
+ ## Not implemented
156
+
157
+ The TWAP endpoints (`/v2/updates/twap/...`) are intentionally omitted — the API returns HTTP 400 "deprecated and no longer available".
158
+
159
+ ## Development
160
+
161
+ ```bash
162
+ pip install -e ".[dev]"
163
+ pytest # unit tests (no network)
164
+ pytest -m integration # live smoke tests against production
165
+ mypy
166
+ ruff check .
167
+ ```
168
+
169
+ ## License
170
+
171
+ MIT
@@ -0,0 +1,133 @@
1
+ # pyth-hermes
2
+
3
+ A typed Python client for the [Pyth Network](https://pyth.network) **Hermes** price-oracle API. Sync **and** async clients, Pydantic v2 models, Server-Sent-Events price streaming with auto-reconnect, and a `Decimal` price helper.
4
+
5
+ - Sync (`HermesClient`) and async (`AsyncHermesClient`) APIs over `httpx`
6
+ - SSE streaming with reconnect + backoff
7
+ - Graceful 429 rate-limit handling (retries that respect the 60s window)
8
+ - Configurable `base_url` (production, beta, or paid providers) and optional API key from day one
9
+ - `mypy --strict` clean, fully type-hinted, ships `py.typed`
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pip install pyth-hermes
15
+ # with the optional pandas helper:
16
+ pip install "pyth-hermes[pandas]"
17
+ ```
18
+
19
+ ## Quickstart — BTC/USD price in under 5 lines
20
+
21
+ ```python
22
+ from pyth_hermes import HermesClient
23
+
24
+ client = HermesClient()
25
+ feed_id = client.get_feed_id("Crypto.BTC/USD") # exact-symbol lookup
26
+ print(client.get_price_decimal(feed_id)) # -> Decimal("63952.82...")
27
+ ```
28
+
29
+ ### Async + streaming
30
+
31
+ ```python
32
+ import asyncio
33
+ from pyth_hermes import AsyncHermesClient
34
+
35
+ BTC = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
36
+
37
+ async def main():
38
+ async with AsyncHermesClient() as client:
39
+ async for update in client.stream_prices([BTC]):
40
+ print(update.parsed[0].to_decimal())
41
+
42
+ asyncio.run(main())
43
+ ```
44
+
45
+ ### Historical price
46
+
47
+ ```python
48
+ resp = client.get_price_at(1718900000, [BTC]) # unix timestamp
49
+ print(resp.parsed[0].to_decimal())
50
+ ```
51
+
52
+ ### pandas
53
+
54
+ ```python
55
+ from pyth_hermes.pandas import updates_to_dataframe
56
+ df = updates_to_dataframe([client.get_latest_price([BTC])])
57
+ ```
58
+
59
+ ## Prices and exponents
60
+
61
+ Pyth returns integer prices plus an exponent. The real value is `price * 10**expo`, computed exactly as a `Decimal`:
62
+
63
+ ```python
64
+ from pyth_hermes import price_to_decimal
65
+ price_to_decimal(6395282153102, -8) # Decimal("63952.82153102")
66
+ ```
67
+
68
+ `RpcPrice.to_decimal()` and `ParsedPriceUpdate.to_decimal()` are convenience wrappers.
69
+
70
+ ## Finding feed ids — use the EXACT symbol
71
+
72
+ `/v2/price_feeds?query=btc` returns **deprecated / variant** feeds (e.g. `MBTC`, `XBTC`) *before* the canonical one and matches substrings. `get_feed_id()` therefore matches on exact `attributes.symbol`:
73
+
74
+ ```python
75
+ client.get_feed_id("Crypto.BTC/USD")
76
+ # -> "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
77
+ ```
78
+
79
+ ## 🔴 Authentication (changes 2026-07-31)
80
+
81
+ Today the public endpoint needs **no** API key. **From 2026-07-31 an API key becomes mandatory.** This client accepts one from day one — pass it now to be ready:
82
+
83
+ ```python
84
+ client = HermesClient(api_key="YOUR_KEY") # default: Authorization: Bearer YOUR_KEY
85
+ ```
86
+
87
+ The exact header is not finalized publicly, so both the header name and scheme are configurable:
88
+
89
+ ```python
90
+ HermesClient(api_key="KEY", api_key_header="X-Api-Key", api_key_scheme="") # -> X-Api-Key: KEY
91
+ ```
92
+
93
+ ## Endpoints / base URLs
94
+
95
+ ```python
96
+ from pyth_hermes import HermesClient
97
+
98
+ HermesClient() # production: https://hermes.pyth.network
99
+ HermesClient(base_url="https://hermes-beta.pyth.network") # beta
100
+ HermesClient(base_url="https://your-paid-provider.example") # Triton / P2P / extrnode / Liquify
101
+ ```
102
+
103
+ You may also inject your own preconfigured `httpx.Client` / `httpx.AsyncClient` via `client=...` (e.g. for custom transports, proxies, or connection pools). In that case the request host is taken from **your** client, so set `base_url` on the client itself — passing both `base_url=` and `client=` raises a `UserWarning` because the constructor's `base_url` would be a no-op. The `api_key` is still applied per-request, so it works with an injected client.
104
+
105
+ ```python
106
+ import httpx
107
+ from pyth_hermes import HermesClient
108
+
109
+ http = httpx.Client(base_url="https://your-paid-provider.example", proxy="http://localhost:8080")
110
+ client = HermesClient(api_key="KEY", client=http) # base_url comes from `http`
111
+ ```
112
+
113
+ ## Rate limits
114
+
115
+ The public endpoint allows **10 requests / 10 seconds per IP**. Exceeding it returns HTTP 429 for the next 60 seconds. The client retries 429 and 5xx responses with exponential backoff + jitter, honoring any `Retry-After` header and never exceeding the 60s rate-limit window per delay. Tune via `max_retries`, `backoff_base`, `backoff_cap`.
116
+
117
+ ## Not implemented
118
+
119
+ The TWAP endpoints (`/v2/updates/twap/...`) are intentionally omitted — the API returns HTTP 400 "deprecated and no longer available".
120
+
121
+ ## Development
122
+
123
+ ```bash
124
+ pip install -e ".[dev]"
125
+ pytest # unit tests (no network)
126
+ pytest -m integration # live smoke tests against production
127
+ mypy
128
+ ruff check .
129
+ ```
130
+
131
+ ## License
132
+
133
+ MIT
@@ -0,0 +1,22 @@
1
+ """Get the latest canonical BTC/USD price from Hermes (production, no auth today).
2
+
3
+ Run: python examples/get_btc_price.py
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from pyth_hermes import HermesClient
9
+
10
+
11
+ def main() -> None:
12
+ with HermesClient() as client:
13
+ feed_id = client.get_feed_id("Crypto.BTC/USD")
14
+ if feed_id is None:
15
+ raise SystemExit("BTC/USD feed not found")
16
+ print(f"Crypto.BTC/USD feed id: {feed_id}")
17
+ price = client.get_price_decimal(feed_id)
18
+ print(f"BTC/USD = ${price:,.2f}")
19
+
20
+
21
+ if __name__ == "__main__":
22
+ main()
@@ -0,0 +1,30 @@
1
+ """Fetch a historical BTC/USD price at a given unix timestamp.
2
+
3
+ Run: python examples/historical_price.py
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import time
9
+
10
+ from pyth_hermes import HermesClient
11
+
12
+ BTC_ID = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
13
+
14
+
15
+ def main() -> None:
16
+ # one hour ago
17
+ publish_time = int(time.time()) - 3600
18
+ with HermesClient() as client:
19
+ resp = client.get_price_at(publish_time, [BTC_ID])
20
+ if not resp.parsed:
21
+ raise SystemExit("no historical update returned")
22
+ price = resp.parsed[0]
23
+ print(
24
+ f"BTC/USD around {publish_time}: "
25
+ f"${price.to_decimal():,.2f} (published {price.price.publish_time})"
26
+ )
27
+
28
+
29
+ if __name__ == "__main__":
30
+ main()
@@ -0,0 +1,29 @@
1
+ """Stream live BTC/USD price updates via SSE with automatic reconnect.
2
+
3
+ Run: python examples/stream_prices.py (Ctrl-C to stop)
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import asyncio
9
+
10
+ from pyth_hermes import AsyncHermesClient
11
+
12
+ BTC_ID = "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"
13
+
14
+
15
+ async def main() -> None:
16
+ async with AsyncHermesClient() as client:
17
+ count = 0
18
+ async for update in client.stream_prices([BTC_ID]):
19
+ if not update.parsed:
20
+ continue
21
+ price = update.parsed[0]
22
+ print(f"BTC/USD = ${price.to_decimal():,.2f} @ {price.price.publish_time}")
23
+ count += 1
24
+ if count >= 5: # demo: stop after 5 ticks
25
+ break
26
+
27
+
28
+ if __name__ == "__main__":
29
+ asyncio.run(main())