Skip to main content

Simple Python client for SonicWall SonicOS REST API (with HTTP Digest Auth).

Project description

SonicWall API Python Client

A simple Python client for interacting with the SonicWall SonicOS REST API, using HTTP Digest Authentication.

Features

  • Login / logout to the SonicOS API
  • Check and manage pending configurations
  • Generic requests (GET, POST, PUT, PATCH, DELETE)
  • Persistent session support via requests.Session()

Installation

Install the package from PyPI:

pip install sonicwall-api-client

Import

from sonicwall_api_client import SonicWallClient

Examples

Initialize the client

# Initialize the client (with optional TFA code)
client = SonicWallClient(
    ip="192.168.1.1",
    port=443,
    username="admin",
    password="password"
    tfa="123456"  # optional, only if TFA is enabled
)

Note
The tfa argument is optional and should only be provided if the SonicWall firewall is configured with Two-Factor Authentication (TFA/2FA).
If TFA is not required, you can omit this argument.

Connect to the firewall

# Log in
success, message, _ = client.login()
if success:
    print("Login successful.")
else:
    print(f"Login failed: {message}")

Check pending configurations

success, message, data = client.get_pending_configurations()
if success:
    print("Pending configurations:", data)
else:
    print(f"Error: {message}")

Commit configurations

success, message, _ = client.commit()
if success:
    print("Configurations committed successfully.")
else:
    print(f"Commit error: {message}")

Discard pending configurations

success, message, _ = client.delete_pending_configurations()
if success:
    print("Pending changes discarded.")
else:
    print(f"Error: {message}")

Generic request

# Without payload
success, message, data = client.request("get", "/zones")
if success:
    print("Zones list:", data)
else:
    print(f"Request error: {message}")

# With payload
payload = {
    "zones": [
        {
            "name": "LAN_IT",
            "security_type": "public",
            "interface_trust": False,
            "auto_generate_access_rules": {
                "allow_from_to_equal": False,
                "allow_from_higher": False,
                "allow_to_lower": False,
                "deny_from_lower": False
            },
        }
    ]
}

success, message, _ = client.request("post", "/zones", payload)
if success:
    print("Object created successfully.")
else:
    print(f"Creation error: {message}")

Logout

success, message, _ = client.logout()
if success:
    print("Logged out successfully.")
else:
    print(f"Logout error: {message}")

License

MIT

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

sonicwall_api_client-1.0.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sonicwall_api_client-1.0.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file sonicwall_api_client-1.0.3.tar.gz.

File metadata

  • Download URL: sonicwall_api_client-1.0.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for sonicwall_api_client-1.0.3.tar.gz
Algorithm Hash digest
SHA256 eb27530c31569dc6ff287716873f0d35311e378507ed655fb0c74e8fffc1cbe5
MD5 89e1dde45f2bc535b65ed1b84d607640
BLAKE2b-256 74c1c0de1a36cf20aa563fde878e8e95cc27107314f8ee4fac960d19f332c9ad

See more details on using hashes here.

File details

Details for the file sonicwall_api_client-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sonicwall_api_client-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78b1d6e5c4052a01c1945494b0dc83039ec14769b0c308d2f822003bd71915c6
MD5 cc159338cce529a5fcb0d4363b9a91cd
BLAKE2b-256 96307383675a72fd6681a3f7bc9886a651eb0d13cd2b30f1d8e9419533bd74a4

See more details on using hashes here.

Supported by

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