Skip to main content

Python API Client for Pi-hole 6

Project description

🍓 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")

Manage Links

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

Module Description
metrics Query history, top clients/domains, DNS stats
dns_control Enable/disable blocking
group_management Create, update, and delete groups
domain_management Allow/block domains (exact & regex)
client_management Manage client-specific rules
list_management Manage blocklists (Adlists)
config Modify Pi-hole configuration
ftl_info Get Pi-hole core process (FTL) info
dhcp Manage DHCP leases
network_info View network devices, interfaces, routes
actions Flush logs, restart services

Contributing

Please check CONTRIBUTING.md for contribution guidelines.

Changelog

See CHANGELOG.md for a list of changes.

License

This project is license under the MIT license.

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

pihole6api-0.2.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

pihole6api-0.2.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file pihole6api-0.2.0.tar.gz.

File metadata

  • Download URL: pihole6api-0.2.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for pihole6api-0.2.0.tar.gz
Algorithm Hash digest
SHA256 938f4aa6a34235029f96dda48fe819b7ad1f39ecf5052944c36097ea6b1577e3
MD5 a0f96468e81ef812511c51b4d310fcea
BLAKE2b-256 02146706814feb88dfddc65192182f349c487b4d3bb6312d77084f4cd3395d6f

See more details on using hashes here.

File details

Details for the file pihole6api-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pihole6api-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for pihole6api-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c327e6f66a3e20bc1322e282e7e2d24158f6efa080aadd3d2f023d262a672a3
MD5 078538f07f7e5ddc11d22d0f0d87b1a3
BLAKE2b-256 1927f7b04143bfc8a155941af372033ee299a4d4f1400bffdc32c545e7ebc913

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page