Skip to main content

A REST API client for pihole v6

Project description

pyhole6 API Client

Version

pyhole6 is an asynchronous Python client for interacting with the Pi-hole v6.0 REST API. It provides a simple interface to perform various operations on your Pi-hole server.

Features

  • Asynchronous API calls using aiohttp
  • Automatic session management
  • Logging with local timestamps
  • Easy-to-use methods for common Pi-hole operations

Installation

pip install pyhole6

Usage

Initializing the Client

from pyhole6 import Pyhole6
import asyncio

async def main():
    client = Pyhole6("http://pi.hole", "your_password")
    await client.connect()
    # Use the client here
    await client.disconnect()

asyncio.run(main())

Using as a Context Manager

async with Pyhole6("http://pi.hole", "your_password") as client:
    # Use the client here

Available Methods

Statistics

stats = await client.stats.summary()
print(stats)


now = datetime.datetime.now()
_from = int(datetime.datetime.timestamp(now - datetime.timedelta(days=3)))
until = int(datetime.datetime.timestamp(now))

top_clients = await client.stats.top_clients(blocked=True, count=5)

# Top 10 clients in the last 3 days
top_clients_date_range = await client.stats.database('top_clients', (_from, until), blocked=False, count=10)}")

DNS - Disable Blocking

# Disable blocking for 5 minutes (300 seconds)
result = await client.dns.disable(timer=300)

# Disable blocking for indefinitely
result = await client.dns.disable()

DNS - Enable Blocking

# Enable blocking for 5 minutes (300 seconds
result = await client.dns.enable(timer=300)

# Enable blocking indefinitely
result = await client.dns.disable()

DNS - Get Blocking Status

status = await client.dns.status()
print(status)

Logging

The client includes built-in logging with local timestamps. You can access the logger through client.logger:

client.logger.info("Custom log message")

Error Handling

The client will raise exceptions for authentication failures and other API errors. It's recommended to use try-except blocks when making API calls:

try:
    await client.connect()
    stats = await client.get_stats()
except Exception as e:
    print(f"An error occurred: {e}")

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the GPLv3 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

pyhole6-0.0.4.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhole6-0.0.4-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file pyhole6-0.0.4.tar.gz.

File metadata

  • Download URL: pyhole6-0.0.4.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.6 Darwin/24.1.0

File hashes

Hashes for pyhole6-0.0.4.tar.gz
Algorithm Hash digest
SHA256 709166043d4961609ce9a780c0e0d069d8fed4f9ffe6d7fbb723d5a64791456b
MD5 dd9c7e6f047f9a90946f09f4e9b2c0a9
BLAKE2b-256 47796f52a885f45b9ee65062d67cabc6d88ba7db2c02414407fdd6eab11d9f21

See more details on using hashes here.

File details

Details for the file pyhole6-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyhole6-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.9.6 Darwin/24.1.0

File hashes

Hashes for pyhole6-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2fe46bae9bbbaa6bef0da9ca4a7eaa52e9d38b1df79edd72fb444d19134d4462
MD5 1928fadd65a462c3c3715b8adf2fc955
BLAKE2b-256 f003023de8220a5e47a77b601a4994258736a46265642aef0d32dc090f5501ed

See more details on using hashes here.

Supported by

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