Skip to main content

Prerequisites

Setup

pip install fastapi uvicorn evocrawl-py
Add your API key to .env:
EVOCRAWL_API_KEY=fc-YOUR-API-KEY

Create the API

Create main.py:
import os
from fastapi import FastAPI
from pydantic import BaseModel
from evocrawl import Evocrawl

app = FastAPI()
evocrawl = Evocrawl(api_key=os.environ["EVOCRAWL_API_KEY"])


class SearchRequest(BaseModel):
    query: str
    limit: int = 5


class ScrapeRequest(BaseModel):
    url: str


class InteractRequest(BaseModel):
    scrape_id: str
    prompt: str


@app.post("/search")
async def search(req: SearchRequest):
    results = evocrawl.search(req.query, limit=req.limit)
    return [{"title": r.title, "url": r.url} for r in results.web]


@app.post("/scrape")
async def scrape(req: ScrapeRequest):
    result = evocrawl.scrape(req.url)
    return {"markdown": result.markdown, "metadata": result.metadata}


@app.post("/interact/start")
async def interact_start(req: ScrapeRequest):
    result = evocrawl.scrape(req.url, formats=["markdown"])
    return {"scrape_id": result.metadata.scrape_id}


@app.post("/interact")
async def interact(req: InteractRequest):
    response = evocrawl.interact(req.scrape_id, prompt=req.prompt)
    return {"output": response.output}


@app.post("/interact/stop")
async def interact_stop(req: InteractRequest):
    evocrawl.stop_interaction(req.scrape_id)
    return {"status": "stopped"}

Run it

uvicorn main:app --reload

Test it

# Search the web
curl -X POST http://localhost:8000/search \
  -H "Content-Type: application/json" \
  -d '{"query": "evocrawl web scraping", "limit": 5}'

# Scrape a page
curl -X POST http://localhost:8000/scrape \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'

# Start an interactive session, then send prompts
curl -X POST http://localhost:8000/interact/start \
  -H "Content-Type: application/json" \
  -d '{"url": "https://www.amazon.com"}'
FastAPI auto-generates interactive docs at http://localhost:8000/docs.

Async variant

For better concurrency under load, use AsyncEvocrawl:
from evocrawl import AsyncEvocrawl

async_evocrawl = AsyncEvocrawl(api_key=os.environ["EVOCRAWL_API_KEY"])

@app.post("/scrape-async")
async def scrape_async(req: ScrapeRequest):
    result = await async_evocrawl.scrape(req.url)
    return {"markdown": result.markdown}

Next steps

Scrape docs

All scrape options including formats, actions, and proxies

Search docs

Search the web and get full page content

Interact docs

Click, fill forms, and extract dynamic content

Python SDK reference

Full SDK reference with crawl, map, async, and more