Skip to main content

Quercle web search and URL fetch tools for Pydantic AI agents

Project description

quercle-pydantic-ai

Quercle web search and URL fetch tools for Pydantic AI agents.

Installation

uv add quercle-pydantic-ai

Or with pip:

pip install quercle-pydantic-ai

Quick Start

from pydantic_ai import Agent
from quercle_pydantic_ai import quercle_tools

# Create an agent with Quercle tools
agent = Agent(
    'openai:gpt-4o',
    tools=quercle_tools(),
)

# Run the agent
result = agent.run_sync("Search for the latest Python 3.13 features")
print(result.data)

Configuration

API Key

Set your Quercle API key via environment variable:

export QUERCLE_API_KEY=qk_your_api_key

Or pass it directly:

from quercle_pydantic_ai import quercle_tools

tools = quercle_tools(api_key="qk_your_api_key")

Get your API key at quercle.dev.

Usage

Individual Tools

Use search or fetch tools separately:

from pydantic_ai import Agent
from quercle_pydantic_ai import quercle_search_tool, quercle_fetch_tool

# Search-only agent
search_agent = Agent(
    'openai:gpt-4o',
    tools=[quercle_search_tool()],
)

# Fetch-only agent
fetch_agent = Agent(
    'openai:gpt-4o',
    tools=[quercle_fetch_tool()],
)

Domain Filtering

Restrict search to specific domains:

from quercle_pydantic_ai import quercle_search_tool

# Only search official documentation sites
tool = quercle_search_tool(
    allowed_domains=["*.python.org", "docs.*.dev"],
)

# Exclude certain domains
tool = quercle_search_tool(
    blocked_domains=["reddit.com", "*.social"],
)

QuercleToolset

Use the toolset for composition with other Pydantic AI toolsets:

from pydantic_ai import Agent
from pydantic_ai.toolsets import CombinedToolset
from quercle_pydantic_ai import QuercleToolset

# Create a Quercle toolset
quercle = QuercleToolset(
    search_allowed_domains=["*.org", "*.edu"],
)

# Combine with other toolsets
combined = CombinedToolset([quercle, other_toolset])

agent = Agent('openai:gpt-4o', toolsets=[combined])

Configure which tools to include:

# Search only
toolset = QuercleToolset(include_fetch=False)

# Fetch only
toolset = QuercleToolset(include_search=False)

Examples

Research Agent

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 research assistant. Use web search to find
    accurate, up-to-date information. Always cite your sources.""",
)

result = agent.run_sync(
    "What are the key differences between Python 3.12 and 3.13?"
)
print(result.data)

Web Analyzer Agent

from pydantic_ai import Agent
from quercle_pydantic_ai import quercle_fetch_tool

agent = Agent(
    'openai:gpt-4o',
    tools=[quercle_fetch_tool()],
    system_prompt="""You analyze web pages and extract key information.
    When given a URL, fetch it and provide a structured summary.""",
)

result = agent.run_sync(
    "Analyze the documentation at https://ai.pydantic.dev/tools/"
)
print(result.data)

Async Usage

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 async Python best practices")
    print(result.data)

asyncio.run(main())

API Reference

Factory Functions

quercle_search_tool()

Creates a web search tool.

def quercle_search_tool(
    api_key: str | None = None,
    allowed_domains: list[str] | None = None,
    blocked_domains: list[str] | None = None,
    timeout: float | None = None,
) -> Tool[Any]

quercle_fetch_tool()

Creates a URL fetch tool.

def quercle_fetch_tool(
    api_key: str | None = None,
    timeout: float | None = None,
) -> Tool[Any]

quercle_tools()

Creates both search and fetch tools.

def quercle_tools(
    api_key: str | None = None,
    timeout: float | None = None,
) -> list[Tool[Any]]

QuercleToolset

A composable toolset for use with Pydantic AI's toolset system.

class QuercleToolset(FunctionToolset):
    def __init__(
        self,
        api_key: str | None = None,
        timeout: float | None = None,
        *,
        include_search: bool = True,
        include_fetch: bool = True,
        search_allowed_domains: list[str] | None = None,
        search_blocked_domains: list[str] | None = None,
    )

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-0.1.0.tar.gz (213.7 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-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: quercle_pydantic_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 213.7 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-0.1.0.tar.gz
Algorithm Hash digest
SHA256 464b981a8dd6a153cc3782832109486f12e611159d481ae82af5c4fd3447143d
MD5 18012dd4aee3cdb09b012abcf5a2bd18
BLAKE2b-256 42366b7274f1dc5bed82f7e38a4a52e39d4c10ed898d9aed822a906fbb4f0d2b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for quercle_pydantic_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7845d4296a3b438c82595b3a93a47bbc9690ffef7250c1af4ea45fd0be53b7db
MD5 6dd2a515245593f1c2d4838b88eb402d
BLAKE2b-256 05b112867a3231ecdd9110486fddcc9f5ce3901a9447c525fa296a64818f5ac7

See more details on using hashes here.

Provenance

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