sol-parser-sdk-python 0.4.4__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.
- sol_parser_sdk_python-0.4.4/.env.example +21 -0
- sol_parser_sdk_python-0.4.4/.gitignore +10 -0
- sol_parser_sdk_python-0.4.4/PKG-INFO +14 -0
- sol_parser_sdk_python-0.4.4/README.md +277 -0
- sol_parser_sdk_python-0.4.4/README_CN.md +249 -0
- sol_parser_sdk_python-0.4.4/examples/meteora_damm_grpc.py +237 -0
- sol_parser_sdk_python-0.4.4/examples/multi_protocol_grpc.py +121 -0
- sol_parser_sdk_python-0.4.4/examples/parse_tx_by_signature.py +144 -0
- sol_parser_sdk_python-0.4.4/examples/pumpfun_quick_test.py +112 -0
- sol_parser_sdk_python-0.4.4/examples/pumpfun_trade_filter.py +263 -0
- sol_parser_sdk_python-0.4.4/examples/pumpfun_with_metrics.py +194 -0
- sol_parser_sdk_python-0.4.4/examples/pumpswap_low_latency.py +203 -0
- sol_parser_sdk_python-0.4.4/examples/pumpswap_with_metrics.py +194 -0
- sol_parser_sdk_python-0.4.4/examples/rust_example_utils.py +11 -0
- sol_parser_sdk_python-0.4.4/pyproject.toml +35 -0
- sol_parser_sdk_python-0.4.4/scripts/bench_parser.py +22 -0
- sol_parser_sdk_python-0.4.4/scripts/gen_golden_rust.sh +6 -0
- sol_parser_sdk_python-0.4.4/sol_parser/__init__.py +400 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_dispatcher.py +209 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_fillers/__init__.py +5 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_fillers/bonk.py +30 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_fillers/meteora.py +51 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_fillers/orca.py +40 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_fillers/pumpfun.py +97 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_fillers/pumpswap.py +93 -0
- sol_parser_sdk_python-0.4.4/sol_parser/account_fillers/raydium.py +119 -0
- sol_parser_sdk_python-0.4.4/sol_parser/accounts/__init__.py +461 -0
- sol_parser_sdk_python-0.4.4/sol_parser/accounts/rpc_wallet.py +64 -0
- sol_parser_sdk_python-0.4.4/sol_parser/accounts/utils.py +71 -0
- sol_parser_sdk_python-0.4.4/sol_parser/check_migration.py +18 -0
- sol_parser_sdk_python-0.4.4/sol_parser/clock.py +10 -0
- sol_parser_sdk_python-0.4.4/sol_parser/common/__init__.py +27 -0
- sol_parser_sdk_python-0.4.4/sol_parser/dex_parsers.py +2576 -0
- sol_parser_sdk_python-0.4.4/sol_parser/entries_decode.py +186 -0
- sol_parser_sdk_python-0.4.4/sol_parser/env_config.py +215 -0
- sol_parser_sdk_python-0.4.4/sol_parser/event_types.py +1750 -0
- sol_parser_sdk_python-0.4.4/sol_parser/geyser_pb2.py +148 -0
- sol_parser_sdk_python-0.4.4/sol_parser/geyser_pb2_grpc.py +398 -0
- sol_parser_sdk_python-0.4.4/sol_parser/grpc/__init__.py +61 -0
- sol_parser_sdk_python-0.4.4/sol_parser/grpc/geyser_connect.py +42 -0
- sol_parser_sdk_python-0.4.4/sol_parser/grpc/subscribe_builder.py +133 -0
- sol_parser_sdk_python-0.4.4/sol_parser/grpc/transaction_meta.py +183 -0
- sol_parser_sdk_python-0.4.4/sol_parser/grpc_client.py +870 -0
- sol_parser_sdk_python-0.4.4/sol_parser/grpc_instruction_parser.py +318 -0
- sol_parser_sdk_python-0.4.4/sol_parser/grpc_types.py +919 -0
- sol_parser_sdk_python-0.4.4/sol_parser/inner_instruction_parser.py +281 -0
- sol_parser_sdk_python-0.4.4/sol_parser/instr/__init__.py +15 -0
- sol_parser_sdk_python-0.4.4/sol_parser/instr_account_utils.py +58 -0
- sol_parser_sdk_python-0.4.4/sol_parser/instructions.py +1026 -0
- sol_parser_sdk_python-0.4.4/sol_parser/json_util.py +41 -0
- sol_parser_sdk_python-0.4.4/sol_parser/log_instr_dedup.py +284 -0
- sol_parser_sdk_python-0.4.4/sol_parser/logs/__init__.py +15 -0
- sol_parser_sdk_python-0.4.4/sol_parser/merger.py +233 -0
- sol_parser_sdk_python-0.4.4/sol_parser/order_buffer.py +171 -0
- sol_parser_sdk_python-0.4.4/sol_parser/parser.py +300 -0
- sol_parser_sdk_python-0.4.4/sol_parser/pumpfun_fee_enrich.py +75 -0
- sol_parser_sdk_python-0.4.4/sol_parser/rpc_parser.py +655 -0
- sol_parser_sdk_python-0.4.4/sol_parser/rust_api_inventory.py +42 -0
- sol_parser_sdk_python-0.4.4/sol_parser/rust_event_json.py +50 -0
- sol_parser_sdk_python-0.4.4/sol_parser/shredstream_client.py +191 -0
- sol_parser_sdk_python-0.4.4/sol_parser/shredstream_pb2.py +40 -0
- sol_parser_sdk_python-0.4.4/sol_parser/shredstream_pb2_grpc.py +81 -0
- sol_parser_sdk_python-0.4.4/sol_parser/shredstream_pumpfun.py +296 -0
- sol_parser_sdk_python-0.4.4/sol_parser/solana_storage_pb2.py +75 -0
- sol_parser_sdk_python-0.4.4/sol_parser/solana_storage_pb2_grpc.py +24 -0
- sol_parser_sdk_python-0.4.4/sol_parser/u128_parity.py +115 -0
- sol_parser_sdk_python-0.4.4/sol_parser/verify_discriminators.py +85 -0
- sol_parser_sdk_python-0.4.4/tests/fixtures/golden_parse_log.json +13 -0
- sol_parser_sdk_python-0.4.4/tests/test_filter_and_account_parity.py +89 -0
- sol_parser_sdk_python-0.4.4/tests/test_golden.py +35 -0
- sol_parser_sdk_python-0.4.4/tests/test_imports_and_inner.py +37 -0
- sol_parser_sdk_python-0.4.4/tests/test_log_instr_dedup.py +50 -0
- sol_parser_sdk_python-0.4.4/tests/test_order_buffer.py +38 -0
- sol_parser_sdk_python-0.4.4/tests/test_pumpfun_v2_parity.py +83 -0
- sol_parser_sdk_python-0.4.4/tests/test_raydium_clmm_instruction_parity.py +107 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copy to `.env` in the package root (`.env` is gitignored — do not commit secrets)
|
|
2
|
+
|
|
3
|
+
# --- Yellowstone gRPC (Python examples under examples/*_grpc.py) ---
|
|
4
|
+
GRPC_URL=https://your-yellowstone-host:443
|
|
5
|
+
# Same as Rust sol-parser-sdk examples (either works):
|
|
6
|
+
# GRPC_ENDPOINT=https://your-yellowstone-host:443
|
|
7
|
+
GRPC_TOKEN=your_x_token_here
|
|
8
|
+
# GRPC_AUTH_TOKEN=your_x_token_here
|
|
9
|
+
|
|
10
|
+
# Legacy aliases (still supported):
|
|
11
|
+
# GEYSER_ENDPOINT=solana-yellowstone-grpc.publicnode.com:443
|
|
12
|
+
# GEYSER_API_TOKEN=
|
|
13
|
+
|
|
14
|
+
# --- ShredStream (when you add ShredStream examples; same as Node) ---
|
|
15
|
+
# SHREDSTREAM_URL=http://127.0.0.1:10800
|
|
16
|
+
# SHRED_URL=http://127.0.0.1:10800
|
|
17
|
+
|
|
18
|
+
# --- examples/parse_tx_by_signature.py ---
|
|
19
|
+
# RPC_URL=https://api.mainnet-beta.solana.com
|
|
20
|
+
# SOLANA_RPC_URL=https://api.mainnet-beta.solana.com
|
|
21
|
+
# TX_SIGNATURE=
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sol-parser-sdk-python
|
|
3
|
+
Version: 0.4.4
|
|
4
|
+
Summary: Solana DEX program log parsing (pure Python, API aligned with sol-parser-sdk)
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: base58>=2.0
|
|
7
|
+
Requires-Dist: grpcio-tools>=1.64.0
|
|
8
|
+
Requires-Dist: grpcio>=1.64.0
|
|
9
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: pytest-benchmark>=4.0; extra == 'dev'
|
|
12
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
13
|
+
Provides-Extra: shredstream
|
|
14
|
+
Requires-Dist: solders>=0.21.0; extra == 'shredstream'
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>⚡ Sol Parser SDK - Python</h1>
|
|
3
|
+
<h3><em>High-performance Solana DEX event parser for Python</em></h3>
|
|
4
|
+
</div>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<strong>High-performance Python library for parsing Solana DEX events in real-time via Yellowstone gRPC</strong>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://pypi.org/project/sol-parser-sdk-python/">
|
|
12
|
+
<img src="https://img.shields.io/pypi/v/sol-parser-sdk-python.svg" alt="PyPI">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/LICENSE">
|
|
15
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img src="https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python">
|
|
21
|
+
<img src="https://img.shields.io/badge/Solana-9945FF?style=for-the-badge&logo=solana&logoColor=white" alt="Solana">
|
|
22
|
+
<img src="https://img.shields.io/badge/gRPC-4285F4?style=for-the-badge&logo=grpc&logoColor=white" alt="gRPC">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<a href="./README_CN.md">中文</a> |
|
|
27
|
+
<a href="./README.md">English</a> |
|
|
28
|
+
<a href="https://fnzero.dev/">Website</a> |
|
|
29
|
+
<a href="https://t.me/fnzero_group">Telegram</a> |
|
|
30
|
+
<a href="https://discord.gg/vuazbGkqQE">Discord</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
> ☕ **Support This Project**
|
|
34
|
+
>
|
|
35
|
+
> This SDK is completely free and open source. However, maintaining and continuously updating it requires significant AI computing resources and token consumption. If this SDK helps with your development, consider making a monthly SOL donation — any amount is appreciated and helps keep this project alive!
|
|
36
|
+
>
|
|
37
|
+
> **Donation Wallet:** `6oW7AXz1yRb57pYSxysuXnMs2aR1ha5rzGzReZ1MjPV8`
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Other language SDKs
|
|
42
|
+
|
|
43
|
+
| Language | Repository |
|
|
44
|
+
|----------|------------|
|
|
45
|
+
| Rust | [sol-parser-sdk](https://github.com/0xfnzero/sol-parser-sdk) |
|
|
46
|
+
| Node.js | [sol-parser-sdk-nodejs](https://github.com/0xfnzero/sol-parser-sdk-nodejs) |
|
|
47
|
+
| Python | [sol-parser-sdk-python](https://github.com/0xfnzero/sol-parser-sdk-python) |
|
|
48
|
+
| Go | [sol-parser-sdk-golang](https://github.com/0xfnzero/sol-parser-sdk-golang) |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## How to use
|
|
53
|
+
|
|
54
|
+
### 1. Install
|
|
55
|
+
|
|
56
|
+
**From PyPI**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install sol-parser-sdk-python
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**From source**
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone https://github.com/0xfnzero/sol-parser-sdk-python
|
|
66
|
+
cd sol-parser-sdk-python
|
|
67
|
+
pip install -e .
|
|
68
|
+
pip install grpcio grpcio-tools protobuf base58 python-dotenv
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2. Environment (Yellowstone gRPC examples)
|
|
72
|
+
|
|
73
|
+
At the **package root** (next to `pyproject.toml`):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
cp .env.example .env
|
|
77
|
+
# Set GRPC_URL (or GRPC_ENDPOINT) and GRPC_AUTH_TOKEN or GRPC_TOKEN
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Run examples from that directory so `.env` is picked up (same idea as the Node.js package).
|
|
81
|
+
|
|
82
|
+
**CLI overrides:** `--grpc-url` / `-g`, `--grpc-token` / `--token` (also `--grpc-url=https://host:443`). **Rust-compatible names:** `GRPC_AUTH_TOKEN` (same as [sol-parser-sdk](https://github.com/0xfnzero/sol-parser-sdk) examples), `GRPC_ENDPOINT` (alias for URL). **Legacy env:** `GEYSER_ENDPOINT` / `GEYSER_API_TOKEN`. **Precedence:** CLI > `GRPC_URL` / `GRPC_ENDPOINT` > `GEYSER_*` > defaults; token: CLI > `GRPC_AUTH_TOKEN` > `GRPC_TOKEN` > `GEYSER_API_TOKEN`. Explicit shell `export` wins over `.env`; `python-dotenv` does not overwrite existing variables.
|
|
83
|
+
|
|
84
|
+
Helpers: `sol_parser.env_config` (`parse_grpc_credentials`, `require_grpc_env`, `parse_shredstream_url`, …), re-exported from `sol_parser`.
|
|
85
|
+
|
|
86
|
+
### 3. Smoke test
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python examples/pumpfun_quick_test.py
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Requires `GRPC_URL` (or `GRPC_ENDPOINT`) and (for most providers) `GRPC_AUTH_TOKEN` or `GRPC_TOKEN` in `.env` or the environment. You can pass credentials on the command line instead; see step 2.
|
|
93
|
+
|
|
94
|
+
### 4. Minimal gRPC subscribe + parse
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import asyncio
|
|
98
|
+
import os
|
|
99
|
+
|
|
100
|
+
import base58
|
|
101
|
+
|
|
102
|
+
from sol_parser import parse_logs_only
|
|
103
|
+
from sol_parser.grpc_client import YellowstoneGrpc
|
|
104
|
+
from sol_parser.grpc_types import Protocol, SubscribeCallbacks, transaction_filter_for_protocols
|
|
105
|
+
|
|
106
|
+
async def main():
|
|
107
|
+
endpoint = (
|
|
108
|
+
os.environ.get("GRPC_URL", "").strip()
|
|
109
|
+
or os.environ.get("GRPC_ENDPOINT", "").strip()
|
|
110
|
+
or os.environ.get("GEYSER_ENDPOINT", "solana-yellowstone-grpc.publicnode.com:443")
|
|
111
|
+
)
|
|
112
|
+
token = (
|
|
113
|
+
os.environ.get("GRPC_AUTH_TOKEN", "").strip()
|
|
114
|
+
or os.environ.get("GRPC_TOKEN", "").strip()
|
|
115
|
+
or os.environ.get("GEYSER_API_TOKEN", "")
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
client = YellowstoneGrpc(endpoint)
|
|
119
|
+
if token:
|
|
120
|
+
client.set_x_token(token)
|
|
121
|
+
await client.connect()
|
|
122
|
+
|
|
123
|
+
filter_ = transaction_filter_for_protocols([Protocol.PUMP_FUN, Protocol.PUMP_SWAP])
|
|
124
|
+
filter_.vote = False
|
|
125
|
+
filter_.failed = False
|
|
126
|
+
|
|
127
|
+
def on_update(update):
|
|
128
|
+
if update.transaction is None or update.transaction.transaction is None:
|
|
129
|
+
return
|
|
130
|
+
tx_info = update.transaction.transaction
|
|
131
|
+
slot = update.transaction.slot
|
|
132
|
+
logs = tx_info.log_messages
|
|
133
|
+
if not logs:
|
|
134
|
+
return
|
|
135
|
+
sb = bytes(tx_info.signature) if tx_info.signature else b""
|
|
136
|
+
sig = base58.b58encode(sb).decode("ascii") if len(sb) == 64 else ""
|
|
137
|
+
events = parse_logs_only(
|
|
138
|
+
logs, sig, slot, None, subscribe_tx_info=tx_info
|
|
139
|
+
) # tx_info from gRPC update — fills accounts from instruction keys
|
|
140
|
+
for ev in events:
|
|
141
|
+
print(ev)
|
|
142
|
+
|
|
143
|
+
sub = await client.subscribe_transactions(
|
|
144
|
+
filter_,
|
|
145
|
+
SubscribeCallbacks(on_update=on_update, on_error=print, on_end=lambda: None),
|
|
146
|
+
)
|
|
147
|
+
print("subscribed", sub.id)
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
await asyncio.Event().wait()
|
|
151
|
+
except KeyboardInterrupt:
|
|
152
|
+
pass
|
|
153
|
+
await client.disconnect()
|
|
154
|
+
|
|
155
|
+
asyncio.run(main())
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Lighter path:** `parse_logs_only(logs, …)` only needs log messages from the update (no full wire transaction).
|
|
159
|
+
|
|
160
|
+
### 5. ShredStream (HTTP — not Yellowstone gRPC)
|
|
161
|
+
|
|
162
|
+
The Node.js SDK includes a ShredStream HTTP client. **Python** provides the same env/CLI helpers as Node (`parse_shredstream_url`: `SHREDSTREAM_URL` / `SHRED_URL`, `--url` / `-u` / `--endpoint=`) for configuration parity; a native ShredStream client may be added later. **Not** `GRPC_URL`.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Examples
|
|
167
|
+
|
|
168
|
+
From the **package root** after `pip install -e .`. Run with `python examples/<file>.py`. Scripts are written to mirror the **output layout and env names** of [sol-parser-sdk/examples](https://github.com/0xfnzero/sol-parser-sdk/tree/main/examples) (Rust); streaming uses `subscribe_transactions` + `parse_logs_only` with the same program IDs as `TransactionFilter::for_protocols` in Rust.
|
|
169
|
+
|
|
170
|
+
| Description | Run command | Source |
|
|
171
|
+
|-------------|-------------|--------|
|
|
172
|
+
| **PumpFun** | | |
|
|
173
|
+
| PumpFun trade filtering | `python examples/pumpfun_trade_filter.py` | [pumpfun_trade_filter.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpfun_trade_filter.py) |
|
|
174
|
+
| PumpFun events + metrics | `python examples/pumpfun_with_metrics.py` | [pumpfun_with_metrics.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpfun_with_metrics.py) |
|
|
175
|
+
| Quick PumpFun connection test | `python examples/pumpfun_quick_test.py` | [pumpfun_quick_test.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpfun_quick_test.py) |
|
|
176
|
+
| **PumpSwap** | | |
|
|
177
|
+
| PumpSwap ultra-low latency | `python examples/pumpswap_low_latency.py` | [pumpswap_low_latency.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpswap_low_latency.py) |
|
|
178
|
+
| PumpSwap events + metrics | `python examples/pumpswap_with_metrics.py` | [pumpswap_with_metrics.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpswap_with_metrics.py) |
|
|
179
|
+
| **Meteora DAMM** | | |
|
|
180
|
+
| Meteora DAMM V2 events | `python examples/meteora_damm_grpc.py` | [meteora_damm_grpc.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/meteora_damm_grpc.py) |
|
|
181
|
+
| **Multi-protocol** | | |
|
|
182
|
+
| Subscribe to every program in Rust `Protocol` / `program_ids` | `python examples/multi_protocol_grpc.py` | [multi_protocol_grpc.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/multi_protocol_grpc.py) |
|
|
183
|
+
| **Utility** | | |
|
|
184
|
+
| Parse tx by signature (HTTP RPC; not gRPC). `TX_SIGNATURE` / `RPC_URL` or `SOLANA_RPC_URL` in `.env` or `--sig` / `--rpc`. | `python examples/parse_tx_by_signature.py` | [parse_tx_by_signature.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/parse_tx_by_signature.py) |
|
|
185
|
+
|
|
186
|
+
**Env:** gRPC examples need **`GRPC_URL`** or **`GRPC_ENDPOINT`**, plus **`GRPC_AUTH_TOKEN`** or **`GRPC_TOKEN`** (or legacy `GEYSER_*`). See **`.env.example`**.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Protocols
|
|
191
|
+
|
|
192
|
+
PumpFun, PumpSwap, Raydium AMM V4 / CLMM / CPMM, Orca Whirlpool, Meteora DAMM V2 / DLMM, Bonk Launchpad (see `sol_parser/`).
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Useful exports
|
|
197
|
+
|
|
198
|
+
- `parse_logs_only` — log-based DEX events from gRPC log messages.
|
|
199
|
+
- `format_dex_event_json` / `dex_event_to_jsonable` — pretty-print `DexEvent` as indented JSON (one field per line); `repr(ev)` is the default dataclass single-line form, not JSON.
|
|
200
|
+
- `YellowstoneGrpc` — async Yellowstone gRPC client (`connect`, `subscribe_transactions`, `disconnect`).
|
|
201
|
+
- `now_micros` — microsecond clock (same role as Rust `sol_parser_sdk::core::now_micros`).
|
|
202
|
+
- `transaction_filter_for_protocols` / `program_ids_for_protocols` / `account_filter_for_protocols` — same program IDs as Rust `Protocol` + `for_protocols` in `grpc/filter.rs`.
|
|
203
|
+
- `parse_grpc_credentials` / `require_grpc_env` — load `.env` + env + CLI (aligned with [sol-parser-sdk-nodejs](https://github.com/0xfnzero/sol-parser-sdk-nodejs) `grpc_env`).
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Advanced
|
|
208
|
+
|
|
209
|
+
### Custom gRPC endpoint
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
import os
|
|
213
|
+
|
|
214
|
+
from sol_parser.grpc_client import YellowstoneGrpc
|
|
215
|
+
|
|
216
|
+
endpoint = os.environ.get("GRPC_URL") or os.environ.get("GRPC_ENDPOINT") or os.environ.get(
|
|
217
|
+
"GEYSER_ENDPOINT", "solana-yellowstone-grpc.publicnode.com:443"
|
|
218
|
+
)
|
|
219
|
+
token = (
|
|
220
|
+
os.environ.get("GRPC_AUTH_TOKEN")
|
|
221
|
+
or os.environ.get("GRPC_TOKEN")
|
|
222
|
+
or os.environ.get("GEYSER_API_TOKEN", "")
|
|
223
|
+
)
|
|
224
|
+
client = YellowstoneGrpc(endpoint)
|
|
225
|
+
if token:
|
|
226
|
+
client.set_x_token(token)
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Create + buy detection
|
|
230
|
+
|
|
231
|
+
`parse_logs_only` can detect create-and-buy patterns from program logs; see the PumpFun examples.
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Project structure
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
sol-parser-sdk-python/
|
|
239
|
+
├── sol_parser/
|
|
240
|
+
│ ├── grpc_client.py # YellowstoneGrpc (async connect / subscribe)
|
|
241
|
+
│ ├── env_config.py # GRPC_URL, .env, CLI helpers (Node parity)
|
|
242
|
+
│ ├── clock.py # now_micros()
|
|
243
|
+
│ ├── grpc_types.py # TransactionFilter, SubscribeCallbacks, for_protocols helpers, …
|
|
244
|
+
│ ├── parser.py # parse_logs_only, …
|
|
245
|
+
│ ├── geyser_pb2.py # Generated proto (Yellowstone)
|
|
246
|
+
│ └── …
|
|
247
|
+
├── examples/
|
|
248
|
+
│ ├── pumpfun_trade_filter.py
|
|
249
|
+
│ ├── pumpfun_quick_test.py
|
|
250
|
+
│ └── …
|
|
251
|
+
├── .env.example
|
|
252
|
+
└── pyproject.toml
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## Development
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
pip install -e ".[dev]"
|
|
261
|
+
pytest tests/
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
MIT — https://github.com/0xfnzero/sol-parser-sdk-python
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## Contact
|
|
273
|
+
|
|
274
|
+
- **Repository**: https://github.com/0xfnzero/sol-parser-sdk-python
|
|
275
|
+
- **Website**: https://fnzero.dev/
|
|
276
|
+
- **Telegram**: https://t.me/fnzero_group
|
|
277
|
+
- **Discord**: https://discord.gg/vuazbGkqQE
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>⚡ Sol Parser SDK - Python</h1>
|
|
3
|
+
<h3><em>高性能 Solana DEX 事件解析(Python / asyncio)</em></h3>
|
|
4
|
+
</div>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<strong>通过 Yellowstone gRPC 实时解析 Solana DEX 事件的 Python 库</strong>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://pypi.org/project/sol-parser-sdk-python/">
|
|
12
|
+
<img src="https://img.shields.io/pypi/v/sol-parser-sdk-python.svg" alt="PyPI">
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/LICENSE">
|
|
15
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
<p align="center">
|
|
20
|
+
<img src="https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white" alt="Python">
|
|
21
|
+
<img src="https://img.shields.io/badge/Solana-9945FF?style=for-the-badge&logo=solana&logoColor=white" alt="Solana">
|
|
22
|
+
<img src="https://img.shields.io/badge/gRPC-4285F4?style=for-the-badge&logo=grpc&logoColor=white" alt="gRPC">
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<a href="./README_CN.md">中文</a> |
|
|
27
|
+
<a href="./README.md">English</a> |
|
|
28
|
+
<a href="https://fnzero.dev/">官网</a> |
|
|
29
|
+
<a href="https://t.me/fnzero_group">Telegram</a> |
|
|
30
|
+
<a href="https://discord.gg/vuazbGkqQE">Discord</a>
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
> ☕ **支持本项目**
|
|
34
|
+
>
|
|
35
|
+
> 本 SDK 完全免费且开源。但维护和持续更新需要消耗大量 AI 算力与 Token。如果这个 SDK 对您的开发有帮助,欢迎每月捐赠任意数量的 SOL,您的支持将帮助这个项目持续运行!
|
|
36
|
+
>
|
|
37
|
+
> **捐赠钱包:** `6oW7AXz1yRb57pYSxysuXnMs2aR1ha5rzGzReZ1MjPV8`
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 其他语言 SDK
|
|
42
|
+
|
|
43
|
+
| 语言 | 仓库 |
|
|
44
|
+
|------|------|
|
|
45
|
+
| Rust | [sol-parser-sdk](https://github.com/0xfnzero/sol-parser-sdk) |
|
|
46
|
+
| Node.js | [sol-parser-sdk-nodejs](https://github.com/0xfnzero/sol-parser-sdk-nodejs) |
|
|
47
|
+
| Python | [sol-parser-sdk-python](https://github.com/0xfnzero/sol-parser-sdk-python) |
|
|
48
|
+
| Go | [sol-parser-sdk-golang](https://github.com/0xfnzero/sol-parser-sdk-golang) |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 怎么用
|
|
53
|
+
|
|
54
|
+
### 1. 安装
|
|
55
|
+
|
|
56
|
+
**PyPI**
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install sol-parser-sdk-python
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**源码**
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone https://github.com/0xfnzero/sol-parser-sdk-python
|
|
66
|
+
cd sol-parser-sdk-python
|
|
67
|
+
pip install -e .
|
|
68
|
+
pip install grpcio grpcio-tools protobuf base58 python-dotenv
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2. 环境变量(Yellowstone gRPC 示例)
|
|
72
|
+
|
|
73
|
+
在**包根目录**(与 `pyproject.toml` 同级):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
cp .env.example .env
|
|
77
|
+
# 填写 GRPC_URL(或 GRPC_ENDPOINT)、GRPC_AUTH_TOKEN 或 GRPC_TOKEN
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
在该目录下运行示例,以便加载 `.env`(与 Node 包行为一致)。
|
|
81
|
+
|
|
82
|
+
**命令行覆盖:** `--grpc-url` / `-g`、`--grpc-token` / `--token`(亦支持 `--grpc-url=https://host:443`)。**与 Rust 示例一致的名字:** `GRPC_AUTH_TOKEN`、`GRPC_ENDPOINT`(URL 别名)。**旧名:** `GEYSER_ENDPOINT` / `GEYSER_API_TOKEN`。**优先级:** 命令行 > `GRPC_URL` / `GRPC_ENDPOINT` > `GEYSER_*`;Token:命令行 > `GRPC_AUTH_TOKEN` > `GRPC_TOKEN` > `GEYSER_API_TOKEN`。已在 shell 里 `export` 的变量优先于 `.env`;`python-dotenv` 不会覆盖已有环境变量。
|
|
83
|
+
|
|
84
|
+
辅助函数:`sol_parser.env_config`(`parse_grpc_credentials`、`require_grpc_env`、`parse_shredstream_url` 等),亦可从 `sol_parser` 直接导入。
|
|
85
|
+
|
|
86
|
+
### 3. 冒烟
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python examples/pumpfun_quick_test.py
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
需要 `GRPC_URL`(或 `GRPC_ENDPOINT`)以及多数提供商要求的 `GRPC_AUTH_TOKEN` 或 `GRPC_TOKEN`(写在 `.env` 或环境中),也可用命令行传入,见步骤 2。
|
|
93
|
+
|
|
94
|
+
### 4. 最小 gRPC 订阅示例
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import asyncio
|
|
98
|
+
import os
|
|
99
|
+
|
|
100
|
+
import base58
|
|
101
|
+
|
|
102
|
+
from sol_parser import parse_logs_only
|
|
103
|
+
from sol_parser.grpc_client import YellowstoneGrpc
|
|
104
|
+
from sol_parser.grpc_types import Protocol, SubscribeCallbacks, transaction_filter_for_protocols
|
|
105
|
+
|
|
106
|
+
async def main():
|
|
107
|
+
endpoint = (
|
|
108
|
+
os.environ.get("GRPC_URL", "").strip()
|
|
109
|
+
or os.environ.get("GRPC_ENDPOINT", "").strip()
|
|
110
|
+
or os.environ.get("GEYSER_ENDPOINT", "solana-yellowstone-grpc.publicnode.com:443")
|
|
111
|
+
)
|
|
112
|
+
token = (
|
|
113
|
+
os.environ.get("GRPC_AUTH_TOKEN", "").strip()
|
|
114
|
+
or os.environ.get("GRPC_TOKEN", "").strip()
|
|
115
|
+
or os.environ.get("GEYSER_API_TOKEN", "")
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
client = YellowstoneGrpc(endpoint)
|
|
119
|
+
if token:
|
|
120
|
+
client.set_x_token(token)
|
|
121
|
+
await client.connect()
|
|
122
|
+
|
|
123
|
+
filter_ = transaction_filter_for_protocols([Protocol.PUMP_FUN, Protocol.PUMP_SWAP])
|
|
124
|
+
filter_.vote = False
|
|
125
|
+
filter_.failed = False
|
|
126
|
+
|
|
127
|
+
def on_update(update):
|
|
128
|
+
if update.transaction is None or update.transaction.transaction is None:
|
|
129
|
+
return
|
|
130
|
+
tx_info = update.transaction.transaction
|
|
131
|
+
slot = update.transaction.slot
|
|
132
|
+
logs = tx_info.log_messages
|
|
133
|
+
if not logs:
|
|
134
|
+
return
|
|
135
|
+
sb = bytes(tx_info.signature) if tx_info.signature else b""
|
|
136
|
+
sig = base58.b58encode(sb).decode("ascii") if len(sb) == 64 else ""
|
|
137
|
+
events = parse_logs_only(
|
|
138
|
+
logs, sig, slot, None, subscribe_tx_info=tx_info
|
|
139
|
+
) # 来自 gRPC 的 tx_info,用于从指令账户补全字段
|
|
140
|
+
for ev in events:
|
|
141
|
+
print(ev)
|
|
142
|
+
|
|
143
|
+
sub = await client.subscribe_transactions(
|
|
144
|
+
filter_,
|
|
145
|
+
SubscribeCallbacks(on_update=on_update, on_error=print, on_end=lambda: None),
|
|
146
|
+
)
|
|
147
|
+
print("subscribed", sub.id)
|
|
148
|
+
|
|
149
|
+
try:
|
|
150
|
+
await asyncio.Event().wait()
|
|
151
|
+
except KeyboardInterrupt:
|
|
152
|
+
pass
|
|
153
|
+
await client.disconnect()
|
|
154
|
+
|
|
155
|
+
asyncio.run(main())
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
更轻量:仅用日志时用 `parse_logs_only`(无需完整线格式交易)。
|
|
159
|
+
|
|
160
|
+
### 5. ShredStream(HTTP,不是 Yellowstone gRPC)
|
|
161
|
+
|
|
162
|
+
Node 版提供 ShredStream HTTP 客户端。**Python** 侧提供与 Node 相同的配置方式(`parse_shredstream_url`:`SHREDSTREAM_URL` / `SHRED_URL`,`--url` / `-u` / `--endpoint=`);原生 ShredStream 客户端后续可能补充。**不要**用 `GRPC_URL` 配 ShredStream。
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 示例列表
|
|
167
|
+
|
|
168
|
+
在**包根目录**执行,`pip install -e .` 之后。运行:`python examples/<文件>.py`。示例的**打印格式与环境变量命名**与 Rust 仓库 [sol-parser-sdk/examples](https://github.com/0xfnzero/sol-parser-sdk/tree/main/examples) 对齐;流式订阅在 Python 侧为 `subscribe_transactions` + `parse_logs_only`,Program ID 与 Rust `TransactionFilter::for_protocols` 一致。
|
|
169
|
+
|
|
170
|
+
| 描述 | 运行命令 | 源码 |
|
|
171
|
+
|------|----------|------|
|
|
172
|
+
| **PumpFun** | | |
|
|
173
|
+
| PumpFun 交易过滤 | `python examples/pumpfun_trade_filter.py` | [pumpfun_trade_filter.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpfun_trade_filter.py) |
|
|
174
|
+
| PumpFun 事件 + 性能指标 | `python examples/pumpfun_with_metrics.py` | [pumpfun_with_metrics.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpfun_with_metrics.py) |
|
|
175
|
+
| PumpFun 快速连接测试 | `python examples/pumpfun_quick_test.py` | [pumpfun_quick_test.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpfun_quick_test.py) |
|
|
176
|
+
| **PumpSwap** | | |
|
|
177
|
+
| PumpSwap 超低延迟 | `python examples/pumpswap_low_latency.py` | [pumpswap_low_latency.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpswap_low_latency.py) |
|
|
178
|
+
| PumpSwap 事件 + 性能指标 | `python examples/pumpswap_with_metrics.py` | [pumpswap_with_metrics.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/pumpswap_with_metrics.py) |
|
|
179
|
+
| **Meteora DAMM** | | |
|
|
180
|
+
| Meteora DAMM V2 事件 | `python examples/meteora_damm_grpc.py` | [meteora_damm_grpc.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/meteora_damm_grpc.py) |
|
|
181
|
+
| **多协议** | | |
|
|
182
|
+
| 订阅 Rust `Protocol` / `program_ids` 中的全部程序 | `python examples/multi_protocol_grpc.py` | [multi_protocol_grpc.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/multi_protocol_grpc.py) |
|
|
183
|
+
| **工具** | | |
|
|
184
|
+
| 按签名解析交易(HTTP RPC,非 gRPC)。`.env` 或环境中 `TX_SIGNATURE` / `RPC_URL` 或 `SOLANA_RPC_URL`,或 `--sig` / `--rpc`。 | `python examples/parse_tx_by_signature.py` | [parse_tx_by_signature.py](https://github.com/0xfnzero/sol-parser-sdk-python/blob/main/examples/parse_tx_by_signature.py) |
|
|
185
|
+
|
|
186
|
+
**环境变量:** gRPC 示例需要 **`GRPC_URL`** 或 **`GRPC_ENDPOINT`**,以及 **`GRPC_AUTH_TOKEN`** 或 **`GRPC_TOKEN`**(或旧名 `GEYSER_*`)。详见 **`.env.example`**。
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## 协议
|
|
191
|
+
|
|
192
|
+
PumpFun、PumpSwap、Raydium AMM V4 / CLMM / CPMM、Orca Whirlpool、Meteora DAMM V2 / DLMM、Bonk Launchpad(见 `sol_parser/`)。
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 常用 API
|
|
197
|
+
|
|
198
|
+
- `parse_logs_only` — 从 gRPC 日志消息解析 DEX 事件。
|
|
199
|
+
- `format_dex_event_json` / `dex_event_to_jsonable` — 将 `DexEvent` 格式化为缩进 JSON(一行一个字段);直接 `print(ev)`/`repr` 为 dataclass 默认单行,不是 JSON。
|
|
200
|
+
- `YellowstoneGrpc` — 异步 Yellowstone 客户端(`connect`、`subscribe_transactions`、`disconnect`)。
|
|
201
|
+
- `now_micros` — 微秒时间戳(对应 Rust `sol_parser_sdk::core::now_micros`)。
|
|
202
|
+
- `transaction_filter_for_protocols` / `program_ids_for_protocols` / `account_filter_for_protocols` — 与 Rust `Protocol` + `for_protocols` 相同的 Program ID。
|
|
203
|
+
- `parse_grpc_credentials` / `require_grpc_env` — 加载 `.env` + 环境变量 + 命令行(与 [sol-parser-sdk-nodejs](https://github.com/0xfnzero/sol-parser-sdk-nodejs) 的 `grpc_env` 对齐)。
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## 项目结构
|
|
208
|
+
|
|
209
|
+
```
|
|
210
|
+
sol-parser-sdk-python/
|
|
211
|
+
├── sol_parser/
|
|
212
|
+
│ ├── grpc_client.py # YellowstoneGrpc(异步连接 / 订阅)
|
|
213
|
+
│ ├── env_config.py # GRPC_URL、.env、命令行(与 Node 对齐)
|
|
214
|
+
│ ├── clock.py # now_micros()
|
|
215
|
+
│ ├── grpc_types.py # TransactionFilter、SubscribeCallbacks、for_protocols 等
|
|
216
|
+
│ ├── parser.py # parse_logs_only…
|
|
217
|
+
│ ├── geyser_pb2.py # 生成的 proto(Yellowstone)
|
|
218
|
+
│ └── …
|
|
219
|
+
├── examples/
|
|
220
|
+
│ ├── pumpfun_trade_filter.py
|
|
221
|
+
│ ├── pumpfun_quick_test.py
|
|
222
|
+
│ └── …
|
|
223
|
+
├── .env.example
|
|
224
|
+
└── pyproject.toml
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## 开发
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
pip install -e ".[dev]"
|
|
233
|
+
pytest tests/
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## 许可证
|
|
239
|
+
|
|
240
|
+
MIT — https://github.com/0xfnzero/sol-parser-sdk-python
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## 联系我们
|
|
245
|
+
|
|
246
|
+
- **仓库**: https://github.com/0xfnzero/sol-parser-sdk-python
|
|
247
|
+
- **官网**: https://fnzero.dev/
|
|
248
|
+
- **Telegram**: https://t.me/fnzero_group
|
|
249
|
+
- **Discord**: https://discord.gg/vuazbGkqQE
|