async_fmg
High-level FortiManager object API.
AsyncFMG #
Bases: AsyncFMGBase
High-level asynchronous FortiManager client.
Accepts configuration models and execution objects, constructs API requests, and returns bound models from high-level GET operations. Dictionary requests remain supported for endpoints without models. Use an authenticated connection context for object operations.
Install the async extra and await requests and operations on bound objects. Constructing or binding an object with get_obj() does not require awaiting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
FMGSettings
|
Connection settings; when supplied, takes precedence over keyword settings |
None
|
Other Parameters:
| Name | Type | Description |
|---|---|---|
base_url |
str
|
Base URL to access FMG (e.g.: https://myfmg) |
username |
str
|
User to authenticate |
password |
str
|
Password for authentication |
adom |
str
|
ADOM to use for this connection |
verify |
bool
|
Verify SSL certificate (REQUESTS_CA_BUNDLE can set accepted CA cert) |
timeout |
float
|
Connect/read inactivity timeout per transport attempt, in seconds |
raise_on_error |
bool
|
Raise exception on error |
discard_on_close |
bool
|
Discard changes after connection close (workspace mode) |
discard_on_error |
bool
|
Discard changes when exception occurs (workspace mode) |
Source code in pyfortinet/fmg_api/async_fmg.py
add
async
#
add(request: MULTI_REQUEST_ARG) -> AsyncFMGResponse
Create configuration objects in FortiManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AsyncFMGResponse |
AsyncFMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server", subnet="192.0.2.10/32")
response = await fmg.add(address)
Source code in pyfortinet/fmg_api/async_fmg.py
clone
async
#
clone(request: REQUEST_ARG, *, create_task: bool = False, **new: str) -> AsyncFMGResponse
Clone one configuration object using new identity values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
REQUEST_ARG
|
Source model or raw clone request dictionary. |
required |
create_task
|
bool
|
Request a background task. Keep the connection open until it finishes. |
False
|
**new
|
str
|
New identity fields, usually name, matching the model's master keys. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
AsyncFMGResponse |
AsyncFMGResponse
|
Clone operation status, with task metadata when provided by FortiManager. |
Examples:
Inside an open connection, clone an existing address to an unused name:
from pyfortinet.fmg_api.firewall import Address
response = await fmg.clone(Address(name="example-server"), name="example-server-copy")
Source code in pyfortinet/fmg_api/async_fmg.py
delete
async
#
delete(request: MULTI_REQUEST_ARG) -> AsyncFMGResponse
Delete the identified configuration objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AsyncFMGResponse |
AsyncFMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server")
response = await fmg.delete(address)
Source code in pyfortinet/fmg_api/async_fmg.py
exec
async
#
Execute on FMG
Source code in pyfortinet/fmg_api/async_fmg.py
get
async
#
get(
request: Union[dict[str, Any], FMGObject, Type[FMGObject]],
filters: Union[str, FILTER_TYPE] = None,
scope: Optional[str] = None,
fields: Optional[List[str]] = None,
loadsub: bool = True,
options: Optional[List[GetOption]] = None,
**kwargs: Optional[Dict[str, str]],
) -> AsyncFMGResponse
Read objects from FortiManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Union[dict[str, Any], FMGObject, Type[FMGObject]]
|
Model class for a collection, initialized model for selection, or raw request dictionary. |
required |
filters
|
Union[str, FILTER_TYPE]
|
Filter expression as text or composed with F. |
None
|
scope
|
Optional[str]
|
Request scope; an explicit model scope takes precedence. |
None
|
fields
|
Optional[List[str]]
|
API field names to request, or None for all fields. |
None
|
loadsub
|
bool
|
Request nested tables. |
True
|
options
|
Optional[List[GetOption]]
|
Additional API GET options. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
AsyncFMGResponse |
AsyncFMGResponse
|
High-level data contains bound models. A successful empty lookup |
AsyncFMGResponse
|
has an empty data list and first() returns None. Dictionary requests retain raw results. |
Examples:
Use configured connection settings and handle an empty lookup:
from pyfortinet import AsyncFMG
from pyfortinet.fmg_api.common import F
from pyfortinet.fmg_api.firewall import Address
async with AsyncFMG(**config) as fmg:
response = await fmg.get(Address, F(name__like="server%"))
for address in response.data:
print(address.name, address.subnet)
server = (await fmg.get(Address(name="server1"))).first()
if server is not None:
print(server.name)
Source code in pyfortinet/fmg_api/async_fmg.py
get_adom_list
async
#
Gather adoms from FMG
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
FILTER_TYPE
|
filter as list or F object |
None
|
Returns:
| Type | Description |
|---|---|
Optional[List[str]]
|
list of adom strings or None in case of error |
Source code in pyfortinet/fmg_api/async_fmg.py
get_obj #
get_obj(obj: Union[Type[FMGObject], Type[FMGExecObject], AnyFMGObject], **kwargs: Any) -> AnyFMGObject
Construct or bind a local model to this client without an API request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Union[Type[FMGObject], Type[FMGExecObject], AnyFMGObject]
|
FMGObject or FMGExecObject class, or an existing instance. |
required |
**kwargs
|
Any
|
Initialization fields when obj is a class; ignored for existing instances. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
AnyFMGObject |
AnyFMGObject
|
A new instance for a class argument, or the same bound instance for an object argument. |
Examples:
This method is synchronous for both clients. Creating the model does not create the remote object:
from pyfortinet.fmg_api.firewall import Address
address = fmg.get_obj(Address, name="example-server", subnet="192.0.2.10/32")
Source code in pyfortinet/fmg_api/async_fmg.py
refresh
async
#
Re-load data from FMG
Source code in pyfortinet/fmg_api/async_fmg.py
set
async
#
set(request: MULTI_REQUEST_ARG) -> AsyncFMGResponse
Submit a FortiManager SET operation for the supplied objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AsyncFMGResponse |
AsyncFMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server", subnet="192.0.2.10/32")
response = await fmg.set(address)
Source code in pyfortinet/fmg_api/async_fmg.py
update
async
#
update(request: MULTI_REQUEST_ARG) -> AsyncFMGResponse
Update supplied non-null configuration fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
MULTI_REQUEST_ARG
|
One model or dictionary, or a nonempty list containing only models or only dictionaries. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
AsyncFMGResponse |
AsyncFMGResponse
|
Operation status; read the object separately to obtain its resulting configuration. |
Notes
This operation writes configuration. Models use API aliases and omit None values. Empty lists are sent explicitly. Batch operations are not a transaction; partial writes may remain after a failure. Check firmware semantics before using SET for a resource.
Examples:
Inside an open connection, with the appropriate target and permissions:
from pyfortinet.fmg_api.firewall import Address
address = Address(name="example-server", comment="Application server")
response = await fmg.update(address)