A simple Python wrapper for the OPNsense REST API.
Forked from mtrinish/pyopnsense and modeled after proxmoxer/proxmoxer.
The purpose of this library is also to extend the existing OPNsense API reference. Each endpoint that has been implemented in this library has a corresponding docstring with a brief explanation of what the endpoint does. Additionally, POST requests that require payloads include the corresponding JSON payloads that are required and other relevant information.
pip install pyopn
In order to access the OPNsense API you first need to generate an API key.
from pyopn import OPNsenseAPI
opn = OPNsenseAPI("https://192.168.199.1", api_key_file="OPNsense.localdomain_apikey.txt")
print(opn.kea.dhcpv4.search_reservation())
The endpoints are organized as opn.module.controller.command(param1, param2, data)
. Anytime camel case is used in the endpoint names, this wrapper uses snake case.
Parameters are passed in as arguments and are positioned in the order of they appear in the OPNsense API reference. If an endpoint accepts a JSON payload, the function will have a data
arguement in the last position where you can pass in a Python dictionary.
Ex: kea/dhcpv4/setSubnet
--> opn.kea.dhcpv4.set_subnet(uuid, data)
(Kea API Reference)
Below is a checklist of core OPNsense API modules. Checked off modules are completed
- Captiveportal
- Core
- Cron
- Dhcp
- Dhcpv4
- Dhcpv6
- Dhcrelay
- Diagnostics
- Firewall
- Firmware
- Ids
- Interfaces
- Ipsec
- Kea
- Menu
- Monit
- Openvpn
- Proxy
- Routes
- Routing
- Syslog
- Trafficshaper
- Trust
- Unbound
- Wireguard
Feel free to contribute to the library if there are missing endpoints you need. See CONTRIBUTING.md for guidelines and a quick tutorial on how to add new endpoints.
This project is licensed under the GPL-3.0 license - see the LICENSE file for details