r/pihole • u/slatecipher • 5h ago
gravitywell: an unofficial, typed Python client for the Pi-hole v6 API, with an optional MCP server
Up front: AI helped write the code. I drove the design and reviewed every change to make sure it matched my vision.
gravitywell is a third-party Python client for the Pi-hole v6 REST API. It isn't affiliated with or endorsed by the Pi-hole project.
import os
from gravitywell import PiHole, PiHoleAuth
auth = PiHoleAuth(os.environ["PIHOLE_PASSWORD"])
with PiHole("http://pi.hole", auth=auth) as api:
print(api.stats.summary().queries.percent_blocked)
api.dns.set_blocking(False, timer=300) # pause for 5 minutes- Covers the whole API: blocking, domain rules, lists, groups, stats, the query log, settings, DHCP, logs, gravity updates, and backups.
- Careful with sessions: it logs in once, reuses the session, and logs out when done, so it doesn't use up v6's small session limit.
- Typed, sync and async: every response is a Pydantic model, and
PiHoleandAsyncPiHolehave the same methods. - Optional MCP server: ask Claude or another AI assistant "why is this site blocked?" or "is my Pi-hole healthy?". It's read-only unless you pass
--allow-writesor--allow-destructive.
It needs Python 3.12+ and Pi-hole v6, and I tested it against FTL v6.9.
I thought it was worth sharing. Feedback is welcome, especially if something doesn't work on your setup.