Skip to main content

High-performance Web3 client with batching and latency optimization.

Project description

fastweb3

High-performance Web3 client.

NOTE: This library is still in early alpha development. Prior to a v1.0.0 (which may never come), expect breaking changes and no backward compatibility between versions.

Installation

You can install the latest release via pip:

pip install fastweb3

Or clone the repository for the most up-to-date version:

git clone https://github.com/iamdefinitelyahuman/fastweb3.git
cd fastweb3
pip install -e .

Features

Automatic public RPC discovery and pooling

fastweb3 queries a list of public RPC endpoints, maintains a pool of useable nodes, distributes requests between them, and reroutes failed requests. Users can rely on public infrastructure without thinking about timeouts, rate limiting, nodes falling out of sync, etc.

>>> from fw3 import Web3

# only a chainId is needed to connect
>>> w3 = Web3(1)

# the object immediately begins querying endpoints to check availability and latency
# the best nodes are selected to be used in an "active pool"
>>> w3.active_pool_size()
6

# we continue to monitor all known good endpoints, in case we have issues with any
# member of the active pool
>>> w3.pool_capacity()
11

Users with their own RPC can target it as their primary endpoint. This endpoint is then favored for write methods, but read methods continue to be distributed amongst the node pool.

>>> w3 = Web3(1, primary_endpoint=["my.local.node"])

Deferred Execution

RPC calls return Proxy objects immediately, while network I/O happens in the background.

>>> amount = w3.eth.get_balance('0xd8da6bf26964af9d7eed9e03e53415d37aa96045')
>>> amount
<Proxy at 0x7b9ac0764a40 of object ... >
>>> print(amount)
32131215082101779377

Simple Batching Semantics

Batching uses natural syntax. With a context manager open, each requests is queued in the same batch until one of the Proxy objects is read, at which point the entire request is processed. This also guarantees queried values are all read from the same block.

>>> with w3.batch_requests():
...     a = w3.eth.get_balance("0xd8da6bf26964af9d7eed9e03e53415d37aa96045")
...     b = w3.eth.get_balance("0x1db3439a222c519ab44bb1144fc28167b4fa6ee6")
...     # both eth_getBalance queries are sent in the same batched request
...     print(a + b)
...
32840401623804415458

Tests

First, install the dev dependencies:

pip install -e ".[dev]"

To run the test suite:

pytest

License

This project is licensed under the MIT license.

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

fastweb3-0.1.1.tar.gz (47.7 kB view details)

Uploaded Source

Built Distribution

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

fastweb3-0.1.1-py3-none-any.whl (57.3 kB view details)

Uploaded Python 3

File details

Details for the file fastweb3-0.1.1.tar.gz.

File metadata

  • Download URL: fastweb3-0.1.1.tar.gz
  • Upload date:
  • Size: 47.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for fastweb3-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a8b8aeca4e3f3b50c32ce6c36dffdb2e1c2695931be6b46d46fe28d43c3cc937
MD5 a40b12ad69c917d20041898ccddb2c06
BLAKE2b-256 6e277054607a56fcac1bdca2171ee023026f09e022a0cb14c7c31d39025eaac7

See more details on using hashes here.

File details

Details for the file fastweb3-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastweb3-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 57.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for fastweb3-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0770971d5cf979dcc6b851e96cfa3d7244cda28e11abf2a816d2612553990b8a
MD5 02d08932e742537095d7147ba2319428
BLAKE2b-256 a745f327edc6863da7a4618b9a776c3167bc5929cfb2d2030639aaf4afa5e938

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