🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

pihole6api

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pihole6api

Python API Client for Pi-hole 6

0.1.9
Maintainers
1

🍓 pihole6api

This package provides a simple, modular SDK for the PiHole 6 REST API.

Features

  • Automatically handles authentication and renewal
  • Graceful error management
  • Logically organized modules
  • Easily maintained

Installation

Install using pip:

pip install pihole6api

Install from source:

git clone https://github.com/sbarbett/pihole6api.git
cd pihole6api
pip install -e .

Quick Start

Initialize the Client

from pihole6api import PiHole6Client
client = PiHole6Client("https://your-pihole.local/", "your-password")

Example Usage

Get Pi-Hole Metrics

history = client.metrics.get_history()
print(history)  # {'history': [{'timestamp': 1740120900, 'total': 0, 'cached': 0 ...}]}
queries = client.metrics.get_queries()
print(queries)

Enable/Disable Blocking

client.dns_control.set_blocking_status(False, 60)
print(client.dns_control.get_blocking_status()) # {'blocking': 'disabled', 'timer': 60 ...}

Manage Groups

client.group_management.add_group("Custom Group", comment="For testing")
client.group_management.delete_group("Custom Group")

Manage Domains

client.domain_management.add_domain("ads.example.com", "deny", "exact")
client.domain_management.delete_domain("ads.example.com", "deny", "exact")
client.list_management.add_list("https://example.com/blocklist.txt", "block")
client.list_management.delete_list("https://example.com/blocklist.txt", "block")

Export/Import PiHole Settings

# Export settings and save as a .zip file
with open("pihole-settings.zip", "wb") as f:
    f.write(client.config.export_settings())

client.config.import_settings("pihole-settings.zip", {"config": True, "gravity": {"group": True}})

Flush Logs & Restart DNS

client.actions.flush_logs()
client.actions.restart_dns()

API Modules

ModuleDescription
metricsQuery history, top clients/domains, DNS stats
dns_controlEnable/disable blocking
group_managementCreate, update, and delete groups
domain_managementAllow/block domains (exact & regex)
client_managementManage client-specific rules
list_managementManage blocklists (Adlists)
configModify Pi-hole configuration
ftl_infoGet Pi-hole core process (FTL) info
dhcpManage DHCP leases
network_infoView network devices, interfaces, routes
actionsFlush logs, restart services

License

This project is license under the MIT license.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts