### Install pihole6api from source Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Installs the pihole6api package from its source code repository. This involves cloning the repository and then installing it in editable mode. ```bash git clone https://github.com/sbarbett/pihole6api.git cd pihole6api pip install -e . ``` -------------------------------- ### Initialize Pi-hole Client and Get Version/Summary Source: https://context7.com/sbarbett/pihole6api/llms.txt Demonstrates how to initialize the PiHole6Client with a server URL and password. It shows how to retrieve client version information and PADD summary data. Remember to close the session when done. ```python from pihole6api import PiHole6Client # Initialize the client client = PiHole6Client("https://pi.hole/", "your-password") # Get client version info print(client.version()) # {'version': '0.2.1', 'description': 'Python API Client for Pi-hole 6', 'project_url': '...'} # Get PADD summary data summary = client.get_padd_summary(full=True) print(summary) # Close session when done client.close_session() ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/sbarbett/pihole6api/blob/main/CONTRIBUTING.md This snippet shows how to create a Python virtual environment named '.venv' using the 'venv' module. This isolates project dependencies. ```bash python -m venv .venv ``` -------------------------------- ### Install Project in Editable Mode Source: https://github.com/sbarbett/pihole6api/blob/main/CONTRIBUTING.md This snippet installs the current project in editable mode within an activated virtual environment using pip. This allows for development and testing of the project directly. ```bash pip install -e . ``` -------------------------------- ### Install pihole6api using pip Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Installs the pihole6api package using pip. This is the standard method for installing Python packages. ```bash pip install pihole6api ``` -------------------------------- ### Network Information API Source: https://context7.com/sbarbett/pihole6api/llms.txt Get information about network devices, interfaces, routes, and gateway configuration. ```APIDOC ## Network Information API ### Description Get information about network devices, interfaces, routes, and gateway configuration. ### Method Various (Python client methods) ### Endpoints N/A (Client library abstraction) ### Parameters #### Path Parameters None #### Query Parameters - **max_devices** (integer) - Optional - Maximum number of devices to retrieve. - **max_addresses** (integer) - Optional - Maximum number of addresses per device to retrieve. - **detailed** (boolean) - Optional - Whether to retrieve detailed information. - **device_id** (integer) - Required for delete_device - The ID of the device to delete. #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get network devices devices = client.network_info.get_devices(max_devices=50, max_addresses=10) print(devices) # Delete a device from network table client.network_info.delete_device(device_id=123) # Get gateway information gateway = client.network_info.get_gateway(detailed=True) # Get network interfaces interfaces = client.network_info.get_interfaces(detailed=True) # Get network routes routes = client.network_info.get_routes(detailed=True) ``` ### Response #### Success Response (200) Responses contain various data structures depending on the information requested (e.g., lists of devices, gateway info, interface details, route details). #### Response Example ```json // Example for get_devices response { "devices": [ { "id": 123, "ip": "192.168.1.1", "mac": "AA:BB:CC:DD:EE:FF", "hostname": "router" } ] } ``` ``` -------------------------------- ### Manage Pi-hole Configuration Source: https://context7.com/sbarbett/pihole6api/llms.txt Facilitates reading and modifying Pi-hole's configuration settings, managing local DNS records, and exporting/importing settings. Supports getting full or section-specific configurations, updating settings, and managing local A records. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get full configuration config = client.config.get_config(detailed=True) print(config) # Get specific config section dns_config = client.config.get_config_section("dns", detailed=True) # Update configuration client.config.update_config({ "dns": { "queryLogging": True, "cnameDeepInspect": True } }) # Add local A record (requires webserver.api.app_sudo enabled) client.config.add_local_a_record("myserver.local", "192.168.1.50") # Remove local A record client.config.remove_local_a_record("myserver.local", "192.168.1.50") ``` -------------------------------- ### Manage Pi-hole Domains (Add, Get, Update, Delete) Source: https://context7.com/sbarbett/pihole6api/llms.txt This section covers the management of domains within Pi-hole's allow and deny lists. It includes adding single or multiple domains, specifying exact matches or regex patterns, retrieving domain information, updating existing domains (e.g., changing type), and deleting domains. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Add domain to blocklist (exact match) client.domain_management.add_domain( domain="ads.example.com", domain_type="deny", kind="exact", comment="Block ads", enabled=True ) # Add multiple domains at once client.domain_management.add_domain( domain=["tracker1.com", "tracker2.com"], domain_type="deny", kind="exact" ) # Add regex pattern to allowlist client.domain_management.add_domain( domain=r"(\\.|^)example\\.org$", domain_type="allow", kind="regex", comment="Allow all example.org subdomains" ) # Get domain info info = client.domain_management.get_domain("ads.example.com", "deny", "exact") print(info) # Get all domains all_domains = client.domain_management.get_all_domains() print(all_domains) # {'whitelist': {...}, 'blacklist': {...}} # Update domain (move from deny to allow) client.domain_management.update_domain( domain="ads.example.com", domain_type="deny", kind="exact", new_type="allow", comment="Actually needed" ) # Delete domain client.domain_management.delete_domain("ads.example.com", "allow", "exact") ``` -------------------------------- ### Retrieve Pi-hole FTL Information and Diagnostics Source: https://context7.com/sbarbett/pihole6api/llms.txt This snippet demonstrates how to retrieve various system information, diagnostics, logs, and version details from the Pi-hole FTL engine. It includes functions for getting versions, system metrics, logs, and diagnosis messages. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get Pi-hole version version = client.ftl_info.get_version() print(version) # {'core': {'version': '...', ...}, 'ftl': {...}, 'web': {...}} # Get FTL parameters tl = client.ftl_info.get_ftl_info() # Get system info system = client.ftl_info.get_system_info() # Get host info host = client.ftl_info.get_host_info() # Get client info (requesting client) client_info = client.ftl_info.get_client_info() # Get database statistics db_info = client.ftl_info.get_database_info() # Get system metrics (CPU, memory, etc.) metrics = client.ftl_info.get_metrics_info() # Get sensor data (temperature, etc.) sensors = client.ftl_info.get_sensors_info() # Get diagnosis messages messages = client.ftl_info.get_diagnosis_messages() msg_count = client.ftl_info.get_diagnosis_message_count() # Delete a diagnosis message client.ftl_info.delete_diagnosis_message(message_id=1) # Get available API endpoints endpoints = client.ftl_info.get_endpoints() # Get login page info login_info = client.ftl_info.get_login_info() # Get dnsmasq logs (with pagination) logs = client.ftl_info.get_dnsmasq_logs() next_logs = client.ftl_info.get_dnsmasq_logs(next_id=logs.get("nextID")) # Get FTL logs ftl_logs = client.ftl_info.get_ftl_logs() # Get webserver logs web_logs = client.ftl_info.get_webserver_logs() ``` -------------------------------- ### Retrieve Pi-hole Network Information Source: https://context7.com/sbarbett/pihole6api/llms.txt This snippet shows how to obtain information about network devices, interfaces, routes, and gateway configuration from Pi-hole. It includes functions to get devices, delete devices, and retrieve detailed gateway and interface information. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get network devices devices = client.network_info.get_devices(max_devices=50, max_addresses=10) print(devices) # Delete a device from network table client.network_info.delete_device(device_id=123) # Get gateway information gateway = client.network_info.get_gateway(detailed=True) # Get network interfaces interfaces = client.network_info.get_interfaces(detailed=True) # Get network routes routes = client.network_info.get_routes(detailed=True) ``` -------------------------------- ### Get Pi-Hole Metrics Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Retrieves historical data and query statistics from the Pi-Hole API. The `get_history()` method returns a dictionary containing historical metrics, while `get_queries()` provides query-related data. ```python history = client.metrics.get_history() print(history) # {'history': [{'timestamp': 1740120900, 'total': 0, 'cached': 0 ...}]} queries = client.metrics.get_queries() print(queries) ``` -------------------------------- ### Client Initialization Source: https://context7.com/sbarbett/pihole6api/llms.txt Initialize the Pi-hole client with your server URL and password. The client automatically authenticates and provides access to all API modules. ```APIDOC ## Client Initialization ### Description Initialize the Pi-hole client with your server URL and password. The client automatically authenticates and provides access to all API modules. ### Method N/A (Initialization) ### Endpoint N/A (Initialization) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client # Initialize the client client = PiHole6Client("https://pi.hole/", "your-password") # Get client version info print(client.version()) # {'version': '0.2.1', 'description': 'Python API Client for Pi-hole 6', 'project_url': '...'} # Get PADD summary data summary = client.get_padd_summary(full=True) print(summary) # Close session when done client.close_session() ``` ### Response #### Success Response (200) - **version** (string) - The version of the Pi-hole API client. - **description** (string) - A description of the API client. - **project_url** (string) - The URL of the project. #### Response Example ```json { "version": "0.2.1", "description": "Python API Client for Pi-hole 6", "project_url": "..." } ``` ``` -------------------------------- ### System Actions API Source: https://context7.com/sbarbett/pihole6api/llms.txt Perform system-level actions like flushing logs, restarting DNS, and updating gravity. ```APIDOC ## System Actions API ### Description Perform system-level actions like flushing logs, restarting DNS, and updating gravity. ### Method Various (Python client methods) ### Endpoints N/A (Client library abstraction) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Flush DNS logs client.actions.flush_logs() # Flush ARP cache (network table) client.actions.flush_arp() # Restart DNS resolver client.actions.restart_dns() # Run gravity update (refresh blocklists) result = client.actions.run_gravity() print(result) ``` ### Response #### Success Response (200) Responses vary based on the action (e.g., success status, update results). #### Response Example ```json // Example for run_gravity success { "status": "success", "message": "Gravity updated successfully." } ``` ``` -------------------------------- ### Perform Pi-hole System Actions Source: https://context7.com/sbarbett/pihole6api/llms.txt This snippet shows how to execute system-level commands on Pi-hole, such as flushing logs, restarting the DNS resolver, and updating the gravity (blocklists). It requires a PiHole6Client instance. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Flush DNS logs client.actions.flush_logs() # Flush ARP cache (network table) client.actions.flush_arp() # Restart DNS resolver client.actions.restart_dns() # Run gravity update (refresh blocklists) result = client.actions.run_gravity() print(result) ``` -------------------------------- ### Configuration Management API Source: https://context7.com/sbarbett/pihole6api/llms.txt Manage local DNS records (CNAMEs) and import/export Pi-hole settings. ```APIDOC ## Configuration Management API ### Description Manage local DNS records (CNAMEs) and import/export Pi-hole settings. ### Method Various (Python client methods) ### Endpoints N/A (Client library abstraction) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Add CNAME record client.config.add_local_cname("alias.local", "myserver.local") # Add CNAME with TTL client.config.add_local_cname("alias2.local", "myserver.local", ttl=3600) # Remove CNAME record client.config.remove_local_cname("alias.local", "myserver.local") # Export settings to file with open("pihole-backup.zip", "wb") as f: f.write(client.config.export_settings()) # Import settings from file result = client.config.import_settings( "pihole-backup.zip", import_options={ "config": True, "gravity": {"group": True} } ) ``` ### Response #### Success Response (200) Responses vary based on the operation (e.g., boolean for add/remove, file content for export, import status for import). #### Response Example ```json // Example for import_settings success { "status": "success", "message": "Settings imported successfully." } ``` ``` -------------------------------- ### Metrics and Statistics Source: https://context7.com/sbarbett/pihole6api/llms.txt Retrieve query history, DNS statistics, top clients, top domains, and upstream destination metrics. ```APIDOC ## Metrics and Statistics ### Description Retrieve query history, DNS statistics, top clients, top domains, and upstream destination metrics. ### Method N/A (Module) ### Endpoint N/A (Module) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client import time client = PiHole6Client("https://pi.hole/", "your-password") # Get activity graph data history = client.metrics.get_history() print(history) # {'history': [{'timestamp': 1740120900, 'total': 0, 'cached': 0, ...}]} # Get per-client activity (top 20 clients) client_history = client.metrics.get_history_clients(clients=20) # Get query log with filtering queries = client.metrics.get_queries( length=50, domain="*.google.com", client="192.168.1.100" ) # Get summary overview summary = client.metrics.get_stats_summary() print(summary) # {'queries': {'total': 12345, 'blocked': 1234, ...}, 'gravity': {...}} # Get top domains (blocked) top_blocked = client.metrics.get_stats_top_domains(blocked=True, count=10) # Get top clients top_clients = client.metrics.get_stats_top_clients(count=10) # Get query types distribution query_types = client.metrics.get_stats_query_types() # Get upstream destinations upstreams = client.metrics.get_stats_upstreams() # Get recently blocked domains recent = client.metrics.get_stats_recent_blocked(count=5) # Long-term database queries (by date range) end_ts = int(time.time()) start_ts = end_ts - 86400 # Last 24 hours db_history = client.metrics.get_history_database(start_ts, end_ts) db_summary = client.metrics.get_stats_database_summary(start_ts, end_ts) ``` ### Response #### Success Response (200) Responses vary depending on the specific metrics function called. Examples include: - **history** (list of dicts) - Activity graph data. - **queries** (list of dicts) - Query log entries. - **summary** (dict) - Overall statistics. - **top_blocked** (list of dicts) - Top blocked domains. - **top_clients** (list of dicts) - Top clients. - **query_types** (dict) - Distribution of query types. - **upstreams** (list of dicts) - Upstream DNS destinations. - **recent** (list of dicts) - Recently blocked domains. - **db_history** (list of dicts) - Historical database query data. - **db_summary** (dict) - Summary of database query data. #### Response Example ```json { "history": [ { "timestamp": 1740120900, "total": 0, "cached": 0 } ] } ``` ``` -------------------------------- ### Domain Management Source: https://context7.com/sbarbett/pihole6api/llms.txt Add, update, and remove domains from allow/deny lists with exact or regex matching. ```APIDOC ## Domain Management ### Description Add, update, and remove domains from allow/deny lists with exact or regex matching. ### Method N/A (Module) ### Endpoint N/A (Module) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Add domain to blocklist (exact match) client.domain_management.add_domain( domain="ads.example.com", domain_type="deny", kind="exact", comment="Block ads", enabled=True ) # Add multiple domains at once client.domain_management.add_domain( domain=["tracker1.com", "tracker2.com"], domain_type="deny", kind="exact" ) # Add regex pattern to allowlist client.domain_management.add_domain( domain=r"(\\.|^)example\\.org$", domain_type="allow", kind="regex", comment="Allow all example.org subdomains" ) # Get domain info info = client.domain_management.get_domain("ads.example.com", "deny", "exact") print(info) # Get all domains all_domains = client.domain_management.get_all_domains() print(all_domains) # {'whitelist': {...}, 'blacklist': {...}} # Update domain (move from deny to allow) client.domain_management.update_domain( domain="ads.example.com", domain_type="deny", kind="exact", new_type="allow", comment="Actually needed" ) # Delete domain client.domain_management.delete_domain("ads.example.com", "allow", "exact") ``` ### Response #### Success Response (200) Responses vary depending on the operation. For `get_domain` and `get_all_domains`, the response will contain domain information. For add, update, and delete operations, a success confirmation is typically returned. #### Response Example ```json { "whitelist": { "example.org": { "type": "regex", "comment": "Allow all example.org subdomains" } }, "blacklist": { "ads.example.com": { "type": "exact", "comment": "Block ads" } } } ``` ``` -------------------------------- ### Connection Configuration API Source: https://context7.com/sbarbett/pihole6api/llms.txt Configure advanced connection settings including retries, timeouts, and connection pooling. ```APIDOC ## Connection Configuration API ### Description Configure advanced connection settings including retries, timeouts, and connection pooling. ### Method Various (Python client methods and direct connection usage) ### Endpoints N/A (Client library abstraction, but raw GET example provided) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pihole6api import PiHole6Connection from pihole6api import PiHole6Metrics # Create connection with custom settings conn = PiHole6Connection( base_url="https://pi.hole/", password="your-password", max_retries=5, retry_delay=2, connection_timeout=30, disable_connection_pooling=False ) # Use connection directly with modules metrics = PiHole6Metrics(conn) history = metrics.get_history() # Make raw API calls response = conn.get("stats/summary") print(response) # Close session conn.exit() ``` ### Response #### Success Response (200) Responses vary based on the raw API call made (e.g., JSON object for `stats/summary`). #### Response Example ```json // Example for conn.get("stats/summary") response { "dns_queries_today": 1000, "unique_clients": 50, "ads_blocked_today": 200 } ``` ``` -------------------------------- ### Manage Pi-hole Configuration Settings Source: https://context7.com/sbarbett/pihole6api/llms.txt This snippet demonstrates how to add, remove, export, and import Pi-hole configuration settings using the Pi-hole 6 API. It covers CNAME record management and backup/restore operations. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Add CNAME record client.config.add_local_cname("alias.local", "myserver.local") # Add CNAME with TTL client.config.add_local_cname("alias2.local", "myserver.local", ttl=3600) # Remove CNAME record client.config.remove_local_cname("alias.local", "myserver.local") # Export settings to file with open("pihole-backup.zip", "wb") as f: f.write(client.config.export_settings()) # Import settings from file result = client.config.import_settings( "pihole-backup.zip", import_options={ "config": True, "gravity": {"group": True} } ) ``` -------------------------------- ### Retrieve Pi-hole Metrics and Statistics Source: https://context7.com/sbarbett/pihole6api/llms.txt This snippet demonstrates fetching various metrics from Pi-hole, including query history, client activity, query logs, summary statistics, top domains, top clients, query types, upstream destinations, and recently blocked domains. It also shows how to query long-term database history by date range. ```python from pihole6api import PiHole6Client import time client = PiHole6Client("https://pi.hole/", "your-password") # Get activity graph data history = client.metrics.get_history() print(history) # {'history': [{'timestamp': 1740120900, 'total': 0, 'cached': 0, ...]}) # Get per-client activity (top 20 clients) client_history = client.metrics.get_history_clients(clients=20) # Get query log with filtering queries = client.metrics.get_queries( length=50, domain="*.google.com", client="192.168.1.100" ) # Get summary overview summary = client.metrics.get_stats_summary() print(summary) # {'queries': {'total': 12345, 'blocked': 1234, ...}, 'gravity': {...}} # Get top domains (blocked) top_blocked = client.metrics.get_stats_top_domains(blocked=True, count=10) # Get top clients top_clients = client.metrics.get_stats_top_clients(count=10) # Get query types distribution query_types = client.metrics.get_stats_query_types() # Get upstream destinations upstreams = client.metrics.get_stats_upstreams() # Get recently blocked domains recent = client.metrics.get_stats_recent_blocked(count=5) # Long-term database queries (by date range) end_ts = int(time.time()) start_ts = end_ts - 86400 # Last 24 hours db_history = client.metrics.get_history_database(start_ts, end_ts) db_summary = client.metrics.get_stats_database_summary(start_ts, end_ts) ``` -------------------------------- ### FTL Information and Diagnostics API Source: https://context7.com/sbarbett/pihole6api/llms.txt Retrieve system information, diagnostics, logs, and version details from the Pi-hole FTL engine. ```APIDOC ## FTL Information and Diagnostics API ### Description Retrieve system information, diagnostics, logs, and version details from the Pi-hole FTL engine. ### Method Various (Python client methods) ### Endpoints N/A (Client library abstraction) ### Parameters #### Path Parameters None #### Query Parameters - **message_id** (integer) - Optional - The ID of the diagnosis message to delete. - **next_id** (string) - Optional - The ID to use for pagination when fetching dnsmasq logs. #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get Pi-hole version version = client.ftl_info.get_version() print(version) # Get FTL parameters ftl = client.ftl_info.get_ftl_info() # Get system info system = client.ftl_info.get_system_info() # Get host info host = client.ftl_info.get_host_info() # Get client info (requesting client) client_info = client.ftl_info.get_client_info() # Get database statistics db_info = client.ftl_info.get_database_info() # Get system metrics (CPU, memory, etc.) metrics = client.ftl_info.get_metrics_info() # Get sensor data (temperature, etc.) sensors = client.ftl_info.get_sensors_info() # Get diagnosis messages messages = client.ftl_info.get_diagnosis_messages() msg_count = client.ftl_info.get_diagnosis_message_count() # Delete a diagnosis message client.ftl_info.delete_diagnosis_message(message_id=1) # Get available API endpoints endpoints = client.ftl_info.get_endpoints() # Get login page info login_info = client.ftl_info.get_login_info() # Get dnsmasq logs (with pagination) logs = client.ftl_info.get_dnsmasq_logs() next_logs = client.ftl_info.get_dnsmasq_logs(next_id=logs.get("nextID")) # Get FTL logs ftl_logs = client.ftl_info.get_ftl_logs() # Get webserver logs web_logs = client.ftl_info.get_webserver_logs() ``` ### Response #### Success Response (200) Responses contain various data structures depending on the information requested (e.g., dictionaries for version, system info, logs). #### Response Example ```json // Example for get_version response { "core": {"version": "5.17.1"}, "ftl": {"version": "5.17"}, "web": {"version": "1.22.1"} } ``` ``` -------------------------------- ### Import Pi-Hole Settings Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Imports Pi-Hole settings from a zip file. Allows specifying which components to import, such as configuration and gravity data. ```python client.config.import_settings("pihole-settings.zip", {"config": True, "gravity": {"group": True}}) ``` -------------------------------- ### Configure Pi-hole Advanced Connection Settings Source: https://context7.com/sbarbett/pihole6api/llms.txt This snippet demonstrates how to configure advanced connection settings for the Pi-hole API, including retries, timeouts, and connection pooling. It shows how to create a connection with custom parameters and use it for API calls. ```python from pihole6api import PiHole6Connection from pihole6api import PiHole6Metrics # Create connection with custom settings conn = PiHole6Connection( base_url="https://pi.hole/", password="your-password", max_retries=5, retry_delay=2, connection_timeout=30, disable_connection_pooling=False ) # Use connection directly with modules metrics = PiHole6Metrics(conn) history = metrics.get_history() # Make raw API calls response = conn.get("stats/summary") print(response) # Close session conn.exit() ``` -------------------------------- ### Manage Pi-hole Clients Source: https://context7.com/sbarbett/pihole6api/llms.txt Enables management of client-specific rules based on IP, MAC address, or hostname. Supports adding, retrieving, updating, deleting, and batch deleting clients. Clients can be assigned to groups. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Add a client by IP client.client_management.add_client( client="192.168.1.100", comment="Living room TV", groups=[1, 2] # Assign to group IDs ) # Add client by MAC address client.client_management.add_client( client="12:34:56:78:9A:BC", comment="Smart thermostat" ) # Add multiple clients at once client.client_management.add_client( client=["192.168.1.101", "192.168.1.102"], comment="Guest devices" ) # Get all clients clients = client.client_management.get_clients() print(clients) # Get specific client info = client.client_management.get_client("192.168.1.100") # Get client suggestions from known devices suggestions = client.client_management.get_client_suggestions() # Update client groups client.client_management.update_client( client="192.168.1.100", comment="Updated comment", groups=[1, 3] ) # Delete client client.client_management.delete_client("192.168.1.100") # Batch delete clients client.client_management.batch_delete_clients([ {"item": "192.168.1.101"}, {"item": "192.168.1.102"} ]) ``` -------------------------------- ### Initialize PiHole6Client Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Initializes the PiHole6Client with the Pi-hole URL and password. This client object is used to interact with the Pi-Hole API. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://your-pihole.local/", "your-password") ``` -------------------------------- ### Manage Pi-hole Groups Source: https://context7.com/sbarbett/pihole6api/llms.txt Provides functionality to create, retrieve, update, and delete groups in Pi-hole. Groups are used for organizing domains, clients, and lists. Supports adding single or multiple groups at once, and batch deletion. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Create a new group client.group_management.add_group( name="Kids Devices", comment="Stricter filtering for children", enabled=True ) # Create multiple groups at once client.group_management.add_group( name=["IoT Devices", "Guest Network"], comment="Network segments" ) # Get all groups groups = client.group_management.get_groups() print(groups) # Get specific group group_info = client.group_management.get_group("Kids Devices") # Update/rename group client.group_management.update_group( name="Kids Devices", new_name="Children Devices", comment="Updated description", enabled=True ) # Delete group client.group_management.delete_group("Children Devices") # Batch delete multiple groups client.group_management.batch_delete_groups(["IoT Devices", "Guest Network"]) ``` -------------------------------- ### Clone Pi-hole 6 API Repository Source: https://github.com/sbarbett/pihole6api/blob/main/CONTRIBUTING.md This snippet demonstrates how to clone the Pi-hole 6 API project repository from GitHub using Git. It also shows how to navigate into the cloned directory. ```bash git clone https://github.com/sbarbett/pihole6api.git cd pihole6api ``` -------------------------------- ### Export Pi-Hole Settings Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Exports the current Pi-Hole configuration and settings as a zip file. The exported data is written to a specified file path. ```python # Export settings and save as a .zip file with open("pihole-settings.zip", "wb") as f: f.write(client.config.export_settings()) ``` -------------------------------- ### DNS Blocking Control Source: https://context7.com/sbarbett/pihole6api/llms.txt Enable or disable DNS blocking globally, with optional timer support for temporary changes. ```APIDOC ## DNS Blocking Control ### Description Enable or disable DNS blocking globally, with optional timer support for temporary changes. ### Method N/A (Module) ### Endpoint N/A (Module) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get current blocking status status = client.dns_control.get_blocking_status() print(status) # {'blocking': 'enabled', 'timer': None, ...} # Disable blocking for 60 seconds client.dns_control.set_blocking_status(blocking=False, timer=60) print(client.dns_control.get_blocking_status()) # {'blocking': 'disabled', 'timer': 60, ...} # Re-enable blocking permanently client.dns_control.set_blocking_status(blocking=True) ``` ### Response #### Success Response (200) - **blocking** (string) - The current blocking status ('enabled' or 'disabled'). - **timer** (integer or null) - The remaining time in seconds for temporary blocking, or null if not in temporary mode. #### Response Example ```json { "blocking": "enabled", "timer": null } ``` ``` -------------------------------- ### Control Pi-hole DNS Blocking Status Source: https://context7.com/sbarbett/pihole6api/llms.txt Shows how to manage Pi-hole's DNS blocking status. You can check the current status, disable blocking temporarily with a timer, or re-enable it permanently. Requires an initialized PiHole6Client. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get current blocking status status = client.dns_control.get_blocking_status() print(status) # {'blocking': 'enabled', 'timer': None, ...} # Disable blocking for 60 seconds client.dns_control.set_blocking_status(blocking=False, timer=60) print(client.dns_control.get_blocking_status()) # {'blocking': 'disabled', 'timer': 60, ...} # Re-enable blocking permanently client.dns_control.set_blocking_status(blocking=True) ``` -------------------------------- ### DHCP Management API Source: https://context7.com/sbarbett/pihole6api/llms.txt View and manage DHCP leases when Pi-hole is configured as a DHCP server. ```APIDOC ## DHCP Management API ### Description View and manage DHCP leases when Pi-hole is configured as a DHCP server. ### Method Various (Python client methods) ### Endpoints N/A (Client library abstraction) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get active DHCP leases leases = client.dhcp.get_leases() print(leases) # Remove a specific lease client.dhcp.remove_lease("192.168.1.100") ``` ### Response #### Success Response (200) - **leases** (array of objects) - A list of active DHCP leases, each containing IP, MAC address, hostname, etc. #### Response Example ```json { "leases": [ { "ip": "192.168.1.100", "hwaddr": "AA:BB:CC:DD:EE:FF", "hostname": "my-device", "lease_time": 86400 } ] } ``` ``` -------------------------------- ### Manage Pi-Hole Domains Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Manages domain entries in Pi-Hole's block/allow lists. `add_domain()` adds a domain with a specified action (e.g., 'deny') and type (e.g., 'exact'), while `delete_domain()` removes it. ```python client.domain_management.add_domain("ads.example.com", "deny", "exact") client.domain_management.delete_domain("ads.example.com", "deny", "exact") ``` -------------------------------- ### Manage Pi-hole Lists (Blocklists/Allowlists) Source: https://context7.com/sbarbett/pihole6api/llms.txt Allows for the management of external blocklists and allowlists (Adlists) within Pi-hole. Operations include adding, retrieving, updating, deleting, and batch deleting lists. Lists can be specified by URL and type. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Add a blocklist client.list_management.add_list( address="https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts", list_type="block", comment="StevenBlack unified hosts", enabled=True ) # Add multiple lists at once client.list_management.add_list( address=[ "https://example.com/blocklist1.txt", "https://example.com/blocklist2.txt" ], list_type="block" ) # Add an allowlist client.list_management.add_list( address="https://example.com/allowlist.txt", list_type="allow" ) # Get all lists all_lists = client.list_management.get_lists() print(all_lists) # Get only blocklists blocklists = client.list_management.get_lists(list_type="block") # Get specific list info info = client.list_management.get_list( "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts", list_type="block" ) # Search for a domain in lists results = client.list_management.search_list( domain="facebook.com", num=10, partial=True, debug=True ) # Update list client.list_management.update_list( address="https://example.com/blocklist1.txt", list_type="block", comment="Updated comment", enabled=False ) # Delete list client.list_management.delete_list( address="https://example.com/blocklist1.txt", list_type="block" ) # Batch delete lists client.list_management.batch_delete_lists([ {"item": "https://example.com/blocklist2.txt", "type": "block"} ]) ``` -------------------------------- ### Restart Pi-Hole DNS Service Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Restarts the Pi-Hole DNS resolver (FTL). This is useful after making configuration changes or troubleshooting. The `restart_dns()` method is used. ```python client.actions.restart_dns() ``` -------------------------------- ### Batch Delete Domains Source: https://context7.com/sbarbett/pihole6api/llms.txt Deletes multiple domains from Pi-hole's blocklists in a single operation. Requires specifying the domain item, type (e.g., 'deny'), and kind (e.g., 'exact'). ```python client.domain_management.batch_delete_domains([ {"item": "tracker1.com", "type": "deny", "kind": "exact"}, {"item": "tracker2.com", "type": "deny", "kind": "exact"} ]) ``` -------------------------------- ### Manage Pi-hole DHCP Leases Source: https://context7.com/sbarbett/pihole6api/llms.txt This snippet illustrates how to view and manage DHCP leases when Pi-hole is configured as a DHCP server. It includes functions to retrieve active leases and remove specific leases by IP address. ```python from pihole6api import PiHole6Client client = PiHole6Client("https://pi.hole/", "your-password") # Get active DHCP leases leases = client.dhcp.get_leases() print(leases) # {'leases': [{'ip': '192.168.1.100', 'hwaddr': '...', 'hostname': '...', ...}]} # Remove a specific lease client.dhcp.remove_lease("192.168.1.100") ``` -------------------------------- ### Manage Local DNS Records (A Records) Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Adds and removes local A records (hostname to IP mapping) in Pi-Hole. Requires `webserver.api.app_sudo` to be enabled in Pi-Hole settings. `add_local_a_record()` and `remove_local_a_record()` are used for this purpose. ```python # Add A record (hostname to IP mapping) client.config.add_local_a_record("foo.dev", "192.168.1.1") client.config.remove_local_a_record("foo.dev", "192.168.1.1") ``` -------------------------------- ### Manage Pi-Hole Lists Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Handles external blocklists (Adlists) in Pi-Hole. `add_list()` adds a URL to a list, and `delete_list()` removes it. ```python client.list_management.add_list("https://example.com/blocklist.txt", "block") client.list_management.delete_list("https://example.com/blocklist.txt", "block") ``` -------------------------------- ### Manage Local DNS Records (CNAME Records) Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Adds and removes local CNAME records (alias to hostname mapping) in Pi-Hole, with optional TTL. Requires `webserver.api.app_sudo` to be enabled. `add_local_cname()` and `remove_local_cname()` are used. ```python # Add CNAME record (alias to hostname mapping) client.config.add_local_cname("bar.xyz", "foo.dev") client.config.add_local_cname("bar.xyz", "foo.dev", ttl=3600) # With TTL client.config.remove_local_cname("bar.xyz", "foo.dev") ``` -------------------------------- ### Manage Pi-Hole Groups Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Allows for the creation and deletion of custom groups within Pi-Hole. `add_group()` creates a new group with an optional comment, and `delete_group()` removes an existing group. ```python client.group_management.add_group("Custom Group", comment="For testing") client.group_management.delete_group("Custom Group") ``` -------------------------------- ### Enable/Disable Pi-Hole Blocking Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Controls the blocking status of Pi-Hole. `set_blocking_status(False, 60)` disables blocking for 60 seconds, while `get_blocking_status()` retrieves the current status. ```python client.dns_control.set_blocking_status(False, 60) print(client.dns_control.get_blocking_status()) # {'blocking': 'disabled', 'timer': 60 ...} ``` -------------------------------- ### Flush Pi-Hole Logs Source: https://github.com/sbarbett/pihole6api/blob/main/README.md Clears the Pi-Hole query logs. This action is performed using the `flush_logs()` method. ```python client.actions.flush_logs() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.