Python wrapper around reth db. Written in Rust.
Project description
reth-db-py
Bare-bones Python package allowing you to interact with the Reth DB via Python. Rust and Pyo3 are used behind the scenes.
This python wrapper can access node data 2x-4x faster than local RPC calls. Using this package, the most recent block hash can be retrieved in ~300μs on a local reth DB.
Installation
This package has been published to PyPi and can be installed using pip:
pip install reth-db-py
Assets
This package only has two assets made available: DbHandler
and TableName
.
TableName
is an enum that contains the names of the supported tables in the Reth DB. This is used to ensure that the table name you are trying to access is valid.
pub enum TableName {
CanonicalHeaders,
Headers,
Transactions,
TxHashNumber,
}
DbHandler
is a struct/class used to interact with the Reth DB. It has two methods, get
and list
:
get
- takes aTableName
and akey
and returns the value associated with that key in the tablelist
- takes aTableName
, skip, length, and areverse
boolean and returns a list of keys and values from the table
impl DbHandler {
pub fn new(db_path: String) -> Self {}
pub fn list(&self, table_name: TableName, skip: usize, len: usize, reverse: bool) -> PyResult<Vec<(String, String)>> {}
pub fn get(&self, table_name: TableName, key: String) -> PyResult<String> {}
}
class DbHandler:
def __init__(self, db_path: str)
def list(self, table_name: TableName, skip: int, len: int, reverse: bool)
def get(self, table_name: TableName, key: str)
Usage
Import reth-db-py assets:
from reth_db_py import DbHandler, TableName
Create a DbHandler instance:
handler = DbHandler("/path/to/db/mdbx.dat")
Get a single block hash from the CanonicalHeaders
table:
header_hash = handler.get(TableName.CanonicalHeaders, '17000000')
Get 5 most recent block hashes from the CanonicalHeaders
table:
header_list = handler.list(TableName.CanonicalHeaders, 0, 5, True)
Table Docs
Goal is to support all tables in Reth (currently only support 4 tables related to headers and transactions). Reth is still in alpha and the database tables are subject to change. Docs on the tables can be found in the reth repo here.
CanonicalHeaders
- contains the block hash for each block numberHeaders
- contains the header for each block hashTransactions
- contains the transaction for each transaction hashTxHashNumber
- contains the block number for each transaction hash
Benchmarks
Speed tests between RPC calls vs. reth-db-py calls (direct db interaction) coming soon.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for reth_db_py-0.0.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8565b1cd1ee298f0001b63f2f9ecb9c8b8019a89203dbfbd3acee36fd62f3e7 |
|
MD5 | baf6be6f4b92935956c8b868be19d8cc |
|
BLAKE2b-256 | 57ab5559e6327e12b9c4f4e8b4554cc754d56ce5ec3d469e9045ea00e134019c |