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

Get Statistics

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

Disable Blocking

# Disable blocking for 5 minutes (300 seconds)
result = await client.disable_blocking(duration=300)
print(result)

Enable Blocking

# Enable blocking immediately
result = await client.enable_blocking()
print(result)

Get Blocking Status

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

Get Host Information

host_info = await client.get_host_info()
print(host_info)

Get Version Information

version_info = await client.get_version_info()
print(version_info)

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.


---
Answer from Perplexity: pplx.ai/share

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.2.tar.gz (14.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.2-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyhole6-0.0.2.tar.gz
  • Upload date:
  • Size: 14.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.2.tar.gz
Algorithm Hash digest
SHA256 ec4964edf03d9c355d25add475b0a56d30aa1d5d0ed9d97f4982424f5b8648b9
MD5 d46d770095355fedb89416e3bb4208f7
BLAKE2b-256 39c21e573e86b93d5fc01ef20f31daf40d60ad2a7121155ab5ee6aa0de53023b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyhole6-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.3 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ff2327b1ca47fb9f42fb3c8c6245475bf6861c63c7ba634b9adda1fb6fbcccf
MD5 b3253c5261d0efb1497cfddf58a3162a
BLAKE2b-256 23f2f7ee371c8617e292e98c8e43da8186906c12571c6247779675757e9d0f81

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