Python wrapper around reth db. Written in Rust.

Overview

reth-db-py

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

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.

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 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 a TableName and a key and returns the value associated with that key in the table
  • list - takes a TableName, skip, length, and a reverse 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 number
  • Headers - contains the header for each block hash
  • Transactions - contains the transaction for each transaction hash
  • TxHashNumber - contains the block number for each transaction hash

Benchmarks

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

You might also like...
Fastest GTF/GFF-to-BED converter chilling around
Fastest GTF/GFF-to-BED converter chilling around

gxf2bed The fastest G{F,T}F-to-BED converter around the block! translates chr27 gxf2bed gene 17266470 17285418 . + . gene_id "ENSG00000151743"; chr27

A fully extensible command interface to navigate around your leptos application.

leptos-kbar A fully extensible command interface to navigate around your leptos application. See demo: https://leptos-kbar.vercel.app/ Roadmap leptos-

Simple OpenAI CLI wrapper written in Rust, feat. configurable prompts and models

Quick Start git clone https://github.com/ryantinder/ask-rs cd ask cargo install --path . Example ask tell me about the Lockheed Martin SR71 The Loc

Fast DNA manipulation for Python, written in Rust.

quickdna Quickdna is a simple, fast library for working with DNA sequences. It is up to 100x faster than Biopython for some translation tasks, in part

This is a simple command line application to convert bibtex to json written in Rust and Python

bibtex-to-json This is a simple command line application to convert bibtex to json written in Rust and Python. Why? To enable you to convert very big

Fuzzy Index for Python, written in Rust. Works like error-tolerant dict, keyed by a human input.

FuzzDex FuzzDex is a fast Python library, written in Rust. It implements an in-memory fuzzy index that works like an error-tolerant dictionary keyed b

📦 A Python package manager written in Rust inspired by Cargo.
📦 A Python package manager written in Rust inspired by Cargo.

huak About A Python package manager written in Rust. The Cargo for Python. ⚠️ Disclaimer: huak is currently in its proof-of-concept (PoC) phase. Huak

📦 A Python package manager written in Rust inspired by Cargo.
📦 A Python package manager written in Rust inspired by Cargo.

huak About A Python package manager written in Rust. The Cargo for Python. ⚠️ Disclaimer: huak is currently in its Alpha phase. Huak aims to support a

An extremely fast Python linter, written in Rust.
An extremely fast Python linter, written in Rust.

Ruff An extremely fast Python linter, written in Rust. Linting the CPython codebase from scratch. ⚡️ 10-100x faster than existing linters 🐍 Installab

Comments
Owner
gibz
Data engineer by day, crypto enthusiast by night.
gibz
Shared memory - A Rust wrapper around native shared memory for Linux and Windows

shared_memory A crate that allows you to share memory between processes. This crate provides lightweight wrappers around shared memory APIs in an OS a

elast0ny 274 Dec 29, 2022
A wrapper around the code action dump from https://mcdiamondfire.com.

DiamondFire Action Dump for Rust A wrapper around the code action dump from https://mcdiamondfire.com. This currently only provides schema types for u

null 3 Sep 17, 2022
Rust Imaging Library's Python binding: A performant and high-level image processing library for Python written in Rust

ril-py Rust Imaging Library for Python: Python bindings for ril, a performant and high-level image processing library written in Rust. What's this? Th

Cryptex 13 Dec 6, 2022
Python wrapper for Rust's httparse HTTP parser

httparse Python wrapper for Rust's httparse. See this project on GitHub. Example from httparse import RequestParser parser = RequestParser() buff =

Adrian Garcia Badaracco 41 Dec 22, 2022
🐎 A fast implementation of the Aho-Corasick algorithm using the compact double-array data structure. (Python wrapper for daachorse)

python-daachorse daachorse is a fast implementation of the Aho-Corasick algorithm using the compact double-array data structure. This is a Python wrap

Koichi Akabe 11 Nov 30, 2022
Rust library for regular expressions using "fancy" features like look-around and backreferences

fancy-regex A Rust library for compiling and matching regular expressions. It uses a hybrid regex implementation designed to support a relatively rich

fancy-regex 302 Jan 3, 2023
Pet project to get acquainted with Rust, and mess around with symbolic expressions.

Symba Pet project to get acquainted with Rust, and to mess around with symbolic expressions, hence the name 'Symba'. Example: use asg::{deftree, r

Ranjeeth Mahankali 3 Nov 23, 2023
Navigating around TUM with excellence – An API and website to search for rooms, buildings and other places

NavigaTUM NavigaTUM is a non-official tool developed by students for students, that aims to help you get around at TUM. Feel free to contribute. Featu

TUM Developers 21 Dec 22, 2022
it aims to augment git with primitives to build integrated, cryptographically verifiable collaboration workflows around source code

it aims to augment git with primitives to build integrated, cryptographically verifiable collaboration workflows around source code. It maintains the distributed property of git, not requiring a central server. it is transport agnostic, and permits data dissemination in client-server, federated, as well as peer-to-peer network topologies.

Kim Altintop 4 Jan 16, 2023
R warpper around `toml_edit` crate

tomleditR The goal of tomleditR is to expose the toml_edit crate to R. Installation You can install the development version of tomleditR from GitHub w

Extendr 3 Jul 6, 2023