Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xelk/pi_hole_api
Pi-hole python api
https://github.com/xelk/pi_hole_api
api-wrapper codereview pihole pip python3 requests
Last synced: about 2 months ago
JSON representation
Pi-hole python api
- Host: GitHub
- URL: https://github.com/xelk/pi_hole_api
- Owner: XelK
- License: mit
- Created: 2021-10-30T12:45:59.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T08:58:00.000Z (about 2 months ago)
- Last Synced: 2024-10-29T10:05:23.763Z (about 2 months ago)
- Topics: api-wrapper, codereview, pihole, pip, python3, requests
- Language: Python
- Homepage:
- Size: 43.9 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pi_hole_api
[![Pylint](https://github.com/XelK/pihole_api/actions/workflows/pylint.yml/badge.svg)](https://github.com/XelK/pihole_api/actions/workflows/pylint.yml)[![Build test](https://github.com/XelK/pi_hole_api/actions/workflows/Build-main.yml/badge.svg)](https://github.com/XelK/pi_hole_api/actions/workflows/Build-main.yml)
Python api module for pi-hole server (https://pi-hole.net/).
Execute api calls to py-hole server from python code.## Installation
```python
# prod version:
pip install pi-hole-api# dev version:
pip install -i https://test.pypi.org/simple/ pi-hole-api
```## Examples
### Create class
```python
import pihole_api as pi
pihole = pi.Pihole("PI_URL", "PI_PSW")
```
where:
- PI_URL: url of pi-hole page
- PI_PSW: password of pi-holeor using environment variables "PI_URL" and "PI_PSW" set to pi-hole url and pi-hole password respectively:
```python
import os
from dotenv import load_dotenv
import pihole_api as pi
pihole = pi.Pihole(os.environ["PI_URL"], os.environ["PI_PSW"])
```
### Core module
Permit:
- enable/disable protection
```python
pihole.enable()
pihole.disable()
pihole.disable(30) # disable per 30 seconds
```
### Dns module
Permit:
- list dns records
- add/remove A record
- add/remove CNAME record
```python
pihole.dns("get") # print dns list
pihole.cname("get") # print cname list
# add domain to dns
pihole.dns("add", ip_address="1.1.1.1",domain="pippo.com"))
# remove domain to dns
pihole.dns("delete", ip_address="1.1.1.1",domain="pippo.com"))
# add cname from pippo.com to pluto.com
pihole.cname("add","pippo.com","pluto.com"))
# remove cname
pihole.cname("delete","pippo.com","pluto.com"))
```## List module
Permit:
- list/add/change/remove domains to white lists
- list/add/change/remove domains to black lists
```python
# get white list
pihole.get_domains("white")
# add to white list
pihole.add_domain("white","pippo.it","add pippo")
# replace in white list
pihole.replace_domain("white","pippo.it","replace pippo")
# delete from white list
pihole.delete_domain("white","pippo.it","delete pippo")# get black list
pihole.get_domains("black")
# add to black list
pihole.add_domain("black","pippo.it","add pippo")
# add change in black list
pihole.replace_domain("black","pippo.it","replace pippo")
# delete from black list
pihole.delete_domain("black","pippo.it","delete pippo")
```