Skip to main content

A python API client for OPNsense

Project description

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'

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

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

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

pyopnsense-0.3.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

pyopnsense-0.3.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file pyopnsense-0.3.0.tar.gz.

File metadata

  • Download URL: pyopnsense-0.3.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for pyopnsense-0.3.0.tar.gz
Algorithm Hash digest
SHA256 aa5cb816553bb6647b63eec5e7528aa9a1d17ce1d5a43f4cb58cc13f56d33a1b
MD5 e681819552dd1f29a62f17d22c026c5a
BLAKE2b-256 28ca712f71ad67c2f2eafde2b56c4d3d479d7b90902b03a31b55c9a0b872bc90

See more details on using hashes here.

File details

Details for the file pyopnsense-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyopnsense-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

File hashes

Hashes for pyopnsense-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 952f085d25bf51152390e3e876ba222be78766123707aaea485e7bf87944c06a
MD5 d5eff01369ae820822539bcd19f3b2ba
BLAKE2b-256 b0f226b40bec90e91396901b30a4ca382a4ed4d8b8a086e9a360d781bfac04cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page