Skip to main content

Python wrapper around reth db. Written in Rust.

Project description

reth-db-py

Python package allowing you to interact with the Reth DB via Python. Written with Rust and Pyo3.

This python wrapper can access node data 15x-30x faster than local RPC calls. Using this package, the most recent block hash can be retrieved in ~100μs on a local reth DB.

Test Suite Py Versions Test OS

Installation

This package has been published to PyPi and can be installed using pip:

pip install reth-db-py

Assets

This package only has a single python class made available: PyDatabaseHandler.

PyDatabaseHandler is a class used to interact with the Reth DB. It's a wrapper around the Rust DatabaseHandler struct. It has a few methods which all return json strings:

  • get_header_by_block_number: get a single header by block number
  • get_headers_by_block_number_range: get multiple headers by block number range
  • get_transaction_by_id: get a single transaction by transaction id
  • get_transactions_by_id_range: get multiple transactions by transaction id range
  • get_transactions_by_block_number_range: get multiple transactions by block number range
  • get_block_by_number: get a single block by block number
  • get_uncles_by_block_number: get uncles by block number
  • get_receipts_by_transaction_id: get receipts by transaction id
  • get_receipts_by_block_number: get receipts by block number
impl PyDatabaseHandler {
    pub fn get_header_by_block_number(&self, number: u64) -> PyResult<String>
    pub fn get_headers_by_block_number_range(&self, start: u64, end: u64) -> PyResult<String>
    pub fn get_transaction_by_id(&self, id: u64) -> PyResult<String>
    pub fn get_transactions_by_id_range(&self, start: u64, end: u64) -> PyResult<String>
    pub fn get_transactions_by_block_number_range(&self, start: u64, end: u64) -> PyResult<String>
    pub fn get_block_by_number(&self, number: u64) -> PyResult<String>
    pub fn get_uncles_by_block_number(&self, number: u64) -> PyResult<String>
    pub fn get_receipts_by_transaction_id(&self, id: u64) -> PyResult<String>
    pub fn get_receipts_by_block_number(&self, number: u64) -> PyResult<String>
}
class PyDatabaseHandler:
    def get_header_by_block_number(self, number: int) -> str
    def get_headers_by_block_number_range(self, start: int, end: int) -> str
    def get_transaction_by_id(self, id: int) -> str
    def get_transactions_by_id_range(self, start: int, end: int) -> str
    def get_transactions_by_block_number_range(self, start: int, end: int) -> str
    def get_block_by_number(self, number: int) -> str
    def get_uncles_by_block_number(self, number: int) -> str
    def get_receipts_by_transaction_id(self, id: int) -> str
    def get_receipts_by_block_number(self, number: int) -> str

Usage

Import reth-db-py assets:

from reth_db_py import PyDatabaseHandler

Create a PyDatabaseHandler instance:

handler = PyDatabaseHandler("/path/to/db/mdbx.dat")

Get the header by block number

header = handler.get_header_by_block_number(17_000_000)

Get the headers by block number range

headers = handler.get_headers_by_block_number_range(17_000_000, 17_000_005)

Get transaction by id

transaction = handler.get_transaction_by_id(1000)

Get transactions by id range

transactions = handler.get_transactions_by_id_range(1000, 1005)

Get transactions by block number range

transactions = handler.get_transactions_by_block_number_range(17_000_000, 17_000_005)

Get block by number

block = handler.get_block_by_number(17_000_000)

Get uncles by block number

uncles = handler.get_uncles_by_block_number(17_000_000)

Get receipts by transaction id

receipts = handler.get_receipts_by_transaction_id(1000)

Get receipts by block number

receipts = handler.get_receipts_by_block_number(17_000_000)

Tests

Coming soon.

Benchmarks

Speed tests between RPC calls vs. reth-db-py calls (direct db interaction) coming soon.

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

reth_db_py-0.1.4.tar.gz (28.3 kB view hashes)

Uploaded Source

Built Distributions

reth_db_py-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

reth_db_py-0.1.4-cp311-cp311-macosx_10_7_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

reth_db_py-0.1.4-cp310-cp310-manylinux_2_34_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

reth_db_py-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

reth_db_py-0.1.4-cp310-cp310-macosx_10_7_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

reth_db_py-0.1.4-cp39-cp39-manylinux_2_34_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.34+ x86-64

reth_db_py-0.1.4-cp39-cp39-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

reth_db_py-0.1.4-cp39-cp39-macosx_10_7_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

reth_db_py-0.1.4-cp38-cp38-manylinux_2_34_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.34+ x86-64

reth_db_py-0.1.4-cp38-cp38-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

reth_db_py-0.1.4-cp38-cp38-macosx_10_7_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

reth_db_py-0.1.4-cp37-cp37m-manylinux_2_34_x86_64.whl (2.1 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.34+ x86-64

reth_db_py-0.1.4-cp37-cp37m-macosx_11_0_arm64.whl (1.1 MB view hashes)

Uploaded CPython 3.7m macOS 11.0+ ARM64

reth_db_py-0.1.4-cp37-cp37m-macosx_10_7_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

Supported by

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