defillama-sdk 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.
Files changed (43) hide show
  1. defillama_sdk-0.1.0/LICENSE +21 -0
  2. defillama_sdk-0.1.0/MANIFEST.in +1 -0
  3. defillama_sdk-0.1.0/PKG-INFO +688 -0
  4. defillama_sdk-0.1.0/README.md +676 -0
  5. defillama_sdk-0.1.0/defillama_api/__init__.py +71 -0
  6. defillama_sdk-0.1.0/defillama_api/client.py +157 -0
  7. defillama_sdk-0.1.0/defillama_api/constants/__init__.py +11 -0
  8. defillama_sdk-0.1.0/defillama_api/constants/dimensions.py +69 -0
  9. defillama_sdk-0.1.0/defillama_api/errors.py +41 -0
  10. defillama_sdk-0.1.0/defillama_api/modules/__init__.py +29 -0
  11. defillama_sdk-0.1.0/defillama_api/modules/account.py +29 -0
  12. defillama_sdk-0.1.0/defillama_api/modules/bridges.py +81 -0
  13. defillama_sdk-0.1.0/defillama_api/modules/dat.py +31 -0
  14. defillama_sdk-0.1.0/defillama_api/modules/ecosystem.py +54 -0
  15. defillama_sdk-0.1.0/defillama_api/modules/emissions.py +32 -0
  16. defillama_sdk-0.1.0/defillama_api/modules/etfs.py +58 -0
  17. defillama_sdk-0.1.0/defillama_api/modules/fees.py +242 -0
  18. defillama_sdk-0.1.0/defillama_api/modules/prices.py +122 -0
  19. defillama_sdk-0.1.0/defillama_api/modules/stablecoins.py +76 -0
  20. defillama_sdk-0.1.0/defillama_api/modules/tvl.py +84 -0
  21. defillama_sdk-0.1.0/defillama_api/modules/volumes.py +116 -0
  22. defillama_sdk-0.1.0/defillama_api/modules/yields.py +85 -0
  23. defillama_sdk-0.1.0/defillama_api/py.typed +0 -0
  24. defillama_sdk-0.1.0/defillama_api/types/__init__.py +14 -0
  25. defillama_sdk-0.1.0/defillama_api/types/account.py +10 -0
  26. defillama_sdk-0.1.0/defillama_api/types/bridges.py +147 -0
  27. defillama_sdk-0.1.0/defillama_api/types/dat.py +144 -0
  28. defillama_sdk-0.1.0/defillama_api/types/ecosystem.py +175 -0
  29. defillama_sdk-0.1.0/defillama_api/types/emissions.py +154 -0
  30. defillama_sdk-0.1.0/defillama_api/types/etfs.py +37 -0
  31. defillama_sdk-0.1.0/defillama_api/types/fees.py +217 -0
  32. defillama_sdk-0.1.0/defillama_api/types/prices.py +99 -0
  33. defillama_sdk-0.1.0/defillama_api/types/stablecoins.py +159 -0
  34. defillama_sdk-0.1.0/defillama_api/types/tvl.py +189 -0
  35. defillama_sdk-0.1.0/defillama_api/types/volumes.py +147 -0
  36. defillama_sdk-0.1.0/defillama_api/types/yields.py +170 -0
  37. defillama_sdk-0.1.0/defillama_sdk.egg-info/PKG-INFO +688 -0
  38. defillama_sdk-0.1.0/defillama_sdk.egg-info/SOURCES.txt +41 -0
  39. defillama_sdk-0.1.0/defillama_sdk.egg-info/dependency_links.txt +1 -0
  40. defillama_sdk-0.1.0/defillama_sdk.egg-info/requires.txt +1 -0
  41. defillama_sdk-0.1.0/defillama_sdk.egg-info/top_level.txt +1 -0
  42. defillama_sdk-0.1.0/pyproject.toml +29 -0
  43. defillama_sdk-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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 @@
