Skip to main content

Quercle web search and URL fetch tools for Pydantic AI agents

Project description

quercle-pydantic-ai

Quercle web search and fetch tools for Pydantic AI.

Installation

uv add quercle-pydantic-ai
# or
pip install quercle-pydantic-ai

Setup

Set your API key as an environment variable:

export QUERCLE_API_KEY=qk_...

Get your API key at quercle.dev.

Quick Start

from pydantic_ai import Agent
from quercle_pydantic_ai import quercle_tools

agent = Agent(
    "openai:gpt-4o",
    tools=quercle_tools(),
    system_prompt="You are a helpful research assistant.",
)

result = agent.run_sync("Search for the latest news about AI agents")
print(result.output)

quercle_tools() returns all 5 tools: search, fetch, raw search, raw fetch, and extract.

Direct Tool Usage

The tools are async (Pydantic AI tools are async by design). For direct usage, use the underlying SDK client:

import asyncio
from quercle import AsyncQuercleClient

async def main():
    client = AsyncQuercleClient()

    # Search
    result = await client.search("best practices for building AI agents")
    print(result.result)

    # Search with domain filtering
    result = await client.search(
        "Python documentation",
        allowed_domains=["docs.python.org"],
    )
    print(result.result)

    # Fetch and analyze a page
    result = await client.fetch(
        "https://en.wikipedia.org/wiki/TypeScript",
        "Summarize the key features of TypeScript",
    )
    print(result.result)

asyncio.run(main())

Custom API Key

tools = quercle_tools(api_key="qk_...")

Agentic Usage

Research Agent

from pydantic_ai import Agent
from quercle_pydantic_ai import quercle_tools

agent = Agent(
    "anthropic:claude-sonnet-4-20250514",
    tools=quercle_tools(),
    system_prompt="You are a research assistant. Search the web to find "
    "accurate, up-to-date information. Always cite your sources.",
)

result = agent.run_sync("What are the latest developments in WebAssembly?")
print(result.output)

Async Agent

import asyncio
from pydantic_ai import Agent
from quercle_pydantic_ai import quercle_tools

agent = Agent("openai:gpt-4o", tools=quercle_tools())

async def main():
    result = await agent.run("Search for trending AI papers this week")
    print(result.output)

asyncio.run(main())

Streaming

import asyncio
from pydantic_ai import Agent
from quercle_pydantic_ai import quercle_tools

agent = Agent("openai:gpt-4o", tools=quercle_tools())

async def main():
    async with agent.run_stream("Summarize the latest AI news") as response:
        async for text in response.stream_text():
            print(text, end="", flush=True)

asyncio.run(main())

Individual Tools

from quercle_pydantic_ai import (
    quercle_search_tool,
    quercle_fetch_tool,
    quercle_raw_search_tool,
    quercle_raw_fetch_tool,
    quercle_extract_tool,
)

# Use only search
agent = Agent("openai:gpt-4o", tools=[quercle_search_tool()])

# Use only fetch
agent = Agent("openai:gpt-4o", tools=[quercle_fetch_tool()])

# Combine specific tools
agent = Agent("openai:gpt-4o", tools=[
    quercle_search_tool(),
    quercle_raw_fetch_tool(),
    quercle_extract_tool(),
])

With QuercleToolset

from pydantic_ai import Agent
from quercle_pydantic_ai import QuercleToolset

# All 5 tools with domain filtering
toolset = QuercleToolset(
    search_allowed_domains=["docs.python.org", "realpython.com"],
)

# Selectively include tools
toolset = QuercleToolset(
    include_raw_fetch=False,
    include_raw_search=False,
    include_extract=False,
)

agent = Agent("openai:gpt-4o", toolsets=[toolset])

Configuration

Parameter Default Description
api_key QUERCLE_API_KEY env var Your Quercle API key
timeout None Request timeout in seconds
allowed_domains None Restrict search to these domains
blocked_domains None Exclude these domains from search

API Reference

Export Description
quercle_search_tool(...) AI-synthesized web search with citations
quercle_fetch_tool(...) Fetch a URL and analyze its content with AI
quercle_raw_search_tool(...) Raw web search results (markdown or JSON)
quercle_raw_fetch_tool(...) Raw URL content (markdown or HTML)
quercle_extract_tool(...) Extract content chunks relevant to a query from a URL
quercle_tools(...) Returns all 5 tools as a list
QuercleToolset(...) Composable FunctionToolset for use with toolsets=

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quercle_pydantic_ai-1.0.1.tar.gz (214.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quercle_pydantic_ai-1.0.1-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file quercle_pydantic_ai-1.0.1.tar.gz.

File metadata

  • Download URL: quercle_pydantic_ai-1.0.1.tar.gz
  • Upload date:
  • Size: 214.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quercle_pydantic_ai-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d6bc6675d5c86cbe0ab57581158ec04c05edc9831e301f90bf690714ed96a73a
MD5 136eea43bf58eb4189dca643e8cfa4ba
BLAKE2b-256 ed4ca16ec5839c100a359e22c5b33773fad52ebd7ff97c884678a5a571b0d3d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for quercle_pydantic_ai-1.0.1.tar.gz:

Publisher: publish.yml on quercledev/quercle-pydantic-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quercle_pydantic_ai-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for quercle_pydantic_ai-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bb47dca34e845d7570c88f3da8049a5abc5feaede27a72594c0daa593d943906
MD5 6d81f1783c94cfcdc0cc1d5c89b4e466
BLAKE2b-256 95804cf91eb248dcdc7d5649ecde1b86bcde7bcd85b3e5afae7fd8a45959a313

See more details on using hashes here.

Provenance

The following attestation bundles were made for quercle_pydantic_ai-1.0.1-py3-none-any.whl:

Publisher: publish.yml on quercledev/quercle-pydantic-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page