hfortix_fortios.FortiObject

class hfortix_fortios.FortiObject(data, raw_envelope=None, response_time=None, request_info=None)[source]

Zero-maintenance wrapper for FortiOS API responses.

Provides clean attribute access to API response data with automatic flattening of member_table fields (lists of dicts with ‘name’ keys).

Features: - No schemas required - works with any FortiOS version - No code generation - same class for all endpoints - No maintenance - automatically handles new fields - Auto-flattening of member_table fields for clean access - Escape hatch via get_full() for raw data access - Access full API envelope via .raw property

Examples

>>> # From dict response
>>> data = {"name": "policy1", "srcaddr": [{"name": "addr1"}]}
>>> obj = FortiObject(data)
>>>
>>> # Clean attribute access
>>> obj.name
'policy1'
>>>
>>> # Auto-flattened member_table fields
>>> obj.srcaddr
['addr1']
>>>
>>> # Get raw data when needed
>>> obj.get_full('srcaddr')
[{'name': 'addr1'}]
>>>
>>> # Convert back to dict
>>> obj.to_dict()
{'name': 'policy1', 'srcaddr': [{'name': 'addr1'}]}
>>>
>>> # Access full API envelope
>>> obj.raw
{'http_status': 200, 'status': 'success', 'results': {...}}
Parameters:
  • data (dict) – Dictionary from FortiOS API response

  • raw_envelope (dict | None) – Optional full API response envelope (with http_status, results, etc.)

  • response_time (float | None)

  • request_info (dict | None)

__init__(data, raw_envelope=None, response_time=None, request_info=None)[source]

Initialize FortiObject with API response data.

Parameters:
  • data (dict) – Dictionary containing the API response fields

  • raw_envelope (dict | None) – Optional full API response envelope

  • response_time (float | None) – Optional response time in seconds (from HTTP request)

  • request_info (dict | None) – Optional HTTP request information (method, url, params, data)

Methods

__init__(data[, raw_envelope, ...])

Initialize FortiObject with API response data.

get(key[, default])

Get field value with optional default (dict-like interface).

get_full(name)

Get raw field value without automatic processing.

items()

Get all field name-value pairs (processed).

keys()

Get all field names.

to_dict()

Get the original dictionary data.

values()

Get all field values (processed).

Attributes

dict

Get the dictionary representation of the object.

fgt_action

API action performed (appears in some response types).

fgt_api_name

API endpoint name (e.g., 'address', 'policy', 'interface').

fgt_api_path

API path segment (e.g., 'firewall', 'system', 'user').

fgt_build

FortiOS firmware build number.

fgt_limit_reached

Whether the pagination limit was reached in a list query.

fgt_matched_count

Number of objects matching the query criteria.

fgt_mkey

FortiGate primary key (mkey) of created/modified object.

fgt_next_idx

Index for the next page in paginated results.

fgt_old_revision

FortiGate previous configuration revision number (before this change).

fgt_response_size

Number of objects returned in the response (for list operations).

fgt_revision

FortiGate configuration revision number.

fgt_revision_changed

Whether the configuration revision changed (indicates config was modified).

fgt_serial

FortiGate device serial number.

fgt_vdom

FortiGate virtual domain name from API response.

fgt_version

FortiOS version string (e.g., 'v7.6.5').

fmg_api_request

Alias for http_api_request when using FortiManager proxy.

fmg_id

FortiManager request ID.

fmg_proxy_status_code

FortiManager proxy status code for this request.

fmg_proxy_status_message

FortiManager proxy status message for this request.

fmg_proxy_target

Target device name in FortiManager proxy request.

fmg_proxy_url

FortiManager proxy URL used for this request.

fmg_raw

Raw FortiManager response data.

fmg_status_code

FortiManager status code for the device response.

fmg_status_message

FortiManager status message for the device response.

fmg_url

FortiGate API URL called through FortiManager.

http_api_request

HTTP API request information for this response.

http_method

HTTP method used (GET, POST, PUT, DELETE).

http_response_time

Response time in milliseconds for this API request.

http_stats

HTTP request/response statistics summary.

http_status

API response status ('success' or 'error').

http_status_code

HTTP status code (200, 404, 500, etc.).

json

Get pretty-printed JSON string of the object.

raw

Get the raw/full API response envelope.