Skip to main content

gravitywell

A third-party, typed Python client for the Pi-hole v6 REST API, with AI tools and an MCP server.

PyPI Python versions CI License: MIT

Overview

gravitywell is a typed Python client for Pi-hole's v6 REST API, in sync and async versions.

It handles the session for you, so you can get straight to work: pause blocking for five minutes, add an allow rule, or pull the last hour of blocked queries from one device. Answers come back as Pydantic models your editor can autocomplete.

It's built for AI agents too. Its methods double as tools with descriptions written for a model, and the insights tools answer questions like "why is this domain blocked?" in a single call. gravitywell-mcp serves them to Claude and other MCP clients, read-only unless you allow more.

Install

pip install gravitywell

For the MCP server, install the mcp extra: pip install "gravitywell[mcp]".

Using an AI coding assistant? Point it at llms.txt, a compact guide to gravitywell for models.

Quickstart

Create an application password in the Pi-hole's web interface, under Settings › Web interface / API, and put it in the PIHOLE_PASSWORD environment variable:

import os

from gravitywell import PiHole, PiHoleAuth

auth = PiHoleAuth(os.environ["PIHOLE_PASSWORD"])  # an application password

with PiHole("http://pi.hole", auth=auth) as api:
    summary = api.stats.summary()  # GET /api/stats/summary -> SummaryResponse
    print(f"{summary.queries.percent_blocked:.1f}% of queries blocked in the last 24 hours")

    status = api.dns.blocking()  # GET /api/dns/blocking -> BlockingResponse
    print(f"Blocking is {status.blocking}")  # enabled

    api.dns.set_blocking(False, timer=300)  # pause blocking for five minutes

    why = api.explain_domain("ads.example.com")  # rules, lists and recent queries in one call
    for rule in why.rules:
        print(f"{rule.type} rule ({rule.kind}): {rule.domain}")
  • The client logs in on its first request, reuses that session, and logs out when the with block ends: a Pi-hole allows only a few sessions at a time.
  • Each method returns a Pydantic model of the Pi-hole's answer, which your editor and type checker know field by field.
  • A 4xx or 5xx answer raises httpx2.HTTPStatusError, with the Pi-hole's reason in its response.
  • For async code, use AsyncPiHole and await each method, as Async clients explains.

Use it from Claude

Put the Pi-hole's URL and application password in a file only you can read:

mkdir -p ~/.config/gravitywell
cat > ~/.config/gravitywell/pihole.env <<'EOF'
PIHOLE_URL=http://pi.hole
PIHOLE_PASSWORD=your-application-password
EOF
chmod 600 ~/.config/gravitywell/pihole.env

Then add the server to Claude Code:

claude mcp add --scope user pihole -- \
  uvx --from "gravitywell[mcp]" gravitywell-mcp --env-file ~/.config/gravitywell/pihole.env

Ask "is my Pi-hole healthy?", "why is this site blocked?" or "which device keeps asking for this domain?". It serves read-only tools until you add --allow-writes or --allow-destructive. MCP server covers Claude Desktop and other MCP clients, and choosing which tools to serve.

Features

  • The whole API. Blocking, domain rules, lists, groups and clients, search, statistics, activity history, the query log, settings, DHCP, the network, diagnosis, logs, actions, sessions, and Teleporter backups.
  • Typed throughout. Pydantic v2 models for every answer, Literal types for fixed sets of values, and times as datetime objects in UTC. The package type-checks in pyright's strict mode.
  • Sessions handled. One login per client, shared by concurrent requests, renewed once when it expires, sent in a header rather than the URL, and logged out on close.
  • Sync and async. PiHole and AsyncPiHole have the same methods, built on httpx2.
  • AI tools. Every endpoint is also a tool for a model, with descriptions written for one, JSON Schemas, safety hints, and errors it can act on. The insights tools answer common questions in one call: why a domain is blocked, who a device is, and what's wrong with the Pi-hole.
  • An MCP server. gravitywell-mcp serves the tools to Claude and other MCP clients, read-only by default, and only the areas you choose.
  • Guard rails. It won't delete the Default group, change settings that could lock you out, hand a model the session or the password hashes, or let a misspelled setting slip past silently, as Pi-hole would.

Guide

Compatibility

gravitywell supports Pi-hole v6, whose REST API replaced v5's interface, on Python 3.12 and newer. It was modeled on, and tested against, Pi-hole core v6.6, web v6.6.1 and FTL v6.9, which gravitywell.PIHOLE_VERSIONS records. Pi-hole compatibility covers newer releases, and the few endpoints gravitywell leaves out.

Project status

gravitywell is pre-1.0, so its API may change between minor versions. Changes are listed in the changelog. It's maintained in spare time: issues and pull requests are welcome, and CONTRIBUTING.md explains how to set up and check a change.

Acknowledgments

gravitywell is built on ClientX, httpx2 and Pydantic, and its MCP server on FastMCP.

gravitywell is an independent, third-party project. It isn't made, endorsed or supported by the Pi-hole project, and uses the name "Pi-hole" only to say what it works with. Pi-hole® is a registered trademark of Pi-hole LLC.

License

gravitywell is released under the MIT License.

Metadata

Release files for gravitywell 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gravitywell 0.1.1
File Size Uploaded Provenance Actions
gravitywell-0.1.1.tar.gz 66.4 kB With provenance Details for gravitywell-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gravitywell 0.1.1
File Interpreter ABI Platform Actions
gravitywell-0.1.1-py3-none-any.whl Python 3 none any Details for gravitywell-0.1.1-py3-none-any.whl

Total release size: 153.1 kB

Release files / gravitywell-0.1.1.tar.gz

Download URL gravitywell-0.1.1.tar.gz
Size 66.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bed98c47f911432d785214ab1fa203ac9d86d844ea0464e1b0a60e7656e9ab65
BLAKE2b-256 checksum
How to use checksums
e103ec3bfc685fc61197233c0a20afbf624cc7873beea6ce41112e9032f9739b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / gravitywell-0.1.1-py3-none-any.whl

Download URL gravitywell-0.1.1-py3-none-any.whl
Size 86.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5da888f5da983dd7338f296a88195dc09768bda3f83e15292b9318bfb82c46f5
BLAKE2b-256 checksum
How to use checksums
181b46295bf2183969105e47e6459c7a8af348f74ca1b4cdec1d7646aa129b41
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for gravitywell 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gravitywell-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page