.. image:: https://img.shields.io/pypi/v/fortigate-api.svg
:target: https://pypi.python.org/pypi/fortigate-api
.. image:: https://img.shields.io/pypi/pyversions/fortigate-api.svg
:target: https://pypi.python.org/pypi/fortigate-api
.. image:: https://img.shields.io/github/last-commit/vladimirs-git/fortigate-api
:target: https://pypi.python.org/pypi/fortigate-api
fortigate-api
=============
Python package to configure Fortigate (Fortios) devices using REST API.
- FortiGateAPI - Python connector to Fortigate API endpoints.
- FortiGate - Python wrapper for the FortiOS REST API.
Checked with FortiOS = v6.4.14.
Fully documented on `Read the Docs`_.
----------------------------------------------------------------------------------------
Quickstart
==========
Install the package from pypi.org
.. code:: bash
pip install fortigate-api
or from github.com repository
.. code:: bash
pip install git+https://github.com/vladimirs-git/fortigate-api
----------------------------------------------------------------------------------------
.. code:: python
"""Quickstart FortiGateAPI.
- Create address in the Fortigate
- Get all addresses from the Fortigate vdom root
- Get address by name (unique identifier)
- Filter address by operator contains `=@`
- Update address data in the Fortigate
- Delete address from the Fortigate
"""
from pprint import pprint
from fortigate_api import FortiGateAPI
HOST = "host"
USERNAME = "username"
PASSWORD = "password"
api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)
# Create address in the Fortigate
data = {
"name": "ADDRESS",
"obj-type": "ip",
"subnet": "127.0.0.100 255.255.255.252",
"type": "ipmask",
}
response = api.cmdb.firewall.address.create(data)
print(f"address.create {response}") # address.create <Response [200]>
# Get all addresses from the Fortigate vdom root
items = api.cmdb.firewall.address.get()
print(f"All addresses count={len(items)}") # All addresses count=14
# Get address by name (unique identifier)
items = api.cmdb.firewall.address.get(name="ADDRESS")
print(f"addresses count={len(items)}") # addresses count=1
pprint(items)
# [{"comment": "",
# "name": "ADDRESS",
# "subnet": "127.0.0.100 255.255.255.252",
# "uuid": "a386e4b0-d6cb-51ec-1e28-01e0bc0de43c",
# ...
# }]
# Filter address by operator contains `=@`
items = api.cmdb.firewall.address.get(filter="subnet=@127.0")
print(f"Filtered by `=@`, count={len(items)}") # Filtered by `=@`, count=2
# Update address data in the Fortigate
data = {"name": "ADDRESS", "subnet": "127.0.0.255 255.255.255.255"}
response = api.cmdb.firewall.address.update(data)
print(f"address.update {response}") # address.update <Response [200]>
# Delete address from the Fortigate
response = api.cmdb.firewall.address.delete("ADDRESS")
print(f"address.delete {response}") # address.delete <Response [200]>
api.logout()
.. code:: python
"""Quickstart FortiGate.
- Creates address in the Fortigate
- Get address by name (unique identifier)
- Updates address data in the Fortigate
- Delete address from the Fortigate
"""
from pprint import pprint
from fortigate_api import FortiGate
HOST = "host"
USERNAME = "username"
PASSWORD = "password"
fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD)
# Creates address in the Fortigate
data = {
"name": "ADDRESS",
"obj-type": "ip",
"subnet": "127.0.0.100 255.255.255.252",
"type": "ipmask",
}
response = fgt.post(url="api/v2/cmdb/firewall/address/", data=data)
print(f"POST {response}", ) # POST <Response [200]>
# Get address by name (unique identifier)
response = fgt.get(url="api/v2/cmdb/firewall/address/ADDRESS")
print(f"GET {response}", ) # POST <Response [200]>
result = response.json()["results"]
pprint(result)
# [{"name": "ADDRESS",
# "subnet": "127.0.0.100 255.255.255.252",
# "uuid": "a386e4b0-d6cb-51ec-1e28-01e0bc0de43c",
# ...
# }]
# Updates address data in the Fortigate
data = {"name": "ADDRESS", "subnet": "127.0.0.255 255.255.255.255"}
response = fgt.put(url="api/v2/cmdb/firewall/address/ADDRESS", data=data)
print(f"PUT {response}") # PUT <Response [200]>
# Delete address from the Fortigate
response = fgt.delete(url="api/v2/cmdb/firewall/address/ADDRESS")
print(f"DELETE {response}", ) # DELETE <Response [200]>
fgt.logout()
----------------------------------------------------------------------------------------
.. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/
Raw data
{
"_id": null,
"home_page": "https://github.com/vladimirs-git/fortigate-api",
"name": "fortigate-api",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "fortigate, fortios, rest, api",
"author": "Vladimirs Prusakovs",
"author_email": "vladimir.prusakovs@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/cf/38/73928831e9bc6fcd79c23fda6e35313f81071c07794816a451cc7d64e704/fortigate_api-2.0.2.tar.gz",
"platform": null,
"description": "\n.. image:: https://img.shields.io/pypi/v/fortigate-api.svg\n :target: https://pypi.python.org/pypi/fortigate-api\n.. image:: https://img.shields.io/pypi/pyversions/fortigate-api.svg\n :target: https://pypi.python.org/pypi/fortigate-api\n.. image:: https://img.shields.io/github/last-commit/vladimirs-git/fortigate-api\n :target: https://pypi.python.org/pypi/fortigate-api\n\n\nfortigate-api\n=============\n\nPython package to configure Fortigate (Fortios) devices using REST API.\n\n - FortiGateAPI - Python connector to Fortigate API endpoints.\n - FortiGate - Python wrapper for the FortiOS REST API.\n\nChecked with FortiOS = v6.4.14.\nFully documented on `Read the Docs`_.\n\n\n----------------------------------------------------------------------------------------\n\nQuickstart\n==========\n\nInstall the package from pypi.org\n\n.. code:: bash\n\n pip install fortigate-api\n\nor from github.com repository\n\n.. code:: bash\n\n pip install git+https://github.com/vladimirs-git/fortigate-api\n\n----------------------------------------------------------------------------------------\n\n.. code:: python\n\n \"\"\"Quickstart FortiGateAPI.\n\n - Create address in the Fortigate\n - Get all addresses from the Fortigate vdom root\n - Get address by name (unique identifier)\n - Filter address by operator contains `=@`\n - Update address data in the Fortigate\n - Delete address from the Fortigate\n \"\"\"\n\n from pprint import pprint\n\n from fortigate_api import FortiGateAPI\n\n HOST = \"host\"\n USERNAME = \"username\"\n PASSWORD = \"password\"\n\n api = FortiGateAPI(host=HOST, username=USERNAME, password=PASSWORD)\n\n # Create address in the Fortigate\n data = {\n \"name\": \"ADDRESS\",\n \"obj-type\": \"ip\",\n \"subnet\": \"127.0.0.100 255.255.255.252\",\n \"type\": \"ipmask\",\n }\n response = api.cmdb.firewall.address.create(data)\n print(f\"address.create {response}\") # address.create <Response [200]>\n\n # Get all addresses from the Fortigate vdom root\n items = api.cmdb.firewall.address.get()\n print(f\"All addresses count={len(items)}\") # All addresses count=14\n\n # Get address by name (unique identifier)\n items = api.cmdb.firewall.address.get(name=\"ADDRESS\")\n print(f\"addresses count={len(items)}\") # addresses count=1\n pprint(items)\n # [{\"comment\": \"\",\n # \"name\": \"ADDRESS\",\n # \"subnet\": \"127.0.0.100 255.255.255.252\",\n # \"uuid\": \"a386e4b0-d6cb-51ec-1e28-01e0bc0de43c\",\n # ...\n # }]\n\n # Filter address by operator contains `=@`\n items = api.cmdb.firewall.address.get(filter=\"subnet=@127.0\")\n print(f\"Filtered by `=@`, count={len(items)}\") # Filtered by `=@`, count=2\n\n # Update address data in the Fortigate\n data = {\"name\": \"ADDRESS\", \"subnet\": \"127.0.0.255 255.255.255.255\"}\n response = api.cmdb.firewall.address.update(data)\n print(f\"address.update {response}\") # address.update <Response [200]>\n\n # Delete address from the Fortigate\n response = api.cmdb.firewall.address.delete(\"ADDRESS\")\n print(f\"address.delete {response}\") # address.delete <Response [200]>\n\n api.logout()\n\n\n.. code:: python\n\n \"\"\"Quickstart FortiGate.\n\n - Creates address in the Fortigate\n - Get address by name (unique identifier)\n - Updates address data in the Fortigate\n - Delete address from the Fortigate\n \"\"\"\n\n from pprint import pprint\n\n from fortigate_api import FortiGate\n\n HOST = \"host\"\n USERNAME = \"username\"\n PASSWORD = \"password\"\n\n fgt = FortiGate(host=HOST, username=USERNAME, password=PASSWORD)\n\n # Creates address in the Fortigate\n data = {\n \"name\": \"ADDRESS\",\n \"obj-type\": \"ip\",\n \"subnet\": \"127.0.0.100 255.255.255.252\",\n \"type\": \"ipmask\",\n }\n response = fgt.post(url=\"api/v2/cmdb/firewall/address/\", data=data)\n print(f\"POST {response}\", ) # POST <Response [200]>\n\n # Get address by name (unique identifier)\n response = fgt.get(url=\"api/v2/cmdb/firewall/address/ADDRESS\")\n print(f\"GET {response}\", ) # POST <Response [200]>\n result = response.json()[\"results\"]\n pprint(result)\n # [{\"name\": \"ADDRESS\",\n # \"subnet\": \"127.0.0.100 255.255.255.252\",\n # \"uuid\": \"a386e4b0-d6cb-51ec-1e28-01e0bc0de43c\",\n # ...\n # }]\n\n # Updates address data in the Fortigate\n data = {\"name\": \"ADDRESS\", \"subnet\": \"127.0.0.255 255.255.255.255\"}\n response = fgt.put(url=\"api/v2/cmdb/firewall/address/ADDRESS\", data=data)\n print(f\"PUT {response}\") # PUT <Response [200]>\n\n # Delete address from the Fortigate\n response = fgt.delete(url=\"api/v2/cmdb/firewall/address/ADDRESS\")\n print(f\"DELETE {response}\", ) # DELETE <Response [200]>\n\n fgt.logout()\n\n\n\n----------------------------------------------------------------------------------------\n\n.. _`Read the Docs`: https://fortigate-api.readthedocs.io/en/latest/\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Python package to configure Fortigate (Fortios) devices using REST API and SSH",
"version": "2.0.2",
"project_urls": {
"Bug Tracker": "https://github.com/vladimirs-git/fortigate-api/issues",
"Download URL": "https://github.com/vladimirs-git/fortigate-api/archive/refs/tags/2.0.2.tar.gz",
"Homepage": "https://github.com/vladimirs-git/fortigate-api",
"Repository": "https://github.com/vladimirs-git/fortigate-api"
},
"split_keywords": [
"fortigate",
" fortios",
" rest",
" api"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6a801e4d9cdd4d60816eab56aa725618c12f16a99e4bcc36020c5a0b32dd1e93",
"md5": "1e3400fe47ba6946cdb0ffb37def90b6",
"sha256": "ded5a782c8b84f99bcd1555963687e5f071274d6b3e80cc0231e25a283e9e409"
},
"downloads": -1,
"filename": "fortigate_api-2.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1e3400fe47ba6946cdb0ffb37def90b6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 3525890,
"upload_time": "2024-05-17T06:46:50",
"upload_time_iso_8601": "2024-05-17T06:46:50.903690Z",
"url": "https://files.pythonhosted.org/packages/6a/80/1e4d9cdd4d60816eab56aa725618c12f16a99e4bcc36020c5a0b32dd1e93/fortigate_api-2.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cf3873928831e9bc6fcd79c23fda6e35313f81071c07794816a451cc7d64e704",
"md5": "5d6cc7b32f8072d8c0c49eaebbd4d47a",
"sha256": "9544aac5f6041a49af8b65bd18a6f520823340303068357fb94ef0052c4bd7b0"
},
"downloads": -1,
"filename": "fortigate_api-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "5d6cc7b32f8072d8c0c49eaebbd4d47a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 3241438,
"upload_time": "2024-05-17T06:46:53",
"upload_time_iso_8601": "2024-05-17T06:46:53.931662Z",
"url": "https://files.pythonhosted.org/packages/cf/38/73928831e9bc6fcd79c23fda6e35313f81071c07794816a451cc7d64e704/fortigate_api-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-17 06:46:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "vladimirs-git",
"github_project": "fortigate-api",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "fortigate-api"
}