Uniswap Python

The unofficial, highly-capable Python client for Uniswap.

uniswap-python provides a clean, Pythonic interface to interact directly with Uniswap's decentralized exchange protocols. Interacting with Ethereum smart contracts typically requires managing Application Binary Interfaces (ABIs), handling complex byte encoding, computing optimal tick ranges, and manually constructing transaction objects. This library abstracts away these complexities, allowing developers, quants, and data scientists to focus on their core logic: quoting prices, executing trades, and managing liquidity.

Why Use uniswap-python?

  • Multi-Version Protocol Support: Seamlessly interact with Uniswap V1 (legacy), V2, and V3 using a single, unified client interface.
  • Cross-Chain Compatibility: Built-in support and routing for Ethereum Mainnet, testnets (Goerli, Sepolia), and Layer-2 scaling solutions including Arbitrum, Optimism, Polygon, and Fantom.
  • Smart Routing & Pricing: Easy-to-use wrappers for quoting prices (get_price_input, get_price_output) and executing trades (make_trade, make_trade_output) that handle intermediary routing (e.g., bridging through WETH).
  • Concentrated Liquidity Management: Advanced V3 features for calculating Total Value Locked (TVL), minting NFT liquidity positions, and closing positions.
  • Automatic Allowances: The library automatically manages ERC20 token allowances, removing the boilerplate of sending approve transactions before trading.
  • Extensible & Flexible: Use any arbitrary ERC20 token by simply providing its contract address. Swap factory and router addresses to interact with forks like Sushiswap or Pancakeswap.
  • CLI Tool Included: Comes with unipy, a robust command-line interface for rapidly querying market prices and token metadata without writing a script.

Architecture Overview

Under the hood, uniswap-python leverages Web3.py to communicate with Ethereum nodes. It bundles the official Uniswap ABIs and contract addresses, dynamically loading the appropriate interfaces based on the version and network you specify.

When you request a price quote, the library queries the read-only functions of the Uniswap Router or Quoter contracts. When you execute a trade, the library constructs the transaction parameters, signs it locally using your provided private key, and broadcasts the raw transaction to the network.

Next Steps

Ready to start integrating Uniswap into your Python applications?

  1. Head over to the Installation guide to set up your environment.
  2. Follow the Getting Started tutorial for your first trade.
  3. Explore the Usage Guide for deep dives into pricing, trading, and liquidity.