Skip to content

A simple Python wrapper for the OPNsense REST API.

License

Notifications You must be signed in to change notification settings

alexchristy/PyOPN

 
 

Repository files navigation

PyOPN

Code style: black Ruff Auto Release Checked with mypy tests PyPI version

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.

Installation

pip install pyopn

Usage

Prerequisites

In order to access the OPNsense API you first need to generate an API key.

Example

from pyopn import OPNsenseAPI

opn = OPNsenseAPI("https://192.168.199.1", api_key_file="OPNsense.localdomain_apikey.txt")

print(opn.kea.dhcpv4.search_reservation())

Structure

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)

Implementation Checklist

Below is a checklist of core OPNsense API modules. Checked off modules are completed

Contributing

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.

License

This project is licensed under the GPL-3.0 license - see the LICENSE file for details

Acknowledgments

  • mtreinish for original code base this project was forked from
  • proxmoxer for the design pattern

About

A simple Python wrapper for the OPNsense REST API.

Resources

License

Stars

Watchers

Forks

Languages

  • Python 100.0%