A SearXNG web-search tool for Pydantic AI agents.
Project description
pydantic-ai-searxng
A SearXNG web-search tool for Pydantic AI agents — modeled on the upstream duckduckgo and tavily common tools, but pointed at any SearXNG instance you control.
Why SearXNG?
SearXNG is a self-hostable metasearch engine that aggregates results from Google, DuckDuckGo, Bing, Wikipedia, GitHub, arXiv, and ~200 other sources. Pointing your agent at your own instance gives you:
- No third-party API keys, rate limits, or per-query billing.
- Full control over which engines, categories, and SafeSearch level the agent sees.
- Privacy: queries don't leave your infrastructure.
Deploy a SearXNG instance
Need an instance? One-click deploy on Railway:
Important: enable JSON on your SearXNG instance
JSON output is not enabled by default. You must add it to search.formats in settings.yml on the instance:
search:
formats:
- html
- json
Without this, requests return HTML and this tool will raise a RuntimeError.
Install
pip install pydantic-ai-searxng
# or
uv add pydantic-ai-searxng
Usage
from pydantic_ai import Agent
from pydantic_ai_searxng import searxng_search_tool
agent = Agent(
'openai:gpt-4o',
tools=[searxng_search_tool('https://searxng.example.com')],
system_prompt='Use the search tool to ground answers in current sources.',
)
result = agent.run_sync('What did Pydantic AI release this month?')
print(result.output)
Configuration
All keyword arguments are optional and are fixed at factory time (the LLM only sees query):
searxng_search_tool(
'https://searxng.example.com',
max_results=5,
categories='general,news',
engines='google,duckduckgo,wikipedia',
language='en',
safesearch=1, # 0 off, 1 moderate, 2 strict
time_range='week', # day | week | month | year
timeout=20.0,
)
Pass your own httpx.AsyncClient if you want shared connection pooling, custom headers, or a proxy:
import httpx
client = httpx.AsyncClient(headers={'User-Agent': 'my-agent/1.0'})
tool = searxng_search_tool('https://searxng.example.com', client=client)
Result shape
Each result is a TypedDict:
class SearxngResult(TypedDict):
url: str
title: str
content: str
engine: NotRequired[str]
publishedDate: NotRequired[str]
thumbnail: NotRequired[str]
Development
This project uses uv, ruff, and ty (Astral's type checker).
uv sync --extra dev
uv run ruff format .
uv run ruff check .
uv run ty check
uv run pytest
uv build
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_ai_searxng-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_ai_searxng-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
722fa28193e3e867dce61ab988de88d81032ee36da66d4bac8a35e72809e0e2a
|
|
| MD5 |
f8258a58d999726aa8333415f839f077
|
|
| BLAKE2b-256 |
8f5df61d5e3c367d3700229c75bc8030aa522937140f1a71ab9584bf4e43534f
|
File details
Details for the file pydantic_ai_searxng-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_ai_searxng-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f06bf3ba4976e49a48198c16c4fae5d9c07a6fb2539a7667084002b3cb074e26
|
|
| MD5 |
4dd08a46159e28d24ecc951f75dc0d48
|
|
| BLAKE2b-256 |
9ca1168b95bde44b98707cdab3d470a1dabd19fc89a4db598c4d1ace161570b8
|