Skip to main content

Ethereum Hive Simulators Python Library

PyPI version Python versions License: GPL v3 uv

Write ethereum/hive simulators using Python.

This library provides a Python API for creating and running Ethereum Hive simulation tests, allowing you to test Ethereum clients against various scenarios and network conditions.

Installation

pip install ethereum-hive

Features

  • Client Management: Start, stop, and manage Ethereum clients.
  • Network Configuration: Configure custom networks and genesis configuration.
  • Test Simulation: Run comprehensive test suites against Ethereum clients.

Quick Start

Start a Hive Development Server

./hive --dev --client go-ethereum

Basic Example

Here's a basic example of how to use the Hive Python API with Hive running in developer mode. It requires a genesis file; please modify the path as required.

from pathlib import Path

from hive.simulation import Simulation
from hive.testing import HiveTestResult

# Create a simulation on a development hive server
simulator = Simulation(url="http://127.0.0.1:3000")

# Get information about the hive instance cli args and clients
hive_info = simulator.hive_instance()

# Start a test suite
suite = simulator.start_suite("my_test_suite", "my test suite description")

# Start a test
test = suite.start_test("my_test", "my test description")

# Start a client for the test
all_clients = simulator.client_types()
print(all_clients[0].version)

# Specify the genesis file; here we use the genesis from the unit test
files = {"genesis.json": Path("src/hive/tests/genesis.json").as_posix()}
env = {"HIVE_CHAIN_ID": "1"}
client = test.start_client(client_type=all_clients[0], environment=env, files=files)

# Run your test logic
# ...

# Stop the test and the suite (will clean-up clients)
test.end(result=HiveTestResult(test_pass=True, details="test details"))
suite.end()

For more detailed examples, check out the unit tests or explore the simulators in the execution-spec-tests repository.

Development

Setup

  1. Install uv:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. Clone and setup the project:

    git clone https://github.com/marioevz/hive.py.git
    cd hive.py
    uv sync --all-extras
    

Running Tests

Prerequisites

  1. Fetch and build hive:

    git clone https://github.com/ethereum/hive.git
    cd hive
    go build -v .
    
  2. Run hive in dev mode:

    ./hive --dev --client go-ethereum,lighthouse-bn,lighthouse-vc
    
  3. Run the test suite:

    uv run pytest
    

Code Quality

  • Linting: uv run black src/
  • Type checking: uv run mypy src/
  • Import sorting: uv run isort src/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Related Projects

Metadata

Release files for ethereum-hive 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ethereum-hive 0.1.0
File Size Uploaded
ethereum_hive-0.1.0.tar.gz 79.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ethereum-hive 0.1.0
File Interpreter ABI Platform
ethereum_hive-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 120.4 kB

Release files / ethereum_hive-0.1.0.tar.gz

Download URL ethereum_hive-0.1.0.tar.gz
Size 79.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7f047fc03f15fc43081432c4adca362e9dffd6bf2faad163f707c7221148d61b
BLAKE2b-256 checksum
How to use checksums
4d06583cb86c2fef9e0da8bb8d4165c9dde076a8c9e1f940327dbbb64bf68dfc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ethereum_hive-0.1.0-py3-none-any.whl

Download URL ethereum_hive-0.1.0-py3-none-any.whl
Size 41.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a511ef89bab8b4740ed501ce7c3d244085f687c5001d9fa1ecc2ab01ad14b51
BLAKE2b-256 checksum
How to use checksums
932f461e38bd697e90f6e7a2199193eedd3653e69ca331cc98431653b46ad156
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page