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.0.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.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quercle_pydantic_ai-1.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 d859870d7854cf2a5a3f3fe3d1ab9793dc6f427fd63ceea8aa447be8a2af1530
MD5 56e5f7e6f490187c4d69b006cf0fe310
BLAKE2b-256 86aabbc5707c78cb3a8df70008bf78dbe202a9989c01fd355417395af91c58fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for quercle_pydantic_ai-1.0.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quercle_pydantic_ai-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63d69ed114380e600979435e4bfabc0685df927f8bf05b0778427abcc1d9c56e
MD5 ab5c6a09c98300efd5068ffe7363fde8
BLAKE2b-256 d0deb9437d93c208c4ba6f93042c17bf977cd251ae68b78048ead64a6f479de9

See more details on using hashes here.

Provenance

The following attestation bundles were made for quercle_pydantic_ai-1.0.0-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