Skip to main content

Tutorial overview

Create a local DuckDB analytics database from DEX pools and OHLCV for instant SQL over on‑chain data.

The local powerhouse: A core pattern for on-chain analysis

Why make thousands of slow, rate-limited API calls when you can run complex SQL queries instantly on your own machine? This tutorial introduces the most effective pattern for crypto data analysis: creating a local, high-performance copy of a complete on-chain dataset. By fetching the data once, you unlock unlimited, high-speed analytical capabilities.
Looking for other analytics solutions? Check out our full list of API Tutorials for more step-by-step guides.
The free tier gives you the full endpoint surface and the full history, not a cut-down dataset. What it caps is throughput (50,000 credits a month keyless, 300,000 with a free key, at 30 requests a minute) and freshness (data is served with a delay of up to 15 seconds; Pro is real time). Pulling once into DuckDB and querying locally is a good fit for that shape. The goal: By the end of this guide, you will have a local uniswap_v3.db file containing all pools and their recent trading history from Uniswap v3 on Ethereum. You will be able to:
  1. Run a robust, high-performance ETL script that pulls a complete dataset from the DexPaprika API.
  2. Perform complex SQL queries against your local copy, where no API limit applies.
  3. Understand a professional workflow for acquiring and analyzing on-chain data.
Why this is a foundational skill:
  • Eliminates Rate Limiting: Instead of thousands of small, repetitive API calls, you perform one efficient batch download.
  • Unlocks True Analytical Power: Run complex joins, aggregations, and window functions that are impossible with a simple API.
  • Creates a Foundation: The skills you learn here can be applied to any data source, preparing you for more advanced, real-time analysis.

Step 1: ETL pipeline

Create a Python script to fetch complete Uniswap v3 pool and OHLCV data.

Step 2: Instant SQL analysis

Populate your database and run complex SQL queries to find insights.

Step 3: AI-powered analysis with an MCP server

Connect your database to an AI assistant for natural language queries.

FAQs

It’s an embedded analytics database: zero server setup, a very fast columnar engine, and a good fit for local SQL over large datasets.
Depends on pools and history length; tens of millions of rows are feasible on a laptop with DuckDB’s compression.
Append new OHLCV daily or hourly depending on your use case; the pipeline is designed for incremental runs.
Yes. Create separate tables per network/DEX and union them, or annotate rows with network/dex columns.

Step 1: Build your local data pipeline

First, let’s create a Python script to act as our ETL (Extract, Transform, Load) pipeline. This script will fetch all pool data for Uniswap v3 on Ethereum and their recent trading history, then load it into a local DuckDB database file. It leverages two key endpoints: the Top Pools on a DEX endpoint to discover pools, and the Pool OHLCV Data endpoint to fetch historical price data. Create a new file named build_uniswap_db.py.
build_uniswap_db.py
A simple, sequential script is great for learning, but real-world data fetching requires a more robust approach. Here is what we’ve used to make sure it runs reliably:
  • Asynchronous Operations: By using asyncio and aiohttp, the script can make many API requests concurrently instead of one by one. This means shorter time for completion.
  • Dynamic Windowing: The get_pool_ohlcv function calculates how much data to request per API call so that it gets all the data for each pool.
  • Concurrency Control & Throttling: An asyncio.Semaphore, combined with carefully tuned BATCH_SIZE and asyncio.sleep() calls, makes sure we don’t hit the rate limit.
  • Resiliency: The fetch_with_retry function automatically retries failed requests with an exponential backoff delay, making the pipeline resilient to temporary network issues.

Required libraries

Before running the script, make sure you have the necessary Python libraries installed.

Step 2: Run the pipeline and query with SQL

Now, execute the script from your terminal. It will fetch all Uniswap v3 pool data from Ethereum and their recent trading history, then create a uniswap_v3.db file in a new dbs directory. This may take several minutes, but it will be significantly faster than a purely sequential script.

Querying your new database

Once the script completes, you have a powerful local database at your fingertips. You can now use any SQL client that supports DuckDB, or Python itself, to perform instant, complex analysis. In step 3, we will connect the database to an AI assistant for natural language queries. If you want to query the database with a Python script, create a new file named query_duckdb.py and paste the following code into it.
query_duckdb.py
Now, execute the script from your terminal:

Step 3: AI-powered analysis with an MCP server

While you can use any SQL client to query your database, the real power comes from connecting it to an AI assistant. By using a Model Context Protocol (MCP) server, you can enable your assistant to directly query the uniswap_v3.db file you created. This allows you to ask for insights in plain English instead of writing SQL. For this, we will use mcp-server-duckdb, an open-source MCP server for DuckDB.

Install the DuckDB MCP server

You can install the server easily using npx:

Configure your AI assistant

Next, you need to tell your AI assistant how to run the server. Add the following to your claude_desktop_config.json file.
If you see a “Server disconnected” error after restarting your AI assistant, it means the application cannot find the uvx or npx command. This happens because the application doesn’t share the same PATH environment variable as your terminal.To fix this, you must use the full, absolute path to the command.
  1. Find the absolute path by running which uvx or which npx in your terminal.
  2. Copy the output (e.g., /Users/yourname/.local/bin/uvx or /opt/homebrew/bin/npx).
  3. Use that full path as the command value in the JSON configuration below.
The example below uses uvx, which is recommended. Make sure to replace </path/to/your/project> with the actual absolute path to your project directory.
Now, when you start your AI assistant, it will have the tools to query your local Uniswap V3 database. You can ask it things like:
  • “Using the duckdb-crypto tool, find the 5 pools with the highest 24-hour volume.”
  • “What was the hourly volatility for the top pool yesterday?”

What you’ve built: From API calls to analytics powerhouse

By completing this tutorial, you have successfully transitioned from being a passive data consumer to an active data analyst. You’ve replaced the slow, restrictive pattern of making individual API calls with a fast, powerful, and scalable local analytics workflow. Key achievements:
  • Built a professional ETL pipeline: You have a reusable, high-performance Python script that can create a comprehensive local database from any supported DEX and network.
  • Unlocked high-speed SQL: You can now perform complex analytical queries on a rich dataset in milliseconds, directly on your machine.
  • Mastered a foundational workflow: This “local-first” data strategy is a cornerstone of professional data analysis. It enables deeper exploration, from high-level market trends down to individual wallet behaviors.
  • Created a Reusable Asset: Your uniswap_v3.db file is a valuable, reusable asset for any future analysis, dashboarding, or AI integration project.
When your project grows and you need to explore other data solutions, check out our full list of API Tutorials for more advanced guides.