dexpaprika-sdk 0.2.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 (37) hide show
  1. dexpaprika_sdk-0.2.0/CHANGELOG.md +36 -0
  2. dexpaprika_sdk-0.2.0/MANIFEST.in +9 -0
  3. dexpaprika_sdk-0.2.0/PKG-INFO +333 -0
  4. dexpaprika_sdk-0.2.0/README.md +293 -0
  5. dexpaprika_sdk-0.2.0/dexpaprika_sdk/__init__.py +34 -0
  6. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/__init__.py +15 -0
  7. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/base.py +225 -0
  8. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/dexes.py +35 -0
  9. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/networks.py +45 -0
  10. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/pools.py +251 -0
  11. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/search.py +28 -0
  12. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/tokens.py +90 -0
  13. dexpaprika_sdk-0.2.0/dexpaprika_sdk/api/utils.py +16 -0
  14. dexpaprika_sdk-0.2.0/dexpaprika_sdk/client.py +130 -0
  15. dexpaprika_sdk-0.2.0/dexpaprika_sdk/models/__init__.py +30 -0
  16. dexpaprika_sdk-0.2.0/dexpaprika_sdk/models/base.py +18 -0
  17. dexpaprika_sdk-0.2.0/dexpaprika_sdk/models/networks.py +26 -0
  18. dexpaprika_sdk-0.2.0/dexpaprika_sdk/models/pools.py +117 -0
  19. dexpaprika_sdk-0.2.0/dexpaprika_sdk/models/search.py +27 -0
  20. dexpaprika_sdk-0.2.0/dexpaprika_sdk/models/tokens.py +64 -0
  21. dexpaprika_sdk-0.2.0/dexpaprika_sdk/models/utils.py +10 -0
  22. dexpaprika_sdk-0.2.0/dexpaprika_sdk/utils/__init__.py +0 -0
  23. dexpaprika_sdk-0.2.0/dexpaprika_sdk/utils/perf.py +58 -0
  24. dexpaprika_sdk-0.2.0/dexpaprika_sdk.egg-info/PKG-INFO +333 -0
  25. dexpaprika_sdk-0.2.0/dexpaprika_sdk.egg-info/SOURCES.txt +35 -0
  26. dexpaprika_sdk-0.2.0/dexpaprika_sdk.egg-info/dependency_links.txt +1 -0
  27. dexpaprika_sdk-0.2.0/dexpaprika_sdk.egg-info/requires.txt +11 -0
  28. dexpaprika_sdk-0.2.0/dexpaprika_sdk.egg-info/top_level.txt +1 -0
  29. dexpaprika_sdk-0.2.0/examples/advanced_example.py +266 -0
  30. dexpaprika_sdk-0.2.0/examples/advanced_usage.py +109 -0
  31. dexpaprika_sdk-0.2.0/examples/basic_example.py +56 -0
  32. dexpaprika_sdk-0.2.0/pyproject.toml +37 -0
  33. dexpaprika_sdk-0.2.0/setup.cfg +4 -0
  34. dexpaprika_sdk-0.2.0/setup.py +50 -0
  35. dexpaprika_sdk-0.2.0/tests/test_all_endpoints.py +190 -0
  36. dexpaprika_sdk-0.2.0/tests/test_features.py +182 -0
  37. dexpaprika_sdk-0.2.0/tests/test_validation.py +73 -0
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ All notable changes to the DexPaprika SDK for Python will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2024-07-01
9
+
10
+ ### Added
11
+ - Retry with exponential backoff mechanism for API requests
12
+ - Automatic retry for connection errors, timeouts, and server errors (5xx)
13
+ - Configurable retry count and backoff times
14
+ - Default backoff times: 100ms, 500ms, 1s, and 5s with random jitter
15
+ - TTL-based caching system
16
+ - Intelligent caching with different TTLs for different types of data
17
+ - Support for caching parameterized requests
18
+ - Skip cache option to force fresh data
19
+ - Cache clearing functionality
20
+ - Example code demonstrating new features
21
+ - Unit tests for caching and retry functionality
22
+
23
+ ### Changed
24
+ - Updated documentation to reflect new features
25
+ - Improved error handling for API requests
26
+
27
+ ## [0.1.0] - 2024-06-01
28
+
29
+ ### Added
30
+ - Initial release of the DexPaprika SDK
31
+ - Support for all DexPaprika API endpoints
32
+ - Type-safe response models using Pydantic
33
+ - Parameter validation
34
+ - API services: Networks, Pools, Tokens, DEXes, Search, Utils
35
+ - Basic examples
36
+ - Unit tests
@@ -0,0 +1,9 @@
1
+ include LICENSE
2
+ include README.md
3
+ include CHANGELOG.md
4
+ recursive-include examples *.py
5
+ recursive-include docs *.md *.py *.rst
6
+ global-exclude __pycache__
7
+ global-exclude *.py[cod]
8
+ global-exclude *.so
9
+ global-exclude .DS_Store
@@ -0,0 +1,333 @@
1
+ Metadata-Version: 2.4
2
+ Name: dexpaprika-sdk
3
+ Version: 0.2.0
4
+ Summary: Python SDK for the DexPaprika API
5
+ Home-page: https://github.com/coinpaprika/dexpaprika-sdk-python
6
+ Author: CoinPaprika
7
+ Author-email: CoinPaprika <support@coinpaprika.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/coinpaprika/dexpaprika-sdk-python
10
+ Project-URL: Bug Tracker, https://github.com/coinpaprika/dexpaprika-sdk-python/issues
11
+ Project-URL: Documentation, https://docs.dexpaprika.com
12
+ Keywords: dexpaprika,crypto,blockchain,defi,api,sdk
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Classifier: Topic :: Software Development
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ Requires-Dist: requests>=2.25.0
27
+ Requires-Dist: pydantic>=2.0.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
31
+ Requires-Dist: black>=23.0.0; extra == "dev"
32
+ Requires-Dist: isort>=5.12.0; extra == "dev"
33
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
34
+ Requires-Dist: twine>=4.0.0; extra == "dev"
35
+ Requires-Dist: build>=0.10.0; extra == "dev"
36
+ Dynamic: author
37
+ Dynamic: home-page
38
+ Dynamic: provides-extra
39
+ Dynamic: requires-python
40
+
41
+ # DexPaprika Python SDK
42
+
43
+ [![PyPI version](https://badge.fury.io/py/dexpaprika-sdk.svg)](https://badge.fury.io/py/dexpaprika-sdk)
44
+ [![Python Version](https://img.shields.io/pypi/pyversions/dexpaprika-sdk)](https://pypi.org/project/dexpaprika-sdk/)
45
+ [![Tests](https://github.com/coinpaprika/dexpaprika-sdk-python/actions/workflows/tests.yml/badge.svg)](https://github.com/coinpaprika/dexpaprika-sdk-python/actions/workflows/tests.yml)
46
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
47
+
48
+ A Python client for the DexPaprika API. This SDK provides easy access to real-time data from decentralized exchanges across multiple blockchain networks.
49
+
50
+ ## Features
51
+
52
+ - Access data from 20+ blockchain networks
53
+ - Query information about DEXes, liquidity pools, and tokens
54
+ - Get detailed price information, trading volume, and transactions
55
+ - Search across the entire DexPaprika ecosystem
56
+ - Automatic parameter validation with clear error messages
57
+ - Type-safe response objects using Pydantic models
58
+ - Built-in retry with exponential backoff for API failures
59
+ - Intelligent caching system with TTL-based expiration
60
+
61
+ ## Installation
62
+
63
+ ```bash
64
+ # Install via pip
65
+ pip install dexpaprika-sdk
66
+
67
+ # Or install from source
68
+ git clone https://github.com/donbagger/dexpaprika-sdk-python.git
69
+ cd dexpaprika-sdk-python
70
+ pip install -e .
71
+ ```
72
+
73
+ ## Usage
74
+
75
+ ### Basic Example
76
+
77
+ ```python
78
+ from dexpaprika_sdk import DexPaprikaClient
79
+
80
+ # Create a new client
81
+ client = DexPaprikaClient()
82
+
83
+ # Get a list of supported networks
84
+ networks = client.networks.list()
85
+ for network in networks:
86
+ print(f"- {network.display_name} ({network.id})")
87
+
88
+ # Get stats about the DexPaprika ecosystem
89
+ stats = client.utils.get_stats()
90
+ print(f"DexPaprika stats: {stats.chains} chains, {stats.pools} pools")
91
+
92
+ # Get top pools by volume
93
+ pools = client.pools.list(limit=5, order_by="volume_usd", sort="desc")
94
+ for pool in pools.pools:
95
+ token_pair = f"{pool.tokens[0].symbol}/{pool.tokens[1].symbol}" if len(pool.tokens) >= 2 else "Unknown Pair"
96
+ print(f"- {token_pair} on {pool.dex_name} ({pool.chain}): ${pool.volume_usd:.2f} volume")
97
+ ```
98
+
99
+ ### Advanced Examples
100
+
101
+ #### Get pools for a specific network
102
+
103
+ ```python
104
+ # Get top Ethereum pools
105
+ eth_pools = client.pools.list_by_network(
106
+ network_id="ethereum",
107
+ limit=5,
108
+ order_by="volume_usd",
109
+ sort="desc"
110
+ )
111
+ ```
112
+
113
+ #### Get pools for a specific DEX
114
+
115
+ ```python
116
+ # Get top Uniswap V3 pools on Ethereum
117
+ uniswap_pools = client.pools.list_by_dex(
118
+ network_id="ethereum",
119
+ dex_id="uniswap_v3",
120
+ limit=5,
121
+ order_by="volume_usd",
122
+ sort="desc"
123
+ )
124
+ ```
125
+
126
+ #### Get details for a specific pool
127
+
128
+ ```python
129
+ # Get details for a specific pool
130
+ pool_details = client.pools.get_details(
131
+ network_id="ethereum",
132
+ pool_address="0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" # USDC/WETH Uniswap v3 pool
133
+ )
134
+ ```
135
+
136
+ #### Get OHLCV data for a pool
137
+
138
+ ```python
139
+ from datetime import datetime, timedelta
140
+
141
+ # Get OHLCV data for the last 7 days
142
+ end_date = datetime.now()
143
+ start_date = end_date - timedelta(days=7)
144
+ ohlcv_data = client.pools.get_ohlcv(
145
+ network_id="ethereum",
146
+ pool_address="0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
147
+ start=start_date.strftime("%Y-%m-%d"),
148
+ end=end_date.strftime("%Y-%m-%d"),
149
+ interval="24h",
150
+ limit=7
151
+ )
152
+ ```
153
+
154
+ #### Get tokens and pools by search query
155
+
156
+ ```python
157
+ # Search for "bitcoin" across the ecosystem
158
+ search_results = client.search.search("bitcoin")
159
+ print(f"Found {len(search_results.tokens)} tokens and {len(search_results.pools)} pools")
160
+ ```
161
+
162
+ ### Caching System
163
+
164
+ The SDK includes an intelligent caching system that helps reduce API calls and improve performance:
165
+
166
+ ```python
167
+ # Caching is enabled by default for all GET requests
168
+ # First request will be fetched from the API
169
+ networks = client.networks.list()
170
+
171
+ # Subsequent requests will use the cached data (faster)
172
+ cached_networks = client.networks.list()
173
+
174
+ # You can skip the cache when you need fresh data
175
+ fresh_networks = client.networks._get("/networks", skip_cache=True)
176
+
177
+ # Clear the entire cache
178
+ client.clear_cache()
179
+
180
+ # Clear cache only for specific endpoints
181
+ client.clear_cache(endpoint_prefix="/networks")
182
+ ```
183
+
184
+ Different types of data have different cache durations:
185
+ - Network data: 24 hours
186
+ - Pool data: 5 minutes
187
+ - Token data: 10 minutes
188
+ - Statistics: 15 minutes
189
+ - Other data: 5 minutes (default)
190
+
191
+ ### Retry with Backoff
192
+
193
+ The SDK automatically retries failed API requests with exponential backoff:
194
+
195
+ ```python
196
+ # Create a client with custom retry settings
197
+ client = DexPaprikaClient(
198
+ max_retries=4, # Number of retry attempts (default: 4)
199
+ backoff_times=[0.1, 0.5, 1.0, 5.0] # Backoff times in seconds
200
+ )
201
+
202
+ # All API requests will now use these retry settings
203
+ # The SDK will retry automatically on connection errors and server errors (5xx)
204
+ ```
205
+
206
+ Default retry behavior:
207
+ - Retries up to 4 times on connection errors, timeouts, and server errors (5xx)
208
+ - Uses backoff intervals of 100ms, 500ms, 1s, and 5s with random jitter
209
+ - Does not retry on client errors (4xx) like 404 or 403
210
+
211
+ ### Parameter Validation
212
+
213
+ The SDK automatically validates parameters before making API requests to help you avoid errors:
214
+
215
+ ```python
216
+ # Invalid parameter examples will raise helpful error messages
217
+ try:
218
+ # Invalid network ID
219
+ client.pools.list_by_network(network_id="", limit=5)
220
+ except ValueError as e:
221
+ print(e) # "network_id is required"
222
+
223
+ try:
224
+ # Invalid sort parameter
225
+ client.pools.list(sort="invalid_sort")
226
+ except ValueError as e:
227
+ print(e) # "sort must be one of: asc, desc"
228
+
229
+ try:
230
+ # Invalid limit parameter
231
+ client.pools.list(limit=500)
232
+ except ValueError as e:
233
+ print(e) # "limit must be at most 100"
234
+ ```
235
+
236
+ ### Error Handling
237
+
238
+ Handle API errors gracefully by using try/except blocks:
239
+
240
+ ```python
241
+ try:
242
+ # Try to fetch pool details
243
+ pool_details = client.pools.get_details(
244
+ network_id="ethereum",
245
+ pool_address="0xInvalidAddress"
246
+ )
247
+ except Exception as e:
248
+ if "404" in str(e):
249
+ print("Pool not found")
250
+ elif "429" in str(e):
251
+ print("Rate limit exceeded")
252
+ else:
253
+ print(f"An error occurred: {e}")
254
+ ```
255
+
256
+ ### Working with Models
257
+
258
+ All API responses are converted to typed Pydantic models for easier access and better code reliability:
259
+
260
+ ```python
261
+ # Get pool details
262
+ pool = client.pools.get_details(
263
+ network_id="ethereum",
264
+ pool_address="0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
265
+ )
266
+
267
+ # Access pool properties
268
+ print(f"Pool: {pool.tokens[0].symbol}/{pool.tokens[1].symbol}")
269
+ print(f"Volume (24h): ${pool.day.volume_usd:.2f}")
270
+ print(f"Transactions (24h): {pool.day.txns}")
271
+ print(f"Price: ${pool.last_price_usd:.4f}")
272
+
273
+ # Time interval data is available for multiple timeframes
274
+ print(f"1h price change: {pool.hour1.last_price_usd_change:.2f}%")
275
+ print(f"24h price change: {pool.day.last_price_usd_change:.2f}%")
276
+ ```
277
+
278
+ ## API Reference
279
+
280
+ The SDK provides the following main components:
281
+
282
+ - `NetworksAPI`: Access information about supported blockchain networks
283
+ - `PoolsAPI`: Query data about liquidity pools across networks
284
+ - `TokensAPI`: Access token information and related pools
285
+ - `DexesAPI`: Get information about decentralized exchanges
286
+ - `SearchAPI`: Search for tokens, pools, and DEXes
287
+ - `UtilsAPI`: Utility endpoints like global statistics
288
+
289
+ ## Publishing
290
+
291
+ For developers contributing to this package, here's how to publish a new version:
292
+
293
+ 1. Update the version in `dexpaprika_sdk/__init__.py`
294
+ 2. Update the `CHANGELOG.md`
295
+ 3. Create a new release in GitHub
296
+ 4. GitHub Actions will automatically build and publish to PyPI
297
+
298
+ ## Development Setup
299
+
300
+ ```bash
301
+ # Clone the repository
302
+ git clone https://github.com/coinpaprika/dexpaprika-sdk-python.git
303
+ cd dexpaprika-sdk-python
304
+
305
+ # Create a virtual environment (optional)
306
+ python -m venv .venv
307
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
308
+
309
+ # Install dev dependencies
310
+ pip install -e ".[dev]"
311
+ ```
312
+
313
+ ## Running Tests
314
+
315
+ ```bash
316
+ # Run tests with pytest
317
+ pytest
318
+
319
+ # Run with coverage
320
+ pytest --cov=dexpaprika_sdk tests/
321
+ ```
322
+
323
+ ## Resources
324
+
325
+ - [Official Documentation](https://docs.dexpaprika.com) - Comprehensive API reference
326
+ - [DexPaprika Website](https://dexpaprika.com) - Main product website
327
+ - [CoinPaprika](https://coinpaprika.com) - Related cryptocurrency data platform
328
+ - [Discord Community](https://discord.gg/DhJge5TUGM) - Get support and connect with other developers
329
+ - [PyPI Package](https://pypi.org/project/dexpaprika-sdk/) - Python package details
330
+
331
+ ## License
332
+
333
+ MIT License
@@ -0,0 +1,293 @@
1
+ # DexPaprika Python SDK
2
+
3
+ [![PyPI version](https://badge.fury.io/py/dexpaprika-sdk.svg)](https://badge.fury.io/py/dexpaprika-sdk)
4
+ [![Python Version](https://img.shields.io/pypi/pyversions/dexpaprika-sdk)](https://pypi.org/project/dexpaprika-sdk/)
5
+ [![Tests](https://github.com/coinpaprika/dexpaprika-sdk-python/actions/workflows/tests.yml/badge.svg)](https://github.com/coinpaprika/dexpaprika-sdk-python/actions/workflows/tests.yml)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ A Python client for the DexPaprika API. This SDK provides easy access to real-time data from decentralized exchanges across multiple blockchain networks.
9
+
10
+ ## Features
11
+
12
+ - Access data from 20+ blockchain networks
13
+ - Query information about DEXes, liquidity pools, and tokens
14
+ - Get detailed price information, trading volume, and transactions
15
+ - Search across the entire DexPaprika ecosystem
16
+ - Automatic parameter validation with clear error messages
17
+ - Type-safe response objects using Pydantic models
18
+ - Built-in retry with exponential backoff for API failures
19
+ - Intelligent caching system with TTL-based expiration
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ # Install via pip
25
+ pip install dexpaprika-sdk
26
+
27
+ # Or install from source
28
+ git clone https://github.com/donbagger/dexpaprika-sdk-python.git
29
+ cd dexpaprika-sdk-python
30
+ pip install -e .
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Basic Example
36
+
37
+ ```python
38
+ from dexpaprika_sdk import DexPaprikaClient
39
+
40
+ # Create a new client
41
+ client = DexPaprikaClient()
42
+
43
+ # Get a list of supported networks
44
+ networks = client.networks.list()
45
+ for network in networks:
46
+ print(f"- {network.display_name} ({network.id})")
47
+
48
+ # Get stats about the DexPaprika ecosystem
49
+ stats = client.utils.get_stats()
50
+ print(f"DexPaprika stats: {stats.chains} chains, {stats.pools} pools")
51
+
52
+ # Get top pools by volume
53
+ pools = client.pools.list(limit=5, order_by="volume_usd", sort="desc")
54
+ for pool in pools.pools:
55
+ token_pair = f"{pool.tokens[0].symbol}/{pool.tokens[1].symbol}" if len(pool.tokens) >= 2 else "Unknown Pair"
56
+ print(f"- {token_pair} on {pool.dex_name} ({pool.chain}): ${pool.volume_usd:.2f} volume")
57
+ ```
58
+
59
+ ### Advanced Examples
60
+
61
+ #### Get pools for a specific network
62
+
63
+ ```python
64
+ # Get top Ethereum pools
65
+ eth_pools = client.pools.list_by_network(
66
+ network_id="ethereum",
67
+ limit=5,
68
+ order_by="volume_usd",
69
+ sort="desc"
70
+ )
71
+ ```
72
+
73
+ #### Get pools for a specific DEX
74
+
75
+ ```python
76
+ # Get top Uniswap V3 pools on Ethereum
77
+ uniswap_pools = client.pools.list_by_dex(
78
+ network_id="ethereum",
79
+ dex_id="uniswap_v3",
80
+ limit=5,
81
+ order_by="volume_usd",
82
+ sort="desc"
83
+ )
84
+ ```
85
+
86
+ #### Get details for a specific pool
87
+
88
+ ```python
89
+ # Get details for a specific pool
90
+ pool_details = client.pools.get_details(
91
+ network_id="ethereum",
92
+ pool_address="0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" # USDC/WETH Uniswap v3 pool
93
+ )
94
+ ```
95
+
96
+ #### Get OHLCV data for a pool
97
+
98
+ ```python
99
+ from datetime import datetime, timedelta
100
+
101
+ # Get OHLCV data for the last 7 days
102
+ end_date = datetime.now()
103
+ start_date = end_date - timedelta(days=7)
104
+ ohlcv_data = client.pools.get_ohlcv(
105
+ network_id="ethereum",
106
+ pool_address="0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
107
+ start=start_date.strftime("%Y-%m-%d"),
108
+ end=end_date.strftime("%Y-%m-%d"),
109
+ interval="24h",
110
+ limit=7
111
+ )
112
+ ```
113
+
114
+ #### Get tokens and pools by search query
115
+
116
+ ```python
117
+ # Search for "bitcoin" across the ecosystem
118
+ search_results = client.search.search("bitcoin")
119
+ print(f"Found {len(search_results.tokens)} tokens and {len(search_results.pools)} pools")
120
+ ```
121
+
122
+ ### Caching System
123
+
124
+ The SDK includes an intelligent caching system that helps reduce API calls and improve performance:
125
+
126
+ ```python
127
+ # Caching is enabled by default for all GET requests
128
+ # First request will be fetched from the API
129
+ networks = client.networks.list()
130
+
131
+ # Subsequent requests will use the cached data (faster)
132
+ cached_networks = client.networks.list()
133
+
134
+ # You can skip the cache when you need fresh data
135
+ fresh_networks = client.networks._get("/networks", skip_cache=True)
136
+
137
+ # Clear the entire cache
138
+ client.clear_cache()
139
+
140
+ # Clear cache only for specific endpoints
141
+ client.clear_cache(endpoint_prefix="/networks")
142
+ ```
143
+
144
+ Different types of data have different cache durations:
145
+ - Network data: 24 hours
146
+ - Pool data: 5 minutes
147
+ - Token data: 10 minutes
148
+ - Statistics: 15 minutes
149
+ - Other data: 5 minutes (default)
150
+
151
+ ### Retry with Backoff
152
+
153
+ The SDK automatically retries failed API requests with exponential backoff:
154
+
155
+ ```python
156
+ # Create a client with custom retry settings
157
+ client = DexPaprikaClient(
158
+ max_retries=4, # Number of retry attempts (default: 4)
159
+ backoff_times=[0.1, 0.5, 1.0, 5.0] # Backoff times in seconds
160
+ )
161
+
162
+ # All API requests will now use these retry settings
163
+ # The SDK will retry automatically on connection errors and server errors (5xx)
164
+ ```
165
+
166
+ Default retry behavior:
167
+ - Retries up to 4 times on connection errors, timeouts, and server errors (5xx)
168
+ - Uses backoff intervals of 100ms, 500ms, 1s, and 5s with random jitter
169
+ - Does not retry on client errors (4xx) like 404 or 403
170
+
171
+ ### Parameter Validation
172
+
173
+ The SDK automatically validates parameters before making API requests to help you avoid errors:
174
+
175
+ ```python
176
+ # Invalid parameter examples will raise helpful error messages
177
+ try:
178
+ # Invalid network ID
179
+ client.pools.list_by_network(network_id="", limit=5)
180
+ except ValueError as e:
181
+ print(e) # "network_id is required"
182
+
183
+ try:
184
+ # Invalid sort parameter
185
+ client.pools.list(sort="invalid_sort")
186
+ except ValueError as e:
187
+ print(e) # "sort must be one of: asc, desc"
188
+
189
+ try:
190
+ # Invalid limit parameter
191
+ client.pools.list(limit=500)
192
+ except ValueError as e:
193
+ print(e) # "limit must be at most 100"
194
+ ```
195
+
196
+ ### Error Handling
197
+
198
+ Handle API errors gracefully by using try/except blocks:
199
+
200
+ ```python
201
+ try:
202
+ # Try to fetch pool details
203
+ pool_details = client.pools.get_details(
204
+ network_id="ethereum",
205
+ pool_address="0xInvalidAddress"
206
+ )
207
+ except Exception as e:
208
+ if "404" in str(e):
209
+ print("Pool not found")
210
+ elif "429" in str(e):
211
+ print("Rate limit exceeded")
212
+ else:
213
+ print(f"An error occurred: {e}")
214
+ ```
215
+
216
+ ### Working with Models
217
+
218
+ All API responses are converted to typed Pydantic models for easier access and better code reliability:
219
+
220
+ ```python
221
+ # Get pool details
222
+ pool = client.pools.get_details(
223
+ network_id="ethereum",
224
+ pool_address="0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640"
225
+ )
226
+
227
+ # Access pool properties
228
+ print(f"Pool: {pool.tokens[0].symbol}/{pool.tokens[1].symbol}")
229
+ print(f"Volume (24h): ${pool.day.volume_usd:.2f}")
230
+ print(f"Transactions (24h): {pool.day.txns}")
231
+ print(f"Price: ${pool.last_price_usd:.4f}")
232
+
233
+ # Time interval data is available for multiple timeframes
234
+ print(f"1h price change: {pool.hour1.last_price_usd_change:.2f}%")
235
+ print(f"24h price change: {pool.day.last_price_usd_change:.2f}%")
236
+ ```
237
+
238
+ ## API Reference
239
+
240
+ The SDK provides the following main components:
241
+
242
+ - `NetworksAPI`: Access information about supported blockchain networks
243
+ - `PoolsAPI`: Query data about liquidity pools across networks
244
+ - `TokensAPI`: Access token information and related pools
245
+ - `DexesAPI`: Get information about decentralized exchanges
246
+ - `SearchAPI`: Search for tokens, pools, and DEXes
247
+ - `UtilsAPI`: Utility endpoints like global statistics
248
+
249
+ ## Publishing
250
+
251
+ For developers contributing to this package, here's how to publish a new version:
252
+
253
+ 1. Update the version in `dexpaprika_sdk/__init__.py`
254
+ 2. Update the `CHANGELOG.md`
255
+ 3. Create a new release in GitHub
256
+ 4. GitHub Actions will automatically build and publish to PyPI
257
+
258
+ ## Development Setup
259
+
260
+ ```bash
261
+ # Clone the repository
262
+ git clone https://github.com/coinpaprika/dexpaprika-sdk-python.git
263
+ cd dexpaprika-sdk-python
264
+
265
+ # Create a virtual environment (optional)
266
+ python -m venv .venv
267
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
268
+
269
+ # Install dev dependencies
270
+ pip install -e ".[dev]"
271
+ ```
272
+
273
+ ## Running Tests
274
+
275
+ ```bash
276
+ # Run tests with pytest
277
+ pytest
278
+
279
+ # Run with coverage
280
+ pytest --cov=dexpaprika_sdk tests/
281
+ ```
282
+
283
+ ## Resources
284
+
285
+ - [Official Documentation](https://docs.dexpaprika.com) - Comprehensive API reference
286
+ - [DexPaprika Website](https://dexpaprika.com) - Main product website
287
+ - [CoinPaprika](https://coinpaprika.com) - Related cryptocurrency data platform
288
+ - [Discord Community](https://discord.gg/DhJge5TUGM) - Get support and connect with other developers
289
+ - [PyPI Package](https://pypi.org/project/dexpaprika-sdk/) - Python package details
290
+
291
+ ## License
292
+
293
+ MIT License
@@ -0,0 +1,34 @@
1
+ """
2
+ DexPaprika SDK for Python
3
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
4
+
5
+ A Python client library for the DexPaprika API,
6
+ providing access to token, pool, and DEX data
7
+ across multiple blockchain networks.
8
+
9
+ :copyright: (c) 2024 CoinPaprika
10
+ :license: MIT, see LICENSE for more details.
11
+ """
12
+
13
+ from .client import DexPaprikaClient
14
+ # Import models for easier access
15
+ from .models import (
16
+ Network, Dex, DexesResponse,
17
+ Token, Pool, PoolsResponse, TimeIntervalMetrics,
18
+ PoolDetails, OHLCVRecord, Transaction, TransactionsResponse,
19
+ TokenSummary, TokenDetails,
20
+ DexInfo, SearchResult,
21
+ Stats
22
+ )
23
+
24
+ __version__ = "0.2.0"
25
+ __all__ = [
26
+ "DexPaprikaClient",
27
+ # Models
28
+ "Network", "Dex", "DexesResponse",
29
+ "Token", "Pool", "PoolsResponse", "TimeIntervalMetrics",
30
+ "PoolDetails", "OHLCVRecord", "Transaction", "TransactionsResponse",
31
+ "TokenSummary", "TokenDetails",
32
+ "DexInfo", "SearchResult",
33
+ "Stats"
34
+ ]