Skip to main content

You can see the full rendered docs at: http://pyopnsense.readthedocs.io/en/latest/

A python API client for the OPNsense API. This provides a python interface for interacting with the OPNsense API.

Installation

pyopnsense is available via pypi so all you need to do is run:

pip install -U pyopnsense

to get the latest pyopnsense release on your system. If you need to use a development version of pyopnsense you can clone the repo and install it locally with:

git clone https://github.com/mtreinish/pyopnsense && pip install -e pyopnsense

which will install pyopnsense in your python environment in editable mode for development.

Usage

To use pyopnsense you need a couple pieces of information, the API key and the API secret. Both can be created/found from the OPNsense web UI by navigating to: System->Access->Users under API keys.

More information on this can be found in the OPNsense documentation: https://docs.opnsense.org/development/how-tos/api.html

Once you have the API key and API secret you can use pyopnsense to interact with your OPNsense installation. You can do this by passing your credentials to a client class. For example:

from pyopnsense import diagnostics

api_key = 'XXXXXX'
api_secret = 'XXXXXXXXXXXXXXX'
opnsense_url = 'http://192.168.1.1/api'
timeout = 5

netinsight_client = diagnostics.NetworkInsightClient(
    api_key, api_secret, opnsense_url, timeout)

print(netinsight_client.get_interfaces())

which will print a dictionary mapping physical devices to their interface label.

This same formula can be used to access each individual API endpoint you need to access. The basic structure of the library is setup to roughly mirror the endpoint tree of the OPNsense API. Each client module maps to the base endpoint and then there is a client class in those modules for the next level up off that.

You can find more detail on how to use the clients in the API reference documentation found here:

http://pyopnsense.readthedocs.io/en/latest/api.html

Metadata

Release files for pyopnsense 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyopnsense 0.4.0
File Size Uploaded
pyopnsense-0.4.0.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyopnsense 0.4.0
File Interpreter ABI Platform
pyopnsense-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.4 kB

Release files / pyopnsense-0.4.0.tar.gz

Download URL pyopnsense-0.4.0.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dc32a556b3ad31ae79813bb9e7ba60a23469760acee69119dcbfbd80aa16f728
BLAKE2b-256 checksum
How to use checksums
d3081dc0e7948764c59635a560dfd14a15266a5efdb4e628ec737bcfb6a1d59e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pyopnsense-0.4.0-py3-none-any.whl

Download URL pyopnsense-0.4.0-py3-none-any.whl
Size 23.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d5ef9de0383a37f7c17e5b7011e345fccd965d0d4188faa155a884f689b0eb1
BLAKE2b-256 checksum
How to use checksums
822a2d444c937ca5d5e69cf56cbc4577f91f95027d48a5a80892bb1c096e1f49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page