Skip to main content
Build DeFi applications with MEV-protected trading on CoW Swap.

What is CoW Protocol?

CoW Protocol (Coincidence of Wants) powers CoW Swap, a decentralized exchange aggregator that protects traders from MEV (Maximal Extractable Value) through batch auctions and intent-based trading. The cowdao_cowpy Python SDK enables developers to programmatically interact with CoW Swap and the CoW Protocol ecosystem.

Key Features

MEV-Protected Trading

Execute trades with built-in protection against front-running and sandwich attacks

Multi-Chain Support

Trade on Ethereum, Gnosis Chain, Arbitrum, Base, Polygon, Avalanche, BNB, and Lens

Order Management

Create, fetch, and cancel orders with full Python type hints

Subgraph Querying

Access trading data and analytics via GraphQL queries

Smart Contract Integration

Interact with CoW Protocol smart contracts using Web3.py

Advanced Orders

Build composable programmatic orders and TWAP strategies

Use Cases

The CoW Protocol Python SDK is perfect for:
  • Trading Bots — Automate trading strategies with MEV protection
  • DeFi Applications — Integrate CoW Swap functionality into your projects
  • Data Analytics — Query trading volumes, order history, and market data
  • Solver Development — Build custom order matching solutions
  • Portfolio Management — Execute multi-token swaps across chains

Quick Example

import os
import asyncio
from web3 import Account, Web3
from web3.types import Wei
from cowdao_cowpy.cow.swap import swap_tokens
from cowdao_cowpy.common.chains import Chain

# Configuration
BUY_TOKEN = Web3.to_checksum_address("0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14")  # WETH
SELL_TOKEN = Web3.to_checksum_address("0xbe72E441BF55620febc26715db68d3494213D8Cb")  # USDC
SELL_AMOUNT = Wei(5000000000000000000)  # 50 USDC with 18 decimals

# Load account
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
account = Account.from_key(PRIVATE_KEY)

# Execute swap
asyncio.run(
    swap_tokens(
        amount=SELL_AMOUNT,
        account=account,
        chain=Chain.SEPOLIA,
        sell_token=SELL_TOKEN,
        buy_token=BUY_TOKEN,
    )
)

Why Choose CoW Protocol SDK?

Type-Safe Development

Full Python type hints and Pydantic models throughout the SDK ensure compile-time safety and excellent IDE support.

Async/Await Support

Native asyncio support for building high-performance applications that can handle multiple concurrent operations.

Web3.py Integration

Seamless integration with Web3.py for Ethereum and other EVM-compatible chains.

Gasless Trading

Pay transaction fees in sell tokens instead of ETH, making trading more accessible.

Next Steps

Community & Support

This SDK is community-maintained and not officially endorsed by CoW Protocol. For production use, thoroughly test your integration and understand the risks involved in DeFi trading.
Last modified on March 12, 2026