> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cow.bleu.builders/llms.txt
> Use this file to discover all available pages before exploring further.

# CoW Protocol Python SDK

> Python SDK for interacting with CoW Swap and CoW Protocol, featuring MEV-protected trading, order management, and multi-chain support.

Build DeFi applications with MEV-protected trading on CoW Swap.

<CardGroup cols={2}>
  <Card title="Get Started" icon="rocket" href="/cow-py/quickstart">
    Execute your first token swap in minutes
  </Card>

  <Card title="View on GitHub" icon="github" href="https://github.com/cowdao-grants/cow-py">
    Browse the source code
  </Card>
</CardGroup>

## 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

<CardGroup cols={2}>
  <Card title="MEV-Protected Trading" icon="shield-check">
    Execute trades with built-in protection against front-running and sandwich attacks
  </Card>

  <Card title="Multi-Chain Support" icon="link">
    Trade on Ethereum, Gnosis Chain, Arbitrum, Base, Polygon, Avalanche, and BNB
  </Card>

  <Card title="Order Management" icon="list-check">
    Create, fetch, and cancel orders with full Python type hints
  </Card>

  <Card title="Subgraph Querying" icon="chart-line">
    Access trading data and analytics via GraphQL queries
  </Card>

  <Card title="Smart Contract Integration" icon="file-contract">
    Interact with CoW Protocol smart contracts using Web3.py
  </Card>

  <Card title="Advanced Orders" icon="puzzle-piece">
    Build composable programmatic orders and TWAP strategies
  </Card>
</CardGroup>

## 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

```python theme={null}
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?

<CardGroup cols={2}>
  <Card title="Type-Safe Development" icon="shield">
    Full Python type hints and Pydantic models throughout the SDK ensure compile-time safety and excellent IDE support.
  </Card>

  <Card title="Async/Await Support" icon="bolt">
    Native asyncio support for building high-performance applications that can handle multiple concurrent operations.
  </Card>

  <Card title="Web3.py Integration" icon="plug">
    Seamless integration with Web3.py for Ethereum and other EVM-compatible chains.
  </Card>

  <Card title="Gasless Trading" icon="gas-pump">
    Pay transaction fees in sell tokens instead of ETH, making trading more accessible.
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Installation" icon="download" href="/cow-py/installation">
    Install the SDK via pip and set up your environment
  </Card>

  <Card title="Quickstart" icon="play" href="/cow-py/quickstart">
    Execute your first token swap in minutes
  </Card>

  <Card title="Core Concepts" icon="book" href="/cow-py/concepts/chains">
    Learn about chains, orders, and trading mechanics
  </Card>

  <Card title="API Reference" icon="code" href="/cow-py/api/swap">
    Explore the complete API documentation
  </Card>
</CardGroup>

## Community & Support

* **GitHub Repository**: [cowdao-grants/cow-py](https://github.com/cowdao-grants/cow-py)
* **CoW Protocol Docs**: [docs.cow.fi](https://docs.cow.fi)
* **Discord**: [Join the community](https://discord.com/invite/cowprotocol)
* **Twitter**: [@CoWSwap](https://twitter.com/CoWSwap)

<Note>
  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.
</Note>
