Skip to main content

Lightweight Python library for reading Uniswap V3 prices and tick data via Web3.

Project description

uniswap-viewer

A lightweight Python library for accessing Uniswap V3 on-chain data.

uniswap-viewer provides a clean and efficient interface for reading price and tick information directly from Uniswap V3 smart contracts using web3.py. It supports both synchronous and asynchronous workflows and is ideal for developers, analysts, and algorithmic traders.

Features

  • Supports both sync and async Web3 clients
  • Fetches token prices using sqrtPriceX96 and token decimals
  • Retrieves detailed tick data via ABI-decoded contract calls
  • Computes tick index, tick spacing, and tick slot
  • Includes block streaming generator to track new blocks in real time
  • Built-in utilities for loading ABIs and checking Ethereum addresses

Modules

  • viewer_sync.py – synchronous Uniswap V3 viewer using web3.Web3
  • viewer_async.py – asynchronous Uniswap V3 viewer using web3.AsyncWeb3
  • utils.py – helper functions (ABI loading, tick keys, address filters)

Usage

Sync example

from uniswap_viewer import ViewerSync
from web3 import Web3

w3 = Web3(Web3.HTTPProvider("<your_provider_url>"))

viewer = ViewerSync(w3, "usdt", "weth", fee=3000)
viewer.init()

price = viewer.get_price()

tick = viewer.calc_tick(price, normalize=True)
tick_data = viewer.get_tick_data(tick)
liquidity = tick_data['liquidityGross']

Async example

from uniswap_viewer import ViewerAsync
from web3 import AsyncWeb3

w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider("<your_provider_url>"))

viewer = ViewerAsync(w3, "usdt", "weth", fee=3000)
await viewer.init()

price = await viewer.get_price()

tick = viewer.calc_tick(price, normalize=True)
tick_data = await viewer.get_tick_data(tick)
liquidity = tick_data['liquidityGross']

Stream example

from uniswap_viewer.viewer_async import Viewer as ViewerAsync, stream_new_blocks
from web3 import AsyncWeb3

w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider("<your_provider_url>"))

viewer = ViewerAsync(w3, "usdt", "weth", fee=3000)
await viewer.init()

async for block_num in stream_new_blocks(w3, timeout=3):
    price = await viewer.get_price(block_num=block_num)

    tick = viewer.calc_tick(price, normalize=True)
    tick_data = await viewer.get_tick_data(tick, block_num=block_num)
    liquidity = tick_data['liquidityGross']

    print(price, liquidity)

Requirements

  • Python 3.8+
  • web3 library (sync or async)

Motivation

This library is designed for:

  • Developers integrating Uniswap data directly from the blockchain
  • Quants and analysts building custom tooling
  • Avoiding reliance on third-party APIs like The Graph

License

MIT

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

uniswap_viewer-0.1.9.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

uniswap_viewer-0.1.9-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file uniswap_viewer-0.1.9.tar.gz.

File metadata

  • Download URL: uniswap_viewer-0.1.9.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uniswap_viewer-0.1.9.tar.gz
Algorithm Hash digest
SHA256 c98afcc188a9ce8b4b6afc3b03a81b2f6125c59d265e3d2e3c5c2c062d4c6967
MD5 bdb507cdd6cca87ecda564ca63047209
BLAKE2b-256 5ea17a288b03478131fac776780501ea95e837efe1cf3843f22c26a233bb47c0

See more details on using hashes here.

File details

Details for the file uniswap_viewer-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: uniswap_viewer-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for uniswap_viewer-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 28bef568c7fec8d9ddf30ed8b3e3d66b5e704c59283fbcf13550d6cbd04db0a6
MD5 14a36bbe4780119dc60d64c5fa2d6b05
BLAKE2b-256 5c17ed05b5522bdd4ceb6fd7ba7ef854d31c1ee564184a5019959f1de5bf8d48

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