erpc-sdk 0.3.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.
- erpc_sdk-0.3.0/.gitignore +17 -0
- erpc_sdk-0.3.0/LICENSE +21 -0
- erpc_sdk-0.3.0/PKG-INFO +152 -0
- erpc_sdk-0.3.0/README.md +101 -0
- erpc_sdk-0.3.0/pyproject.toml +65 -0
- erpc_sdk-0.3.0/src/erpc_sdk/__init__.py +108 -0
- erpc_sdk-0.3.0/src/erpc_sdk/client.py +213 -0
- erpc_sdk-0.3.0/src/erpc_sdk/config.py +114 -0
- erpc_sdk-0.3.0/src/erpc_sdk/errors.py +110 -0
- erpc_sdk-0.3.0/src/erpc_sdk/py.typed +1 -0
- erpc_sdk-0.3.0/src/erpc_sdk/rest.py +486 -0
- erpc_sdk-0.3.0/src/erpc_sdk/rpc.py +291 -0
- erpc_sdk-0.3.0/src/erpc_sdk/subscriptions.py +351 -0
- erpc_sdk-0.3.0/src/erpc_sdk/transport.py +316 -0
- erpc_sdk-0.3.0/src/erpc_sdk/types.py +180 -0
- erpc_sdk-0.3.0/tests/test_client.py +215 -0
- erpc_sdk-0.3.0/tests/test_rest.py +151 -0
- erpc_sdk-0.3.0/tests/test_subscriptions.py +84 -0
erpc_sdk-0.3.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ELSOUL LABO B.V.
|
|
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.
|
erpc_sdk-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: erpc-sdk
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Async Python SDK for ERPC
|
|
5
|
+
Project-URL: Documentation, https://github.com/elsoul/erpc-sdk/tree/main/packages/python
|
|
6
|
+
Project-URL: Homepage, https://erpc.global
|
|
7
|
+
Project-URL: Repository, https://github.com/elsoul/erpc-sdk
|
|
8
|
+
Author: ELSOUL LABO B.V.
|
|
9
|
+
License: MIT License
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 ELSOUL LABO B.V.
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Keywords: erpc,ethereum,json-rpc,rpc,solana
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Framework :: AsyncIO
|
|
34
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
35
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
39
|
+
Classifier: Typing :: Typed
|
|
40
|
+
Requires-Python: >=3.11
|
|
41
|
+
Requires-Dist: httpx<1,>=0.27
|
|
42
|
+
Requires-Dist: websockets<17,>=13
|
|
43
|
+
Provides-Extra: dev
|
|
44
|
+
Requires-Dist: build<2,>=1.2; extra == 'dev'
|
|
45
|
+
Requires-Dist: mypy<2,>=1.11; extra == 'dev'
|
|
46
|
+
Requires-Dist: pytest-asyncio<2,>=0.24; extra == 'dev'
|
|
47
|
+
Requires-Dist: pytest<10,>=8; extra == 'dev'
|
|
48
|
+
Requires-Dist: ruff<1,>=0.8; extra == 'dev'
|
|
49
|
+
Requires-Dist: twine<7,>=5; extra == 'dev'
|
|
50
|
+
Description-Content-Type: text/markdown
|
|
51
|
+
|
|
52
|
+
# ERPC SDK for Python
|
|
53
|
+
|
|
54
|
+
Async Python client for ERPC. It covers standard Solana and Ethereum JSON-RPC,
|
|
55
|
+
indexed assets, history, leader and analytics RPC, WebSocket subscriptions,
|
|
56
|
+
price REST and server-sent events, account usage, and scoped Cloud reads.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
python -m pip install erpc-sdk
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Python 3.11 or newer is required.
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import asyncio
|
|
68
|
+
import os
|
|
69
|
+
|
|
70
|
+
from erpc_sdk import ErpcClient, ErpcClientConfig
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
async def main() -> None:
|
|
74
|
+
async with ErpcClient(ErpcClientConfig(os.environ["ERPC_API_KEY"])) as erpc:
|
|
75
|
+
slot = await erpc.solana.rpc.get_slot().send()
|
|
76
|
+
chain_id = await erpc.ethereum.rpc.eth_chain_id().send()
|
|
77
|
+
print(slot, chain_id)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
asyncio.run(main())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Both exact wire names (`getSlot`, `eth_chainId`) and Python snake-case aliases
|
|
84
|
+
(`get_slot`, `eth_chain_id`) create inert requests. Network I/O starts only
|
|
85
|
+
when `send()` is awaited. `request()` restricts calls to the namespace catalog;
|
|
86
|
+
`raw()` is the forward-compatible escape hatch.
|
|
87
|
+
|
|
88
|
+
## Namespaces
|
|
89
|
+
|
|
90
|
+
| Namespace | Purpose |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| `erpc.solana.rpc` | Standard Solana JSON-RPC |
|
|
93
|
+
| `erpc.solana.das` | Indexed assets and tokens |
|
|
94
|
+
| `erpc.solana.history` | Address transactions and transfers |
|
|
95
|
+
| `erpc.solana.leaders` | Leader slots and validator information |
|
|
96
|
+
| `erpc.solana.analytics` | Epoch, slot, program, and TPS analytics |
|
|
97
|
+
| `erpc.solana.subscriptions` | Enhanced WebSocket subscriptions |
|
|
98
|
+
| `erpc.ethereum.rpc` | Standard Ethereum JSON-RPC |
|
|
99
|
+
| `erpc.ethereum.subscriptions` | Ethereum WebSocket subscriptions |
|
|
100
|
+
| `erpc.price` | Price metadata, updates, and SSE streams |
|
|
101
|
+
| `erpc.account` | Token balance |
|
|
102
|
+
| `erpc.usage` | Masked monthly API-key usage |
|
|
103
|
+
|
|
104
|
+
## Intact batches
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
results = await erpc.solana.rpc.batch([
|
|
108
|
+
{"method": "getSlot", "params": []},
|
|
109
|
+
{"method": "getBlockHeight", "params": []},
|
|
110
|
+
]).send()
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The SDK sends one caller batch as one server batch, restores caller order,
|
|
114
|
+
accepts at most 256 calls, and rejects invalid mixed or unsupported batches
|
|
115
|
+
locally. It never silently splits a batch.
|
|
116
|
+
|
|
117
|
+
## Subscriptions
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
subscription = await erpc.ethereum.subscriptions.subscribe("newHeads")
|
|
121
|
+
async for header in subscription:
|
|
122
|
+
print(header)
|
|
123
|
+
await subscription.unsubscribe()
|
|
124
|
+
break
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Solana exposes `account_subscribe`, `transaction_subscribe`, and
|
|
128
|
+
`raw_subscribe`. HTTP requests accept a `RequestOptions(cancel_event=...)`;
|
|
129
|
+
normal asyncio task cancellation is also preserved.
|
|
130
|
+
|
|
131
|
+
## Cloud reads
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from erpc_sdk import ErpcCloudClient, ErpcCloudClientConfig
|
|
135
|
+
|
|
136
|
+
async with ErpcCloudClient(ErpcCloudClientConfig(access_token)) as cloud:
|
|
137
|
+
offerings = await cloud.catalog.list()
|
|
138
|
+
resources = await cloud.resources.list()
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Cloud configuration accepts HTTPS endpoints and localhost HTTP endpoints for
|
|
142
|
+
testing. It retains only the access token supplied by the caller and does not
|
|
143
|
+
implement interactive authorization or refresh-credential storage.
|
|
144
|
+
|
|
145
|
+
## Safety boundaries
|
|
146
|
+
|
|
147
|
+
- Credentials are redacted from configuration representations, public
|
|
148
|
+
endpoints, transport errors, and JSON-RPC error data.
|
|
149
|
+
- State-changing calls, including transaction submission, are never retried.
|
|
150
|
+
- REST, JSON-RPC, and caller batch boundaries remain explicit.
|
|
151
|
+
- Unknown methods remain available through `raw()` without being included in
|
|
152
|
+
the typed compatibility catalog.
|
erpc_sdk-0.3.0/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# ERPC SDK for Python
|
|
2
|
+
|
|
3
|
+
Async Python client for ERPC. It covers standard Solana and Ethereum JSON-RPC,
|
|
4
|
+
indexed assets, history, leader and analytics RPC, WebSocket subscriptions,
|
|
5
|
+
price REST and server-sent events, account usage, and scoped Cloud reads.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
python -m pip install erpc-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Python 3.11 or newer is required.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import asyncio
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
from erpc_sdk import ErpcClient, ErpcClientConfig
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
async def main() -> None:
|
|
23
|
+
async with ErpcClient(ErpcClientConfig(os.environ["ERPC_API_KEY"])) as erpc:
|
|
24
|
+
slot = await erpc.solana.rpc.get_slot().send()
|
|
25
|
+
chain_id = await erpc.ethereum.rpc.eth_chain_id().send()
|
|
26
|
+
print(slot, chain_id)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
asyncio.run(main())
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Both exact wire names (`getSlot`, `eth_chainId`) and Python snake-case aliases
|
|
33
|
+
(`get_slot`, `eth_chain_id`) create inert requests. Network I/O starts only
|
|
34
|
+
when `send()` is awaited. `request()` restricts calls to the namespace catalog;
|
|
35
|
+
`raw()` is the forward-compatible escape hatch.
|
|
36
|
+
|
|
37
|
+
## Namespaces
|
|
38
|
+
|
|
39
|
+
| Namespace | Purpose |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `erpc.solana.rpc` | Standard Solana JSON-RPC |
|
|
42
|
+
| `erpc.solana.das` | Indexed assets and tokens |
|
|
43
|
+
| `erpc.solana.history` | Address transactions and transfers |
|
|
44
|
+
| `erpc.solana.leaders` | Leader slots and validator information |
|
|
45
|
+
| `erpc.solana.analytics` | Epoch, slot, program, and TPS analytics |
|
|
46
|
+
| `erpc.solana.subscriptions` | Enhanced WebSocket subscriptions |
|
|
47
|
+
| `erpc.ethereum.rpc` | Standard Ethereum JSON-RPC |
|
|
48
|
+
| `erpc.ethereum.subscriptions` | Ethereum WebSocket subscriptions |
|
|
49
|
+
| `erpc.price` | Price metadata, updates, and SSE streams |
|
|
50
|
+
| `erpc.account` | Token balance |
|
|
51
|
+
| `erpc.usage` | Masked monthly API-key usage |
|
|
52
|
+
|
|
53
|
+
## Intact batches
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
results = await erpc.solana.rpc.batch([
|
|
57
|
+
{"method": "getSlot", "params": []},
|
|
58
|
+
{"method": "getBlockHeight", "params": []},
|
|
59
|
+
]).send()
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The SDK sends one caller batch as one server batch, restores caller order,
|
|
63
|
+
accepts at most 256 calls, and rejects invalid mixed or unsupported batches
|
|
64
|
+
locally. It never silently splits a batch.
|
|
65
|
+
|
|
66
|
+
## Subscriptions
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
subscription = await erpc.ethereum.subscriptions.subscribe("newHeads")
|
|
70
|
+
async for header in subscription:
|
|
71
|
+
print(header)
|
|
72
|
+
await subscription.unsubscribe()
|
|
73
|
+
break
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Solana exposes `account_subscribe`, `transaction_subscribe`, and
|
|
77
|
+
`raw_subscribe`. HTTP requests accept a `RequestOptions(cancel_event=...)`;
|
|
78
|
+
normal asyncio task cancellation is also preserved.
|
|
79
|
+
|
|
80
|
+
## Cloud reads
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from erpc_sdk import ErpcCloudClient, ErpcCloudClientConfig
|
|
84
|
+
|
|
85
|
+
async with ErpcCloudClient(ErpcCloudClientConfig(access_token)) as cloud:
|
|
86
|
+
offerings = await cloud.catalog.list()
|
|
87
|
+
resources = await cloud.resources.list()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Cloud configuration accepts HTTPS endpoints and localhost HTTP endpoints for
|
|
91
|
+
testing. It retains only the access token supplied by the caller and does not
|
|
92
|
+
implement interactive authorization or refresh-credential storage.
|
|
93
|
+
|
|
94
|
+
## Safety boundaries
|
|
95
|
+
|
|
96
|
+
- Credentials are redacted from configuration representations, public
|
|
97
|
+
endpoints, transport errors, and JSON-RPC error data.
|
|
98
|
+
- State-changing calls, including transaction submission, are never retried.
|
|
99
|
+
- REST, JSON-RPC, and caller batch boundaries remain explicit.
|
|
100
|
+
- Unknown methods remain available through `raw()` without being included in
|
|
101
|
+
the typed compatibility catalog.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25,<1.28"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "erpc-sdk"
|
|
7
|
+
version = "0.3.0"
|
|
8
|
+
description = "Async Python SDK for ERPC"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { file = "LICENSE" }
|
|
12
|
+
authors = [{ name = "ELSOUL LABO B.V." }]
|
|
13
|
+
keywords = ["erpc", "ethereum", "json-rpc", "rpc", "solana"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Framework :: AsyncIO",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"httpx>=0.27,<1",
|
|
26
|
+
"websockets>=13,<17",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = [
|
|
31
|
+
"build>=1.2,<2",
|
|
32
|
+
"mypy>=1.11,<2",
|
|
33
|
+
"pytest>=8,<10",
|
|
34
|
+
"pytest-asyncio>=0.24,<2",
|
|
35
|
+
"ruff>=0.8,<1",
|
|
36
|
+
"twine>=5,<7",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Documentation = "https://github.com/elsoul/erpc-sdk/tree/main/packages/python"
|
|
41
|
+
Homepage = "https://erpc.global"
|
|
42
|
+
Repository = "https://github.com/elsoul/erpc-sdk"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.sdist]
|
|
45
|
+
include = ["/src", "/tests", "/LICENSE", "/README.md", "/pyproject.toml"]
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["src/erpc_sdk"]
|
|
49
|
+
|
|
50
|
+
[tool.mypy]
|
|
51
|
+
python_version = "3.11"
|
|
52
|
+
strict = true
|
|
53
|
+
packages = ["erpc_sdk"]
|
|
54
|
+
mypy_path = "src"
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
asyncio_mode = "auto"
|
|
58
|
+
testpaths = ["tests"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 100
|
|
62
|
+
target-version = "py311"
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = ["B", "E", "F", "I", "UP"]
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Async Python SDK for ERPC."""
|
|
2
|
+
|
|
3
|
+
from .client import (
|
|
4
|
+
ErpcClient,
|
|
5
|
+
ErpcCloudClient,
|
|
6
|
+
EthereumClient,
|
|
7
|
+
SolanaClient,
|
|
8
|
+
create_erpc_client,
|
|
9
|
+
create_erpc_cloud_client,
|
|
10
|
+
)
|
|
11
|
+
from .config import (
|
|
12
|
+
DEFAULT_ACCOUNT_ENDPOINT,
|
|
13
|
+
DEFAULT_ENDPOINT,
|
|
14
|
+
DEFAULT_TIMEOUT,
|
|
15
|
+
DEFAULT_USER_ENDPOINT,
|
|
16
|
+
ErpcClientConfig,
|
|
17
|
+
ErpcCloudClientConfig,
|
|
18
|
+
)
|
|
19
|
+
from .errors import (
|
|
20
|
+
ErpcAbortedError,
|
|
21
|
+
ErpcBatchPolicyError,
|
|
22
|
+
ErpcConfigError,
|
|
23
|
+
ErpcError,
|
|
24
|
+
ErpcErrorCode,
|
|
25
|
+
ErpcHttpError,
|
|
26
|
+
ErpcInvalidResponseError,
|
|
27
|
+
ErpcJsonRpcError,
|
|
28
|
+
ErpcTimeoutError,
|
|
29
|
+
ErpcTransportError,
|
|
30
|
+
)
|
|
31
|
+
from .rest import (
|
|
32
|
+
AccountClient,
|
|
33
|
+
CloudCatalogClient,
|
|
34
|
+
CloudCreditClient,
|
|
35
|
+
CloudResourcesClient,
|
|
36
|
+
PriceClient,
|
|
37
|
+
UsageClient,
|
|
38
|
+
)
|
|
39
|
+
from .rpc import (
|
|
40
|
+
ETHEREUM_RPC_METHODS,
|
|
41
|
+
ETHEREUM_SUBSCRIPTION_METHODS,
|
|
42
|
+
SOLANA_ANALYTICS_METHODS,
|
|
43
|
+
SOLANA_DAS_METHODS,
|
|
44
|
+
SOLANA_ENHANCED_SUBSCRIPTION_METHODS,
|
|
45
|
+
SOLANA_HISTORY_METHODS,
|
|
46
|
+
SOLANA_LEADER_METHODS,
|
|
47
|
+
SOLANA_RPC_METHODS,
|
|
48
|
+
PendingRpcBatchRequest,
|
|
49
|
+
PendingRpcRequest,
|
|
50
|
+
RpcNamespace,
|
|
51
|
+
)
|
|
52
|
+
from .subscriptions import (
|
|
53
|
+
EthereumSubscriptions,
|
|
54
|
+
RpcSubscription,
|
|
55
|
+
SolanaSubscriptions,
|
|
56
|
+
WebSocketJsonRpcTransport,
|
|
57
|
+
)
|
|
58
|
+
from .transport import HttpJsonRpcTransport
|
|
59
|
+
from .types import * # noqa: F403
|
|
60
|
+
|
|
61
|
+
__version__ = "0.3.0"
|
|
62
|
+
|
|
63
|
+
__all__ = [
|
|
64
|
+
"DEFAULT_ACCOUNT_ENDPOINT",
|
|
65
|
+
"DEFAULT_ENDPOINT",
|
|
66
|
+
"DEFAULT_TIMEOUT",
|
|
67
|
+
"DEFAULT_USER_ENDPOINT",
|
|
68
|
+
"ETHEREUM_RPC_METHODS",
|
|
69
|
+
"ETHEREUM_SUBSCRIPTION_METHODS",
|
|
70
|
+
"SOLANA_ANALYTICS_METHODS",
|
|
71
|
+
"SOLANA_DAS_METHODS",
|
|
72
|
+
"SOLANA_ENHANCED_SUBSCRIPTION_METHODS",
|
|
73
|
+
"SOLANA_HISTORY_METHODS",
|
|
74
|
+
"SOLANA_LEADER_METHODS",
|
|
75
|
+
"SOLANA_RPC_METHODS",
|
|
76
|
+
"AccountClient",
|
|
77
|
+
"CloudCatalogClient",
|
|
78
|
+
"CloudCreditClient",
|
|
79
|
+
"CloudResourcesClient",
|
|
80
|
+
"EthereumClient",
|
|
81
|
+
"EthereumSubscriptions",
|
|
82
|
+
"ErpcAbortedError",
|
|
83
|
+
"ErpcBatchPolicyError",
|
|
84
|
+
"ErpcClient",
|
|
85
|
+
"ErpcClientConfig",
|
|
86
|
+
"ErpcCloudClient",
|
|
87
|
+
"ErpcCloudClientConfig",
|
|
88
|
+
"ErpcConfigError",
|
|
89
|
+
"ErpcError",
|
|
90
|
+
"ErpcErrorCode",
|
|
91
|
+
"ErpcHttpError",
|
|
92
|
+
"ErpcInvalidResponseError",
|
|
93
|
+
"ErpcJsonRpcError",
|
|
94
|
+
"ErpcTimeoutError",
|
|
95
|
+
"ErpcTransportError",
|
|
96
|
+
"HttpJsonRpcTransport",
|
|
97
|
+
"PendingRpcBatchRequest",
|
|
98
|
+
"PendingRpcRequest",
|
|
99
|
+
"PriceClient",
|
|
100
|
+
"RpcNamespace",
|
|
101
|
+
"RpcSubscription",
|
|
102
|
+
"SolanaClient",
|
|
103
|
+
"SolanaSubscriptions",
|
|
104
|
+
"UsageClient",
|
|
105
|
+
"WebSocketJsonRpcTransport",
|
|
106
|
+
"create_erpc_client",
|
|
107
|
+
"create_erpc_cloud_client",
|
|
108
|
+
]
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""Top-level ERPC and Cloud client composition."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from .config import (
|
|
10
|
+
ErpcClientConfig,
|
|
11
|
+
ErpcCloudClientConfig,
|
|
12
|
+
endpoint_with_path,
|
|
13
|
+
websocket_url,
|
|
14
|
+
)
|
|
15
|
+
from .rest import (
|
|
16
|
+
AccountClient,
|
|
17
|
+
CloudCatalogClient,
|
|
18
|
+
CloudCreditClient,
|
|
19
|
+
CloudResourcesClient,
|
|
20
|
+
PriceClient,
|
|
21
|
+
UsageClient,
|
|
22
|
+
)
|
|
23
|
+
from .rpc import (
|
|
24
|
+
ETHEREUM_RPC_METHODS,
|
|
25
|
+
SOLANA_ANALYTICS_METHODS,
|
|
26
|
+
SOLANA_DAS_METHODS,
|
|
27
|
+
SOLANA_HISTORY_METHODS,
|
|
28
|
+
SOLANA_LEADER_METHODS,
|
|
29
|
+
SOLANA_RPC_METHODS,
|
|
30
|
+
RpcNamespace,
|
|
31
|
+
)
|
|
32
|
+
from .subscriptions import (
|
|
33
|
+
EthereumSubscriptions,
|
|
34
|
+
SolanaSubscriptions,
|
|
35
|
+
WebSocketJsonRpcTransport,
|
|
36
|
+
)
|
|
37
|
+
from .transport import HttpJsonRpcTransport, RestTransport
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True, slots=True)
|
|
41
|
+
class SolanaClient:
|
|
42
|
+
rpc: RpcNamespace
|
|
43
|
+
das: RpcNamespace
|
|
44
|
+
history: RpcNamespace
|
|
45
|
+
leaders: RpcNamespace
|
|
46
|
+
analytics: RpcNamespace
|
|
47
|
+
subscriptions: SolanaSubscriptions
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True, slots=True)
|
|
51
|
+
class EthereumClient:
|
|
52
|
+
rpc: RpcNamespace
|
|
53
|
+
subscriptions: EthereumSubscriptions
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ErpcClient:
|
|
57
|
+
"""Async-first client for JSON-RPC, REST, streams, and subscriptions."""
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
config: ErpcClientConfig,
|
|
62
|
+
*,
|
|
63
|
+
http_client: httpx.AsyncClient | None = None,
|
|
64
|
+
) -> None:
|
|
65
|
+
client = http_client or httpx.AsyncClient(timeout=None, follow_redirects=False)
|
|
66
|
+
self._http_client = client
|
|
67
|
+
self._owns_http_client = http_client is None
|
|
68
|
+
solana_transport = HttpJsonRpcTransport(
|
|
69
|
+
api_key=config.api_key,
|
|
70
|
+
endpoint=config.endpoint,
|
|
71
|
+
headers=config.headers,
|
|
72
|
+
timeout=config.timeout,
|
|
73
|
+
client=client,
|
|
74
|
+
)
|
|
75
|
+
ethereum_transport = HttpJsonRpcTransport(
|
|
76
|
+
api_key=config.api_key,
|
|
77
|
+
endpoint=endpoint_with_path(config.endpoint, "/eth"),
|
|
78
|
+
headers=config.headers,
|
|
79
|
+
timeout=config.timeout,
|
|
80
|
+
client=client,
|
|
81
|
+
)
|
|
82
|
+
solana_ws = WebSocketJsonRpcTransport(
|
|
83
|
+
websocket_url(config.endpoint, config.api_key),
|
|
84
|
+
config.api_key,
|
|
85
|
+
config.timeout,
|
|
86
|
+
)
|
|
87
|
+
ethereum_ws = WebSocketJsonRpcTransport(
|
|
88
|
+
websocket_url(config.endpoint, config.api_key, "/eth"),
|
|
89
|
+
config.api_key,
|
|
90
|
+
config.timeout,
|
|
91
|
+
)
|
|
92
|
+
self.solana = SolanaClient(
|
|
93
|
+
rpc=RpcNamespace(
|
|
94
|
+
solana_transport,
|
|
95
|
+
SOLANA_RPC_METHODS,
|
|
96
|
+
parameter_mode="positional",
|
|
97
|
+
batch_policy="solana-standard",
|
|
98
|
+
),
|
|
99
|
+
das=RpcNamespace(solana_transport, SOLANA_DAS_METHODS, parameter_mode="named"),
|
|
100
|
+
history=RpcNamespace(
|
|
101
|
+
solana_transport, SOLANA_HISTORY_METHODS, parameter_mode="positional"
|
|
102
|
+
),
|
|
103
|
+
leaders=RpcNamespace(
|
|
104
|
+
solana_transport,
|
|
105
|
+
SOLANA_LEADER_METHODS,
|
|
106
|
+
parameter_mode="positional",
|
|
107
|
+
batch_policy="unsupported",
|
|
108
|
+
),
|
|
109
|
+
analytics=RpcNamespace(
|
|
110
|
+
solana_transport,
|
|
111
|
+
SOLANA_ANALYTICS_METHODS,
|
|
112
|
+
parameter_mode="positional",
|
|
113
|
+
),
|
|
114
|
+
subscriptions=SolanaSubscriptions(solana_ws),
|
|
115
|
+
)
|
|
116
|
+
self.ethereum = EthereumClient(
|
|
117
|
+
rpc=RpcNamespace(ethereum_transport, ETHEREUM_RPC_METHODS, parameter_mode="positional"),
|
|
118
|
+
subscriptions=EthereumSubscriptions(ethereum_ws),
|
|
119
|
+
)
|
|
120
|
+
self.price = PriceClient(
|
|
121
|
+
RestTransport(
|
|
122
|
+
credential=config.api_key,
|
|
123
|
+
endpoint=config.endpoint,
|
|
124
|
+
headers=config.headers,
|
|
125
|
+
timeout=config.timeout,
|
|
126
|
+
client=client,
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
self.account = AccountClient(
|
|
130
|
+
RestTransport(
|
|
131
|
+
credential=config.api_key,
|
|
132
|
+
endpoint=config.account_endpoint,
|
|
133
|
+
headers=config.headers,
|
|
134
|
+
timeout=config.timeout,
|
|
135
|
+
client=client,
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
self.usage = UsageClient(
|
|
139
|
+
RestTransport(
|
|
140
|
+
credential=config.api_key,
|
|
141
|
+
endpoint=config.user_endpoint,
|
|
142
|
+
headers=config.headers,
|
|
143
|
+
timeout=config.timeout,
|
|
144
|
+
client=client,
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
self._closed = False
|
|
148
|
+
|
|
149
|
+
async def close(self) -> None:
|
|
150
|
+
if self._closed:
|
|
151
|
+
return
|
|
152
|
+
self._closed = True
|
|
153
|
+
await self.solana.subscriptions.close()
|
|
154
|
+
await self.ethereum.subscriptions.close()
|
|
155
|
+
if self._owns_http_client:
|
|
156
|
+
await self._http_client.aclose()
|
|
157
|
+
|
|
158
|
+
async def __aenter__(self) -> ErpcClient:
|
|
159
|
+
return self
|
|
160
|
+
|
|
161
|
+
async def __aexit__(self, *_: object) -> None:
|
|
162
|
+
await self.close()
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class ErpcCloudClient:
|
|
166
|
+
"""Scoped Cloud catalog, credit, resource, and usage reads."""
|
|
167
|
+
|
|
168
|
+
def __init__(
|
|
169
|
+
self,
|
|
170
|
+
config: ErpcCloudClientConfig,
|
|
171
|
+
*,
|
|
172
|
+
http_client: httpx.AsyncClient | None = None,
|
|
173
|
+
) -> None:
|
|
174
|
+
client = http_client or httpx.AsyncClient(timeout=None, follow_redirects=False)
|
|
175
|
+
self._http_client = client
|
|
176
|
+
self._owns_http_client = http_client is None
|
|
177
|
+
transport = RestTransport(
|
|
178
|
+
credential=config.access_token,
|
|
179
|
+
endpoint=config.endpoint,
|
|
180
|
+
headers=config.headers,
|
|
181
|
+
timeout=config.timeout,
|
|
182
|
+
client=client,
|
|
183
|
+
)
|
|
184
|
+
self.catalog = CloudCatalogClient(transport)
|
|
185
|
+
self.credit = CloudCreditClient(transport)
|
|
186
|
+
self.resources = CloudResourcesClient(transport)
|
|
187
|
+
self.usage = UsageClient(transport)
|
|
188
|
+
self._closed = False
|
|
189
|
+
|
|
190
|
+
async def close(self) -> None:
|
|
191
|
+
if self._closed:
|
|
192
|
+
return
|
|
193
|
+
self._closed = True
|
|
194
|
+
if self._owns_http_client:
|
|
195
|
+
await self._http_client.aclose()
|
|
196
|
+
|
|
197
|
+
async def __aenter__(self) -> ErpcCloudClient:
|
|
198
|
+
return self
|
|
199
|
+
|
|
200
|
+
async def __aexit__(self, *_: object) -> None:
|
|
201
|
+
await self.close()
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def create_erpc_client(
|
|
205
|
+
config: ErpcClientConfig, *, http_client: httpx.AsyncClient | None = None
|
|
206
|
+
) -> ErpcClient:
|
|
207
|
+
return ErpcClient(config, http_client=http_client)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def create_erpc_cloud_client(
|
|
211
|
+
config: ErpcCloudClientConfig, *, http_client: httpx.AsyncClient | None = None
|
|
212
|
+
) -> ErpcCloudClient:
|
|
213
|
+
return ErpcCloudClient(config, http_client=http_client)
|