tracefast 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.
- tracefast-0.1.0/.gitignore +5 -0
- tracefast-0.1.0/LICENSE +21 -0
- tracefast-0.1.0/PKG-INFO +508 -0
- tracefast-0.1.0/README.md +477 -0
- tracefast-0.1.0/pyproject.toml +62 -0
- tracefast-0.1.0/src/tracefast/__init__.py +57 -0
- tracefast-0.1.0/src/tracefast/_client.py +268 -0
- tracefast-0.1.0/src/tracefast/_errors.py +160 -0
- tracefast-0.1.0/src/tracefast/_generated/__init__.py +6 -0
- tracefast-0.1.0/src/tracefast/_generated/api.py +16460 -0
- tracefast-0.1.0/src/tracefast/_generated/types.py +11486 -0
- tracefast-0.1.0/src/tracefast/_http.py +524 -0
- tracefast-0.1.0/src/tracefast/_version.py +3 -0
- tracefast-0.1.0/src/tracefast/py.typed +0 -0
- tracefast-0.1.0/src/tracefast/types.py +8 -0
tracefast-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TraceFast
|
|
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.
|
tracefast-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: tracefast
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The official Python SDK for the TraceFast API — Ethereum blocks, transactions, traces, tokens, contracts, DEX pools, the consensus layer, and what TraceFast states about an address.
|
|
5
|
+
Project-URL: Homepage, https://tracefast.xyz
|
|
6
|
+
Project-URL: Documentation, https://docs.tracefast.xyz/api
|
|
7
|
+
Project-URL: Blog, https://blog.tracefast.xyz
|
|
8
|
+
Project-URL: Repository, https://github.com/datanestllc/tracefast-sdk
|
|
9
|
+
Project-URL: Issues, https://github.com/datanestllc/tracefast-sdk/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/datanestllc/tracefast-sdk/blob/main/CHANGELOG.md
|
|
11
|
+
Author: TraceFast
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: api,api-client,blockchain,blockchain-analytics,compliance,defi,dex,ethereum,evm,forensics,onchain,sdk,smart-contracts,tracefast,transaction-trace,web3
|
|
15
|
+
Classifier: Development Status :: 3 - Alpha
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Requires-Dist: httpx<1,>=0.27
|
|
29
|
+
Requires-Dist: typing-extensions>=4.7
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# tracefast
|
|
33
|
+
|
|
34
|
+
**[TraceFast](https://tracefast.xyz) shows what happened on Ethereum, down to
|
|
35
|
+
execution: who took part, what moved, and which code ran.** It reads every block
|
|
36
|
+
from its own archive node and states a fact only when it is proven — always with
|
|
37
|
+
the block it holds for. Behind one API: blocks, transactions and full call
|
|
38
|
+
traces; tokens, DEX pools and the consensus layer; and the TraceFast knowledge
|
|
39
|
+
graph — what an address is now and what it was at past blocks, how its contract
|
|
40
|
+
is built, what its owner can do and has already done, and how it links to other
|
|
41
|
+
addresses — with ecosystem labels that name the protocol and role of each new
|
|
42
|
+
pool, market or vault from the block its factory created it. Built for
|
|
43
|
+
compliance teams, exchanges, auditors and investigators — and open to explore in
|
|
44
|
+
the app at [tracefast.xyz](https://tracefast.xyz).
|
|
45
|
+
|
|
46
|
+
`tracefast` is the official Python SDK for the
|
|
47
|
+
[TraceFast API](https://docs.tracefast.xyz/api): every method, typed, with a
|
|
48
|
+
synchronous and an `asyncio` client.
|
|
49
|
+
|
|
50
|
+
> **Before 1.0**, a minor version may change the package's interface — see
|
|
51
|
+
> [Versioning and stability](#versioning-and-stability).
|
|
52
|
+
|
|
53
|
+
## Contents
|
|
54
|
+
|
|
55
|
+
- [Requirements](#requirements)
|
|
56
|
+
- [Install](#install)
|
|
57
|
+
- [Quick start](#quick-start)
|
|
58
|
+
- [Authentication and plans](#authentication-and-plans)
|
|
59
|
+
- [Configuration](#configuration)
|
|
60
|
+
- [Methods](#methods)
|
|
61
|
+
- [Responses](#responses)
|
|
62
|
+
- [Errors](#errors)
|
|
63
|
+
- [Retries and timeouts](#retries-and-timeouts)
|
|
64
|
+
- [Pagination](#pagination)
|
|
65
|
+
- [Async](#async)
|
|
66
|
+
- [Types](#types)
|
|
67
|
+
- [Versioning and stability](#versioning-and-stability)
|
|
68
|
+
- [Support](#support)
|
|
69
|
+
- [Development](#development)
|
|
70
|
+
- [License](#license)
|
|
71
|
+
|
|
72
|
+
## Requirements
|
|
73
|
+
|
|
74
|
+
- Python 3.10 or later.
|
|
75
|
+
- A TraceFast API key on a paid plan. See
|
|
76
|
+
[tracefast.xyz/pricing](https://tracefast.xyz/pricing) for the plans.
|
|
77
|
+
|
|
78
|
+
## Install
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
pip install tracefast
|
|
82
|
+
# or
|
|
83
|
+
uv add tracefast
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Quick start
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import os
|
|
90
|
+
|
|
91
|
+
from tracefast import TraceFast
|
|
92
|
+
|
|
93
|
+
with TraceFast(api_key=os.environ["TRACEFAST_API_KEY"]) as tf:
|
|
94
|
+
# The newest block.
|
|
95
|
+
block = tf.blocks.latest()["data"]
|
|
96
|
+
print(block["number"], block["hash"], block["txCount"])
|
|
97
|
+
|
|
98
|
+
# Every implementation the USDC proxy has delegated to, newest first.
|
|
99
|
+
proxy = tf.contracts.proxy("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")["data"]
|
|
100
|
+
for impl in proxy["implementations"]:
|
|
101
|
+
if "supersededBy" not in impl:
|
|
102
|
+
state = "storage cannot say"
|
|
103
|
+
elif impl["supersededBy"] is None:
|
|
104
|
+
state = "current"
|
|
105
|
+
else:
|
|
106
|
+
state = f"replaced by {impl['supersededBy']}"
|
|
107
|
+
print(impl["implementation"], impl["firstSeenBlock"], state)
|
|
108
|
+
|
|
109
|
+
# One transaction by hash.
|
|
110
|
+
tx = tf.transactions.get("0x6bb3103eec4ca8f4a324bbab71dc84f533af7e6be11ab8b13d0d10333bb9abc5")["data"]
|
|
111
|
+
print(tx["from"], tx.get("to"), tx["valueWei"], tx.get("status"))
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Run it: save it as `quickstart.py`, then
|
|
115
|
+
`TRACEFAST_API_KEY=tf_live_… python quickstart.py`.
|
|
116
|
+
|
|
117
|
+
The three methods above need the **Enriched Data** plan.
|
|
118
|
+
|
|
119
|
+
## Authentication and plans
|
|
120
|
+
|
|
121
|
+
The client sends your key in the `x-api-key` header, and nowhere else. The key
|
|
122
|
+
is a secret for server-side code. Do not use it in code that runs in a browser
|
|
123
|
+
or on a user's device.
|
|
124
|
+
|
|
125
|
+
Each method needs a plan: **Enriched Data**, **Intelligence** or
|
|
126
|
+
**Investigation**. The docstring of each method names its plan, and your editor
|
|
127
|
+
shows it on hover. When your plan does not include a method, the call raises
|
|
128
|
+
`PermissionDeniedError` with the reason `plan_scope_missing`. Its `details` name
|
|
129
|
+
the plan the method needs and the plan you have:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from tracefast import PermissionDeniedError, TraceFast
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def plan_refusal(tf: TraceFast) -> None:
|
|
136
|
+
try:
|
|
137
|
+
tf.addresses.transactions("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", limit=10)
|
|
138
|
+
except PermissionDeniedError as e:
|
|
139
|
+
if e.reason != "plan_scope_missing":
|
|
140
|
+
raise
|
|
141
|
+
details = e.details or {}
|
|
142
|
+
print("needs", details.get("minimumPlan"), "- you have", details.get("currentPlan"))
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
A missing or invalid key raises `AuthenticationError` (`401`). The key is
|
|
146
|
+
checked when you create the client: it must be made of visible ASCII
|
|
147
|
+
characters. A key with a space, a line break or a typographic character raises
|
|
148
|
+
`ValueError`, and the message does not repeat the key.
|
|
149
|
+
|
|
150
|
+
## Configuration
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import os
|
|
154
|
+
|
|
155
|
+
import httpx
|
|
156
|
+
|
|
157
|
+
from tracefast import TraceFast
|
|
158
|
+
|
|
159
|
+
tf = TraceFast(
|
|
160
|
+
api_key=os.environ["TRACEFAST_API_KEY"],
|
|
161
|
+
timeout=30.0,
|
|
162
|
+
max_retries=2,
|
|
163
|
+
max_retry_wait=60.0,
|
|
164
|
+
user_agent="my-app/1.4",
|
|
165
|
+
)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Option | Default | Meaning |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `api_key` | required | Your `tf_live_…` key. Sent in the `x-api-key` header only. |
|
|
171
|
+
| `base_url` | `https://tracefast.xyz/api/v1` | Must be `https`. Plain `http` is accepted only for a loopback host (tests). |
|
|
172
|
+
| `chain_id` | `1` | Ethereum mainnet, the only chain served today. |
|
|
173
|
+
| `timeout` | `30.0` | Seconds for each phase of one attempt, as httpx counts them: getting a connection, connecting, sending, and each wait for data. It does not limit the whole call. |
|
|
174
|
+
| `max_retries` | `2` | Retries of answers that say "try again". `0` turns retries off. |
|
|
175
|
+
| `max_retry_wait` | `60.0` | The longest `Retry-After` the client waits for, in seconds. A `429` that asks for longer is raised at once. |
|
|
176
|
+
| `user_agent` | `None` | Added to `tracefast-python/<version>` in the `User-Agent` header. |
|
|
177
|
+
| `http_client` | `None` | Your own `httpx.Client` (or `httpx.AsyncClient` for `AsyncTraceFast`), for proxies or transports. |
|
|
178
|
+
|
|
179
|
+
If you give your own `http_client`:
|
|
180
|
+
|
|
181
|
+
- The SDK still never follows a redirect, even when your client is set to
|
|
182
|
+
follow them. A `3xx` answer raises `UnexpectedResponseError`, so the key is
|
|
183
|
+
never sent to another host.
|
|
184
|
+
- The SDK does not close your client. Close it yourself.
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
import os
|
|
188
|
+
|
|
189
|
+
import httpx
|
|
190
|
+
|
|
191
|
+
from tracefast import TraceFast
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def own_http_client() -> None:
|
|
195
|
+
with httpx.Client(proxy="http://proxy.example:3128") as http:
|
|
196
|
+
tf = TraceFast(api_key=os.environ["TRACEFAST_API_KEY"], http_client=http)
|
|
197
|
+
print(tf.blocks.latest()["data"]["number"])
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
`with_options(...)` returns a copy of the client with some options changed. The
|
|
201
|
+
copy shares the connections of the original. Closing the copy does nothing;
|
|
202
|
+
closing the original closes the connections of both.
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from tracefast import TraceFast
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def slow_part(tf: TraceFast) -> None:
|
|
209
|
+
patient = tf.with_options(timeout=120.0, max_retries=4)
|
|
210
|
+
print(patient.traces.get("0x6bb3103eec4ca8f4a324bbab71dc84f533af7e6be11ab8b13d0d10333bb9abc5")["meta"]["docs"])
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Close the client when you are done with it: use `with TraceFast(...) as tf:`
|
|
214
|
+
or call `tf.close()`. A call on a closed client raises `RuntimeError`.
|
|
215
|
+
|
|
216
|
+
## Methods
|
|
217
|
+
|
|
218
|
+
The methods are in groups, in the same way as in the
|
|
219
|
+
[API documentation](https://docs.tracefast.xyz/api/methods). The client has
|
|
220
|
+
every method of the API.
|
|
221
|
+
|
|
222
|
+
| Group | For example |
|
|
223
|
+
|---|---|
|
|
224
|
+
| `tf.blocks` | `latest()`, `get(25_920_000)`, `at_time(timestamp=1767225600)`, `transactions(25_920_000, limit=100)` |
|
|
225
|
+
| `tf.transactions` | `get(hash)`, `events(hash)`, `failures(hash)`, `storage_writes(hash)` |
|
|
226
|
+
| `tf.traces` | `get(hash)`, `frames(hash, limit=100)` |
|
|
227
|
+
| `tf.contracts` | `get(address)`, `proxy(address)`, `capabilities(address)`, `selectors(address)` |
|
|
228
|
+
| `tf.addresses` | `get(address)`, `portfolio(address, block=20_000_000)`, `transactions(address, direction="sent", limit=50)`, `attributes(address)` |
|
|
229
|
+
| `tf.tokens` | `get(token)`, `holders(token, limit=10)`, `transfers(token, from_=address)`, `price_history(token, from_=1767225600, to=1767312000)` |
|
|
230
|
+
| `tf.pools` | `get(pool)`, `for_pair(token_a=usdc, token_b=weth)`, `swaps(pool)`, `reserves(pool)` |
|
|
231
|
+
| `tf.consensus` | `current()`, `queues()`, `validator(1)`, `missed_slots(limit=10)` |
|
|
232
|
+
| `tf.network` | `daily()`, `gas_daily()`, `top_pools(by="volume", days=7)`, `top_dex_tokens()` |
|
|
233
|
+
| `tf.lending` | `config("aave_v3")` |
|
|
234
|
+
| `tf.signals` | `recent(kind="account_drain")`, `kinds()`, `rates()` |
|
|
235
|
+
| `tf.risk` | `blacklist_status(address)`, `blacklist_events(address)` |
|
|
236
|
+
| `tf` itself | `tf.resolve(q="usdc")`: the addresses a name or a fragment can mean |
|
|
237
|
+
|
|
238
|
+
- Path parameters are positional, in the order of the path. Block numbers,
|
|
239
|
+
slots and validator indexes are `int`.
|
|
240
|
+
- Query parameters are keyword arguments. A keyword argument that you do not
|
|
241
|
+
set (or set to `None`) is not sent, and the API uses its default.
|
|
242
|
+
- Names are snake_case: `fromBlock` is `from_block`. A name that is a Python
|
|
243
|
+
keyword gets a trailing underscore: the `from` parameter is `from_`.
|
|
244
|
+
- Addresses and hashes are sent as you give them. The API accepts any case and
|
|
245
|
+
answers in lowercase.
|
|
246
|
+
- A path value that is empty, `.` or `..` raises `ValueError` before any
|
|
247
|
+
request.
|
|
248
|
+
|
|
249
|
+
The docstring of each method gives its description, the plan it needs, whether
|
|
250
|
+
it is **Beta**, and the link to its documentation page.
|
|
251
|
+
|
|
252
|
+
## Responses
|
|
253
|
+
|
|
254
|
+
A method returns the whole answer of the API, `{"data": ..., "meta": ...}`, as
|
|
255
|
+
a plain `dict` typed with a `TypedDict`:
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
from tracefast import TraceFast
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def responses(tf: TraceFast) -> None:
|
|
262
|
+
res = tf.addresses.get("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")
|
|
263
|
+
print(res["data"]["address"])
|
|
264
|
+
print(res["meta"].get("asOfBlock")) # the block the answer is true at
|
|
265
|
+
print(res["meta"]["docs"]) # the documentation page of the method
|
|
266
|
+
print(res["meta"]["cached"]) # True when the answer came from the cache
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
For most methods, `meta.asOfBlock` is the block the answer is true at. For the
|
|
270
|
+
at-block methods (`attributes_at_block`, `relations_at_block`), it is the
|
|
271
|
+
horizon of the history, and the block you asked about is `data["block"]`. Each
|
|
272
|
+
method's documentation page says what `asOfBlock` means for it.
|
|
273
|
+
|
|
274
|
+
**Absent, `None` and a value are three different answers.** A field that the
|
|
275
|
+
API can leave out is `NotRequired` and stays absent from the dict. A field that
|
|
276
|
+
can be `null` is typed `... | None`. When a field can be both, they mean
|
|
277
|
+
different things. For a proxy implementation, `supersededBy` is:
|
|
278
|
+
|
|
279
|
+
- absent: storage cannot say;
|
|
280
|
+
- `None`: no replacement was seen, the implementation is current;
|
|
281
|
+
- an address: the implementation was replaced by it.
|
|
282
|
+
|
|
283
|
+
Read such fields with `"key" in d` or `d.get("key")`, never `d["key"]`.
|
|
284
|
+
|
|
285
|
+
An absent fact is **not proven**. It never means "no".
|
|
286
|
+
|
|
287
|
+
Units are those of the API:
|
|
288
|
+
|
|
289
|
+
- Amounts in wei and gwei, and raw token amounts, are decimal strings
|
|
290
|
+
(`valueWei`, `amountGwei`, `reserveRaw`). Use `int(...)` to calculate with
|
|
291
|
+
them.
|
|
292
|
+
- Token amounts scaled by decimals, and USD values, are `float`. Use them for
|
|
293
|
+
display only.
|
|
294
|
+
- Block numbers and counts are `int`.
|
|
295
|
+
- `meta["timestamp"]` is Unix time in **milliseconds**. Timestamps in `data`
|
|
296
|
+
are Unix time in **seconds**, or RFC 3339 strings where the field says so.
|
|
297
|
+
Timestamps you send (`timestamp`, `from_`, `to`) are Unix seconds.
|
|
298
|
+
|
|
299
|
+
Enumerations are open: the API can add a value. For example,
|
|
300
|
+
`tracefast.types.TokenClass` is `Literal["fungible", "nft"] | str`. Always
|
|
301
|
+
handle a value that you do not know.
|
|
302
|
+
|
|
303
|
+
## Errors
|
|
304
|
+
|
|
305
|
+
Every failure raises a `TraceFastError`:
|
|
306
|
+
|
|
307
|
+
```python
|
|
308
|
+
from tracefast import NotFoundError, TraceFast, TraceFastError, UnprocessableEntityError
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def errors(tf: TraceFast) -> None:
|
|
312
|
+
try:
|
|
313
|
+
tf.blocks.transactions(30_000_000, limit=10)
|
|
314
|
+
except NotFoundError:
|
|
315
|
+
print("no such block yet")
|
|
316
|
+
except UnprocessableEntityError as e:
|
|
317
|
+
if e.code != "block_not_available":
|
|
318
|
+
raise
|
|
319
|
+
print("served up to block", (e.details or {}).get("maxAvailableBlock"))
|
|
320
|
+
except TraceFastError as e:
|
|
321
|
+
print(e.status, e.code, e.reason, e.request_id)
|
|
322
|
+
raise
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
| Attribute | Meaning |
|
|
326
|
+
|---|---|
|
|
327
|
+
| `status` | The HTTP status. `0` when no answer arrived. |
|
|
328
|
+
| `code` | The stable word to branch on: `bad_request`, `invalid_cursor`, `not_found`, `block_not_available`, `coverage_gap`, `auth_failed`, `forbidden`, `rate_limited`, `quota_exceeded`, … or one of the SDK's own: `unexpected_response`, `connection_error`, `timeout`. |
|
|
329
|
+
| `reason` | The stable sub-code, when there is one (`api_key_required`, `plan_scope_missing`, …). |
|
|
330
|
+
| `bucket` | On a `429`, the limit that refused the call (`base`, `concurrency`, …). |
|
|
331
|
+
| `details` | A dict of what to act on, when the API gives it (`maxAvailableBlock`, `maxLimit`, `minimumPlan`, `currentPlan`, …). Read it with `.get`. |
|
|
332
|
+
| `request_id` | The id of the request. Give it to support. |
|
|
333
|
+
| `retry_after` | Seconds from the `Retry-After` header, exactly as sent. |
|
|
334
|
+
| `body` | The raw `error` object of the answer, so a field the SDK does not know is kept. |
|
|
335
|
+
| `message` | `"<status> <code>: <message>"`, for people. It can change; never parse it. |
|
|
336
|
+
|
|
337
|
+
The subclass tells the kind of failure:
|
|
338
|
+
|
|
339
|
+
| Subclass | When |
|
|
340
|
+
|---|---|
|
|
341
|
+
| `BadRequestError` | `400` |
|
|
342
|
+
| `AuthenticationError` | `401` |
|
|
343
|
+
| `PermissionDeniedError` | `403` |
|
|
344
|
+
| `NotFoundError` | `404` |
|
|
345
|
+
| `UnprocessableEntityError` | `422` |
|
|
346
|
+
| `RateLimitError` | `429` |
|
|
347
|
+
| `InternalServerError` | `5xx` |
|
|
348
|
+
| `APIConnectionError` | `connection_error`: the connection failed or broke |
|
|
349
|
+
| `APITimeoutError` | `timeout` |
|
|
350
|
+
| `UnexpectedResponseError` | `unexpected_response`: a redirect, a proxy page, or a body that is not the API's |
|
|
351
|
+
|
|
352
|
+
`reason` comes from the error object when the gateway refuses the key, the
|
|
353
|
+
plan or a limit, and from `details["reason"]` otherwise. Branch on the
|
|
354
|
+
subclass, `code` and `reason`, never on `message`. The
|
|
355
|
+
[full list of codes](https://docs.tracefast.xyz/api/conventions#errors) is in
|
|
356
|
+
the API documentation.
|
|
357
|
+
|
|
358
|
+
## Retries and timeouts
|
|
359
|
+
|
|
360
|
+
The client retries only answers that say "try again", at most `max_retries`
|
|
361
|
+
times:
|
|
362
|
+
|
|
363
|
+
- `429` with a `Retry-After` of at most `max_retry_wait` seconds: the client
|
|
364
|
+
waits that long, then retries.
|
|
365
|
+
- `503`: the client waits for `Retry-After` (at most `max_retry_wait`), or, if
|
|
366
|
+
there is no `Retry-After`, for an exponential backoff from 0.5 s with jitter,
|
|
367
|
+
at most 8 s for each wait.
|
|
368
|
+
- A connection failure, also one while the body is read: backoff as for `503`.
|
|
369
|
+
|
|
370
|
+
These are raised at once: a `429` without `Retry-After` or with a longer one
|
|
371
|
+
(`retry_after` tells the real wait), every `quota_exceeded`, a timeout, and all
|
|
372
|
+
other errors. Every method is a read, so a retry never repeats a side effect.
|
|
373
|
+
|
|
374
|
+
`timeout` applies to each phase of each attempt, not to the whole call. One
|
|
375
|
+
call makes at most `max_retries + 1` attempts, plus the waits between them
|
|
376
|
+
(each at most `max_retry_wait`). If you need a hard limit on a whole call, use
|
|
377
|
+
`asyncio.wait_for` with `AsyncTraceFast`.
|
|
378
|
+
|
|
379
|
+
Set the `tracefast` logger to `DEBUG` to see each retry decision (status, wait,
|
|
380
|
+
attempt and request id). The log never contains the key or the headers.
|
|
381
|
+
|
|
382
|
+
## Pagination
|
|
383
|
+
|
|
384
|
+
A paged method returns one page. `data["nextCursor"]` is present while there are
|
|
385
|
+
more pages, and absent on the last one. Each paged method has two walkers:
|
|
386
|
+
|
|
387
|
+
- `<method>_pages(...)` gives each whole response, `meta` included;
|
|
388
|
+
`max_pages` sets a limit.
|
|
389
|
+
- `<method>_items(...)` gives the rows one by one; `max_items` sets a limit.
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
from itertools import islice
|
|
393
|
+
|
|
394
|
+
from tracefast import TraceFast
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def pagination(tf: TraceFast) -> None:
|
|
398
|
+
for tx in tf.blocks.transactions_items(25_920_000, limit=100, max_items=250):
|
|
399
|
+
print(tx["hash"], tx["valueWei"])
|
|
400
|
+
|
|
401
|
+
for page in tf.tokens.transfers_pages("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", limit=100, max_pages=3):
|
|
402
|
+
print(len(page["data"]["transfers"]), page["meta"].get("asOfBlock"))
|
|
403
|
+
|
|
404
|
+
first = list(islice(tf.blocks.withdrawals_items(25_920_000), 5))
|
|
405
|
+
print(first)
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
Always set a limit. The history of an active address or token has millions of
|
|
409
|
+
rows, and a walk without a limit reads all of them.
|
|
410
|
+
|
|
411
|
+
- A walker stops when `nextCursor` is absent, never on a short page: a page
|
|
412
|
+
can have fewer rows than `limit` and still have a next page.
|
|
413
|
+
- A walker sends the cursor back unchanged, with the same other parameters. If
|
|
414
|
+
you give `cursor=`, the walk starts from it.
|
|
415
|
+
- An empty `nextCursor`, or one equal to the previous cursor, raises
|
|
416
|
+
`UnexpectedResponseError`.
|
|
417
|
+
- `400 invalid_cursor` raises `BadRequestError`. Discard the rows you collected
|
|
418
|
+
and start again from the first page. For the lists of one block, it means the
|
|
419
|
+
block was reorganised, and the rows you read belong to the old block.
|
|
420
|
+
|
|
421
|
+
The walkers use the plan of their method. The feeds of an address
|
|
422
|
+
(`addresses.transactions`, `addresses.token_transfers`,
|
|
423
|
+
`addresses.internal_transfers`) need the **Investigation** plan.
|
|
424
|
+
|
|
425
|
+
## Async
|
|
426
|
+
|
|
427
|
+
`AsyncTraceFast` has the same groups and methods. Each method is a coroutine,
|
|
428
|
+
and each walker is an async iterator:
|
|
429
|
+
|
|
430
|
+
```python
|
|
431
|
+
import asyncio
|
|
432
|
+
import os
|
|
433
|
+
|
|
434
|
+
from tracefast import AsyncTraceFast
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
async def main() -> None:
|
|
438
|
+
async with AsyncTraceFast(api_key=os.environ["TRACEFAST_API_KEY"]) as tf:
|
|
439
|
+
block, proxy = await asyncio.gather(
|
|
440
|
+
tf.blocks.latest(),
|
|
441
|
+
tf.contracts.proxy("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"),
|
|
442
|
+
)
|
|
443
|
+
print(block["data"]["number"], len(proxy["data"]["implementations"]))
|
|
444
|
+
|
|
445
|
+
async for tx in tf.blocks.transactions_items(25_920_000, max_items=20):
|
|
446
|
+
print(tx["hash"])
|
|
447
|
+
|
|
448
|
+
latest = await asyncio.wait_for(tf.blocks.latest(), timeout=10)
|
|
449
|
+
print(latest["meta"]["timestamp"])
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Cancellation works as usual: when the task is cancelled, the call stops and
|
|
453
|
+
`asyncio.CancelledError` propagates. The SDK never catches it.
|
|
454
|
+
|
|
455
|
+
## Types
|
|
456
|
+
|
|
457
|
+
All response types are in `tracefast.types`, one `TypedDict` for each object
|
|
458
|
+
of the API catalogue. They work with mypy, Pyright and your editor:
|
|
459
|
+
|
|
460
|
+
```python
|
|
461
|
+
from tracefast import CATALOGUE_VERSION
|
|
462
|
+
from tracefast.types import ProxyImplementation, TokenClass
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def describe(impl: ProxyImplementation, kind: TokenClass) -> str:
|
|
466
|
+
return f"{impl['implementation']} ({kind}), catalogue {CATALOGUE_VERSION}"
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
At runtime a response is a plain `dict`. An unknown field in a response is kept
|
|
470
|
+
and does not cause an error. `CATALOGUE_VERSION` is the version of the API
|
|
471
|
+
catalogue that the package was generated from.
|
|
472
|
+
|
|
473
|
+
## Versioning and stability
|
|
474
|
+
|
|
475
|
+
- Versions `0.x` can change the interface of the package between minor
|
|
476
|
+
versions.
|
|
477
|
+
- From `1.0`, the package follows semantic versioning.
|
|
478
|
+
- Methods marked **Beta** in their docstring can still change shape, and are
|
|
479
|
+
not covered by these rules. See
|
|
480
|
+
[stability](https://docs.tracefast.xyz/api/conventions#stability).
|
|
481
|
+
|
|
482
|
+
## Support
|
|
483
|
+
|
|
484
|
+
Report problems at
|
|
485
|
+
[github.com/datanestllc/tracefast-sdk/issues](https://github.com/datanestllc/tracefast-sdk/issues).
|
|
486
|
+
For a failed call, give the `request_id` of the error.
|
|
487
|
+
|
|
488
|
+
## Development
|
|
489
|
+
|
|
490
|
+
The code in `src/tracefast/_generated/` is generated from the API catalogue. Do
|
|
491
|
+
not edit it. To change it, edit `codegen/emit-python.mjs` and run the generator
|
|
492
|
+
from the repository root (see the
|
|
493
|
+
[repository README](https://github.com/datanestllc/tracefast-sdk#readme)):
|
|
494
|
+
|
|
495
|
+
```bash
|
|
496
|
+
node codegen/generate.mjs # from the repository root; needs Node.js
|
|
497
|
+
cd python
|
|
498
|
+
uv sync --group dev
|
|
499
|
+
uv run pytest -q # every method against its recorded answer, and the behaviour tests
|
|
500
|
+
uv run mypy --strict # src, examples and tests/static
|
|
501
|
+
uv build
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
The tests need Node.js, because they read the generator's model of the API.
|
|
505
|
+
|
|
506
|
+
## License
|
|
507
|
+
|
|
508
|
+
[MIT](https://github.com/datanestllc/tracefast-sdk/blob/main/LICENSE)
|