1
+ include LICENSE
@@ -0,0 +1,688 @@
1
+ Metadata-Version: 2.4
2
+ Name: defillama-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for DefiLlama API
5
+ Author: DefiLlama
6
+ Project-URL: Homepage, https://api-docs.defillama.com/
7
+ Project-URL: Repository, https://github.com/DefiLlama/python-sdk
8
+ Keywords: defillama,defi,tvl,cryptocurrency,api,sdk
9
+ Requires-Python: >=3.9
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: requests>=2.31.0
12
+
13
+ # DefiLlama Python SDK
14
+
15
+ Official Python SDK for the [DefiLlama API](https://api-docs.defillama.com/). Access DeFi protocol data including TVL, prices, yields, volumes, fees, bridges, and more.
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install defillama-sdk
21
+ ```
22
+
23
+ ```bash
24
+ uv pip install defillama-sdk
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```python
30
+ from defillama_api import DefiLlama
31
+
32
+ # Free tier
33
+ client = DefiLlama()
34
+
35
+ # Pro tier (required for premium endpoints)
36
+ pro_client = DefiLlama({"api_key": "your-api-key"})
37
+
38
+ # Get all protocols
39
+ protocols = client.tvl.getProtocols()
40
+
41
+ # Get current token prices
42
+ prices = client.prices.getCurrentPrices(
43
+ [
44
+ "ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
45
+ "coingecko:bitcoin",
46
+ ]
47
+ )
48
+ ```
49
+
50
+ ## Configuration
51
+
52
+ ```python
53
+ config = {
54
+ "api_key": "your-api-key",
55
+ "timeout": 30000,
56
+ }
57
+
58
+ client = DefiLlama(config)
59
+ ```
60
+
61
+ ## Modules
62
+
63
+ - TVL
64
+ - Prices
65
+ - Stablecoins
66
+ - Yields (Pro)
67
+ - Volumes
68
+ - Fees
69
+ - Emissions (Pro)
70
+ - Bridges (Pro)
71
+ - Ecosystem (Pro)
72
+ - ETFs (Pro)
73
+ - DAT (Pro)
74
+ - Account (Pro)
75
+
76
+ 🔐 = Requires Pro API key
77
+
78
+ ---
79
+
80
+ ## TVL
81
+
82
+ Total Value Locked data for protocols and chains.
83
+
84
+ ### getProtocols
85
+
86
+ Get all protocols with current TVL.
87
+
88
+ ```python
89
+ protocols = client.tvl.getProtocols()
90
+ ```
91
+
92
+ ### getProtocol
93
+
94
+ Get detailed protocol information including historical TVL.
95
+
96
+ ```python
97
+ aave = client.tvl.getProtocol("aave")
98
+ ```
99
+
100
+ ### getTvl
101
+
102
+ Get only current TVL for a protocol.
103
+
104
+ ```python
105
+ tvl = client.tvl.getTvl("uniswap")
106
+ ```
107
+
108
+ ### getChains
109
+
110
+ Get current TVL for all chains.
111
+
112
+ ```python
113
+ chains = client.tvl.getChains()
114
+ ```
115
+
116
+ ### getHistoricalChainTvl
117
+
118
+ Get historical TVL data.
119
+
120
+ ```python
121
+ all_history = client.tvl.getHistoricalChainTvl()
122
+ eth_history = client.tvl.getHistoricalChainTvl("Ethereum")
123
+ ```
124
+
125
+ ### getTokenProtocols 🔐
126
+
127
+ Get protocols holding a specific token.
128
+
129
+ ```python
130
+ holders = pro_client.tvl.getTokenProtocols("ETH")
131
+ ```
132
+
133
+ ### getInflows 🔐
134
+
135
+ Get token inflows/outflows between timestamps.
136
+
137
+ ```python
138
+ inflows = pro_client.tvl.getInflows(
139
+ "lido",
140
+ 1704067200,
141
+ 1704153600,
142
+ "ETH,USDC",
143
+ )
144
+ ```
145
+
146
+ ### getChainAssets 🔐
147
+
148
+ Get asset breakdown for all chains.
149
+
150
+ ```python
151
+ assets = pro_client.tvl.getChainAssets()
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Prices
157
+
158
+ Token price data and historical charts.
159
+
160
+ ### getCurrentPrices
161
+
162
+ ```python
163
+ prices = client.prices.getCurrentPrices(
164
+ [
165
+ "ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
166
+ "coingecko:bitcoin",
167
+ "solana:So11111111111111111111111111111111111111112",
168
+ ]
169
+ )
170
+ ```
171
+
172
+ ### getHistoricalPrices
173
+
174
+ ```python
175
+ prices = client.prices.getHistoricalPrices(
176
+ 1704067200,
177
+ ["ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7"],
178
+ )
179
+ ```
180
+
181
+ ### getBatchHistoricalPrices
182
+
183
+ ```python
184
+ prices = client.prices.getBatchHistoricalPrices(
185
+ {
186
+ "ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": [
187
+ 1704067200,
188
+ 1704153600,
189
+ 1704240000,
190
+ ]
191
+ }
192
+ )
193
+ ```
194
+
195
+ ### getChart
196
+
197
+ ```python
198
+ chart = client.prices.getChart(
199
+ ["coingecko:ethereum"],
200
+ {"start": 1704067200, "period": "1d", "span": 30},
201
+ )
202
+ ```
203
+
204
+ ### getPercentageChange
205
+
206
+ ```python
207
+ change = client.prices.getPercentageChange(
208
+ ["coingecko:bitcoin"],
209
+ {"period": "24h"},
210
+ )
211
+ ```
212
+
213
+ ### getFirstPrices
214
+
215
+ ```python
216
+ first = client.prices.getFirstPrices(
217
+ ["ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"]
218
+ )
219
+ ```
220
+
221
+ ### getBlockAtTimestamp
222
+
223
+ ```python
224
+ block = client.prices.getBlockAtTimestamp("ethereum", 1704067200)
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Stablecoins
230
+
231
+ Stablecoin market cap and dominance data.
232
+
233
+ ### getStablecoins
234
+
235
+ ```python
236
+ stables = client.stablecoins.getStablecoins(True)
237
+ ```
238
+
239
+ ### getAllCharts
240
+
241
+ ```python
242
+ charts = client.stablecoins.getAllCharts()
243
+ ```
244
+
245
+ ### getChartsByChain
246
+
247
+ ```python
248
+ eth_charts = client.stablecoins.getChartsByChain("Ethereum")
249
+ ```
250
+
251
+ ### getStablecoin
252
+
253
+ ```python
254
+ usdt = client.stablecoins.getStablecoin("1")
255
+ ```
256
+
257
+ ### getChains
258
+
259
+ ```python
260
+ chains = client.stablecoins.getChains()
261
+ ```
262
+
263
+ ### getPrices
264
+
265
+ ```python
266
+ prices = client.stablecoins.getPrices()
267
+ ```
268
+
269
+ ### getDominance 🔐
270
+
271
+ ```python
272
+ dominance = pro_client.stablecoins.getDominance("ethereum", 1)
273
+ ```
274
+
275
+ ---
276
+
277
+ ## Yields 🔐
278
+
279
+ Yield farming, lending, staking, and perpetual funding rates.
280
+
281
+ ### getPools
282
+
283
+ ```python
284
+ pools = pro_client.yields.getPools()
285
+ ```
286
+
287
+ ### getPoolsOld
288
+
289
+ ```python
290
+ pools = pro_client.yields.getPoolsOld()
291
+ ```
292
+
293
+ ### getPoolChart
294
+
295
+ ```python
296
+ chart = pro_client.yields.getPoolChart("pool-uuid-here")
297
+ ```
298
+
299
+ ### getBorrowPools
300
+
301
+ ```python
302
+ borrow_pools = pro_client.yields.getBorrowPools()
303
+ ```
304
+
305
+ ### getLendBorrowChart
306
+
307
+ ```python
308
+ chart = pro_client.yields.getLendBorrowChart("pool-uuid-here")
309
+ ```
310
+
311
+ ### getPerps
312
+
313
+ ```python
314
+ perps = pro_client.yields.getPerps()
315
+ ```
316
+
317
+ ### getLsdRates
318
+
319
+ ```python
320
+ lsd_rates = pro_client.yields.getLsdRates()
321
+ ```
322
+
323
+ ---
324
+
325
+ ## Volumes
326
+
327
+ DEX, options, and derivatives trading volume data.
328
+
329
+ ### getDexOverview
330
+
331
+ ```python
332
+ overview = client.volumes.getDexOverview()
333
+ overview = client.volumes.getDexOverview(
334
+ {"excludeTotalDataChart": True, "dataType": "dailyVolume"}
335
+ )
336
+ ```
337
+
338
+ ### getDexOverviewByChain
339
+
340
+ ```python
341
+ eth_volume = client.volumes.getDexOverviewByChain("Ethereum")
342
+ ```
343
+
344
+ ### getDexSummary
345
+
346
+ ```python
347
+ uniswap = client.volumes.getDexSummary("uniswap")
348
+ ```
349
+
350
+ ### getOptionsOverview
351
+
352
+ ```python
353
+ options = client.volumes.getOptionsOverview()
354
+ ```
355
+
356
+ ### getOptionsOverviewByChain
357
+
358
+ ```python
359
+ eth_options = client.volumes.getOptionsOverviewByChain("Ethereum")
360
+ ```
361
+
362
+ ### getOptionsSummary
363
+
364
+ ```python
365
+ derive = client.volumes.getOptionsSummary("derive")
366
+ ```
367
+
368
+ ### getDerivativesOverview 🔐
369
+
370
+ ```python
371
+ derivatives = pro_client.volumes.getDerivativesOverview()
372
+ ```
373
+
374
+ ### getDerivativesSummary 🔐
375
+
376
+ ```python
377
+ gmx = pro_client.volumes.getDerivativesSummary("gmx")
378
+ ```
379
+
380
+ ---
381
+
382
+ ## Fees
383
+
384
+ Protocol fees and revenue data.
385
+
386
+ ### Fee Data Types
387
+
388
+ ```python
389
+ from defillama_api import FeeDataType
390
+
391
+ FeeDataType.DAILY_FEES
392
+ FeeDataType.DAILY_REVENUE
393
+ FeeDataType.DAILY_HOLDERS_REVENUE
394
+ FeeDataType.DAILY_SUPPLY_SIDE_REVENUE
395
+ FeeDataType.DAILY_BRIBES_REVENUE
396
+ FeeDataType.DAILY_TOKEN_TAXES
397
+ FeeDataType.DAILY_APP_FEES
398
+ FeeDataType.DAILY_APP_REVENUE
399
+ FeeDataType.DAILY_EARNINGS
400
+ ```
401
+
402
+ ### getOverview
403
+
404
+ ```python
405
+ fees = client.fees.getOverview()
406
+ revenue = client.fees.getOverview({"dataType": FeeDataType.DAILY_REVENUE})
407
+ ```
408
+
409
+ ### getOverviewByChain
410
+
411
+ ```python
412
+ eth_fees = client.fees.getOverviewByChain("Ethereum")
413
+ ```
414
+
415
+ ### getSummary
416
+
417
+ ```python
418
+ uniswap_fees = client.fees.getSummary("uniswap")
419
+ ```
420
+
421
+ ### getChart 🔐
422
+
423
+ ```python
424
+ chart = pro_client.fees.getChart()
425
+ eth_chart = pro_client.fees.getChartByChain("Ethereum")
426
+ protocol_chart = pro_client.fees.getChartByProtocol("aave")
427
+ ```
428
+
429
+ ### getChartByProtocolChainBreakdown 🔐
430
+
431
+ ```python
432
+ breakdown = pro_client.fees.getChartByProtocolChainBreakdown("aave")
433
+ ```
434
+
435
+ ### getChartByProtocolVersionBreakdown 🔐
436
+
437
+ ```python
438
+ breakdown = pro_client.fees.getChartByProtocolVersionBreakdown("uniswap")
439
+ ```
440
+
441
+ ### getChartByChainProtocolBreakdown 🔐
442
+
443
+ ```python
444
+ breakdown = pro_client.fees.getChartByChainProtocolBreakdown("Ethereum")
445
+ ```
446
+
447
+ ### getChartChainBreakdown 🔐
448
+
449
+ ```python
450
+ breakdown = pro_client.fees.getChartChainBreakdown()
451
+ ```
452
+
453
+ ### getMetrics 🔐
454
+
455
+ ```python
456
+ metrics = pro_client.fees.getMetrics()
457
+ chain_metrics = pro_client.fees.getMetricsByChain("Ethereum")
458
+ protocol_metrics = pro_client.fees.getMetricsByProtocol("aave")
459
+ ```
460
+
461
+ ---
462
+
463
+ ## Emissions 🔐
464
+
465
+ Token unlock schedules and vesting data.
466
+
467
+ ### getAll
468
+
469
+ ```python
470
+ emissions = pro_client.emissions.getAll()
471
+ ```
472
+
473
+ ### getByProtocol
474
+
475
+ ```python
476
+ arbitrum = pro_client.emissions.getByProtocol("arbitrum")
477
+ ```
478
+
479
+ ---
480
+
481
+ ## Bridges 🔐
482
+
483
+ Cross-chain bridge volume and transaction data.
484
+
485
+ ### getAll
486
+
487
+ ```python
488
+ bridges = pro_client.bridges.getAll()
489
+ bridges = pro_client.bridges.getAll({"includeChains": True})
490
+ ```
491
+
492
+ ### getById
493
+
494
+ ```python
495
+ bridge = pro_client.bridges.getById(1)
496
+ ```
497
+
498
+ ### getVolumeByChain
499
+
500
+ ```python
501
+ volume = pro_client.bridges.getVolumeByChain("Ethereum")
502
+ ```
503
+
504
+ ### getDayStats
505
+
506
+ ```python
507
+ stats = pro_client.bridges.getDayStats(1704067200, "Ethereum")
508
+ ```
509
+
510
+ ### getTransactions
511
+
512
+ ```python
513
+ txs = pro_client.bridges.getTransactions(
514
+ 1,
515
+ {
516
+ "limit": 100,
517
+ "startTimestamp": 1704067200,
518
+ "endTimestamp": 1704153600,
519
+ "sourceChain": "Ethereum",
520
+ "address": "0x...",
521
+ },
522
+ )
523
+ ```
524
+
525
+ ---
526
+
527
+ ## Ecosystem 🔐
528
+
529
+ Ecosystem-level data.
530
+
531
+ ### getCategories
532
+
533
+ ```python
534
+ categories = pro_client.ecosystem.getCategories()
535
+ ```
536
+
537
+ ### getForks
538
+
539
+ ```python
540
+ forks = pro_client.ecosystem.getForks()
541
+ ```
542
+
543
+ ### getOracles
544
+
545
+ ```python
546
+ oracles = pro_client.ecosystem.getOracles()
547
+ ```
548
+
549
+ ### getEntities
550
+
551
+ ```python
552
+ entities = pro_client.ecosystem.getEntities()
553
+ ```
554
+
555
+ ### getTreasuries
556
+
557
+ ```python
558
+ treasuries = pro_client.ecosystem.getTreasuries()
559
+ ```
560
+
561
+ ### getHacks
562
+
563
+ ```python
564
+ hacks = pro_client.ecosystem.getHacks()
565
+ ```
566
+
567
+ ### getRaises
568
+
569
+ ```python
570
+ raises = pro_client.ecosystem.getRaises()
571
+ ```
572
+
573
+ ---
574
+
575
+ ## ETFs 🔐
576
+
577
+ Bitcoin and Ethereum ETF data.
578
+
579
+ ### getOverview
580
+
581
+ ```python
582
+ btc_etfs = pro_client.etfs.getOverview()
583
+ ```
584
+
585
+ ### getOverviewEth
586
+
587
+ ```python
588
+ eth_etfs = pro_client.etfs.getOverviewEth()
589
+ ```
590
+
591
+ ### getHistory
592
+
593
+ ```python
594
+ history = pro_client.etfs.getHistory()
595
+ ```
596
+
597
+ ### getHistoryEth
598
+
599
+ ```python
600
+ history_eth = pro_client.etfs.getHistoryEth()
601
+ ```
602
+
603
+ ### getFdvPerformance
604
+
605
+ ```python
606
+ perf = pro_client.etfs.getFdvPerformance("30")
607
+ ```
608
+
609
+ ---
610
+
611
+ ## DAT 🔐
612
+
613
+ Digital Asset Treasury data and institutional holdings.
614
+
615
+ ### getInstitutions
616
+
617
+ ```python
618
+ data = pro_client.dat.getInstitutions()
619
+ ```
620
+
621
+ ### getInstitution
622
+
623
+ ```python
624
+ mstr = pro_client.dat.getInstitution("MSTR")
625
+ ```
626
+
627
+ ---
628
+
629
+ ## Account 🔐
630
+
631
+ API usage management.
632
+
633
+ ### getUsage
634
+
635
+ ```python
636
+ usage = pro_client.account.getUsage()
637
+ ```
638
+
639
+ ---
640
+
641
+ ## Error Handling
642
+
643
+ ```python
644
+ from defillama_api import ApiKeyRequiredError, RateLimitError, NotFoundError, ApiError
645
+
646
+ try:
647
+ data = pro_client.yields.getPools()
648
+ except ApiKeyRequiredError:
649
+ print("Pro API key required for this endpoint")
650
+ except RateLimitError as exc:
651
+ print(f"Rate limited. Retry after {exc.retry_after} seconds")
652
+ except NotFoundError:
653
+ print("Resource not found")
654
+ except ApiError as exc:
655
+ print(f"API error: {exc.status_code}")
656
+ ```
657
+
658
+ ---
659
+
660
+ ## Type Exports
661
+
662
+ All types are available from `defillama_api.types`, and are re-exported at the top level:
663
+
664
+ ```python
665
+ from defillama_api import Protocol, CoinPricesResponse, Stablecoin, YieldPool
666
+ ```
667
+
668
+ ---
669
+
670
+ ## Constants
671
+
672
+ ```python
673
+ from defillama_api import AdapterType, FeeDataType, VolumeDataType
674
+
675
+ AdapterType.DEXS
676
+ VolumeDataType.DAILY_VOLUME
677
+ FeeDataType.DAILY_FEES
678
+ ```
679
+
680
+ ---
681
+
682
+ ## Requirements
683
+
684
+ - Python >= 3.9
685
+
686
+ ## License
687
+
688
+ MIT