Skip to main content

Solana ShredStream SDK for Python — PyO3 bindings to the Rust core, ultra-low latency UDP shred streaming.

Project description

Solana ShredStream SDK for Python

Solana ShredStream SDK/Decoder for Python, enabling ultra-low latency Solana transaction streaming via UDP shreds from ShredStream.com

Part of the ShredStream.com ecosystem — ultra-low latency Solana shred streaming via UDP.

License: MIT Python

📋 Prerequisites

  1. Create an account on ShredStream.com
  2. Launch a Shred Stream and pick your region (Frankfurt, Amsterdam, Singapore, Chicago, and more)
  3. Enter your server's IP address and the UDP port where you want to receive shreds
  4. Open your firewall for inbound UDP traffic on that port (e.g. configure your cloud provider's security group)
  5. Install Python 3.10+:
    # Linux (Ubuntu/Debian)
    sudo apt update && sudo apt install -y python3 python3-venv python3-pip
    
    # macOS
    brew install python3
    

🎁 Want to try before you buy? Open a ticket on our Discord to request a free trial.

📦 Installation

# Create a virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate

# Install the SDK
pip install shredstream

⚡ Quick Start

Create a file main.py:

from shredstream import ShredListener
from solders.transaction import VersionedTransaction
import os

PORT = int(os.environ.get("SHREDSTREAM_PORT", 8001))
listener = ShredListener.bind(PORT)

# Decoded transactions — ready-to-use Solana transactions
for slot, txs in listener:
    for raw in txs:
        tx = VersionedTransaction.from_bytes(raw)
        print(f"slot {slot}: {tx.signatures[0]}")

Each raw is the bincode wire-format encoding of a VersionedTransaction.

Run it:

python3 main.py

📖 API Reference

ShredListener

  • ShredListener.bind(port: int) -> ShredListener — Bind with defaults (64 MB recv buf, 3 slot window, FEC enabled)
  • ShredListener.bind_with_options(port, options: ListenerOptions) -> ShredListener — Custom configuration
  • ShredListener.offline() -> ShredListener — Bind on ephemeral port; drive via handle_packet
  • ShredListener.from_fd(fd: int, options=None) -> ShredListener — Adopt an existing UDP file descriptor
  • Iterator protocolfor slot, txs in listener: yields (int, list[bytes])
  • listener.shreds() -> ShredIter — Iterator yielding RawShred headers (no decode)
  • listener.handle_packet(data: bytes) -> tuple[int, list[bytes]] | None — Inject an externally-received UDP datagram
  • listener.local_addr() -> str — Bound socket address
  • listener.close() — Release the socket

ListenerOptions

ListenerOptions(
    recv_buf=64*1024*1024,
    max_age=3,
    busy_poll_us=200,
    busy_poll_disabled=False,
    pool_size=4096,
    enable_fec=True,
    disable_salvage_delivery=False,
    accumulator=AccumulatorConfig(),
)
Field Default Description
recv_buf 64 MB SO_RCVBUF size
max_age 3 Slot retention window
busy_poll_us 200 Linux SO_BUSY_POLL µs
busy_poll_disabled False Pass True to disable busy poll explicitly
pool_size 4096 Number of 2 KiB buffers in the zero-copy pool
enable_fec True Reed-Solomon recovery on dropped data shreds
disable_salvage_delivery False Drop salvaged tail txs for lowest p99
accumulator AccumulatorConfig() FEC and stuck-batch tuning

AccumulatorConfig

Field Default Description
max_fec_sets_per_slot 32 Per-slot FEC buffer cap
stuck_batch_timeout_ms 50 Force-finalize a stuck batch after this delay

Metrics

Read-only @property accessors on ShredListener:

Group Methods
Throughput data_shred_count_total, code_shred_count_total, bytes_received, slot_count
Decoder batches_decoded_streaming_total, batches_decoded_fallback_total, batches_skipped_total, decode_errors_total
FEC fec_recoveries_total, fec_recovery_failures_total, fec_sets_discarded_unused_total, fec_sets_evicted_early_total
Unparseable unparseable_packets, unparseable_too_short, unparseable_variant, unparseable_payload, unparseable_slot_range
Slot lifecycle slots_completed_total, slots_evicted_by_age, dropped_known_slots, harvested_batches_total, salvaged_tail_tx_total
Tail control batches_force_finalized_corrupted_total, batches_force_finalized_timeout_total
Pool / I-O pool_exhausted_count, last_io_error_kind, busy_poll_active

Helpers

  • shredstream.classify_variant(byte: int) -> VariantKind | None — Classify a shred variant byte
  • shredstream.pin_current_thread_to_cpu(cpu_id: int) -> None — Best-effort thread pinning. Linux: sched_setaffinity; macOS: hint; other: no-op

🎯 Use Cases

ShredStream.com shred data powers a wide range of latency-sensitive strategies — HFT, MEV extraction, token sniping, copy trading, liquidation bots, on-chain analytics, and more.

💎 PumpFun Token Sniping

ShredStream.com SDK detects PumpFun token creations ~499ms before they appear on PumpFun's live feed — tested across 25 consecutive detections:

ShredStream.com SDK vs PumpFun live feed — ~499ms advantage

Ready-to-run example included: see examples/pumpfun_creates.py. Run with python3 examples/pumpfun_creates.py [port].

⚙️ Configuration

OS Tuning

# Linux -- increase max receive buffer
sudo sysctl -w net.core.rmem_max=67108864
sudo sysctl -w net.core.busy_read=200

# macOS
sudo sysctl -w kern.ipc.maxsockbuf=67108864

Dependencies

  • solders>=0.21 — Required to decode the bincode-encoded transactions yielded by the iterator.

🚀 Launch a Shred Stream

Need a feed? Launch a Solana Shred Stream on ShredStream.com — sub-millisecond delivery, multiple global regions, 5-minute setup.

🔗 Links

📄 License

MIT — ShredStream.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shredstream-2.0.0.tar.gz (36.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

shredstream-2.0.0-cp38-abi3-win_amd64.whl (437.4 kB view details)

Uploaded CPython 3.8+Windows x86-64

shredstream-2.0.0-cp38-abi3-manylinux_2_28_x86_64.whl (523.5 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ x86-64

shredstream-2.0.0-cp38-abi3-manylinux_2_28_aarch64.whl (500.1 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ ARM64

shredstream-2.0.0-cp38-abi3-macosx_11_0_arm64.whl (500.8 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file shredstream-2.0.0.tar.gz.

File metadata

  • Download URL: shredstream-2.0.0.tar.gz
  • Upload date:
  • Size: 36.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for shredstream-2.0.0.tar.gz
Algorithm Hash digest
SHA256 850deb1f94db5b616f9f0d588c3ab5d0274ab12daa627845b632d9b1408cc939
MD5 4052782bc13c8913a61721ab0b674f9d
BLAKE2b-256 85f122e9a53ad47330c117293c7a8fc7550415719c01d15b2b7feff497ff4cfe

See more details on using hashes here.

File details

Details for the file shredstream-2.0.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for shredstream-2.0.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e4d172bbb5bb6e2ba3bf117c634697c9ff8c65647e22744669a78f651eb346e3
MD5 4e687a164f74b45da1ec7e21ef319ba0
BLAKE2b-256 2650b9950764e30a6c70d9ee153b87e4c558a06a235bab7919c4eca0a1a5abad

See more details on using hashes here.

File details

Details for the file shredstream-2.0.0-cp38-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for shredstream-2.0.0-cp38-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d600b1afe0d9f16a044a4b736c842965271d9ccec70670494b0f382c7452693a
MD5 94750e72e06bb9802af0787971a45bad
BLAKE2b-256 e7cb2ef7366d103a91ebb574ba8c08092bcca0b3e59ff59d17d99d7b3491a62a

See more details on using hashes here.

File details

Details for the file shredstream-2.0.0-cp38-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for shredstream-2.0.0-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 350319d0b06dc82292126f91c398e4685df6ba1f376cdc2d6787a25b0c3dbfcc
MD5 4fe6567e882b35977d37d3b53137941c
BLAKE2b-256 659dbf5faf767f7ada2744a2b79f941108753a31675a5b1d819935b765fc6215

See more details on using hashes here.

File details

Details for the file shredstream-2.0.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for shredstream-2.0.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a1ba6d5d873432178f6e71c2aaf0978d5f378d7bcc70e9e283643502e38a88c
MD5 9d37320b80a6239222d7ab322f0b3224
BLAKE2b-256 4578e1bb7e1765b3995e0580e499a052bc79906b5618dd1bcdcd4a784f6c8b2d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page