Skip to content

IPAM

Networks, network containers, network views, IP addresses, VLANs, RIRs, super-hosts. Accessed via client.ipam.

Service

IpamService

IpamService(client: HttpClient)

Entry point for NIOS IPAM resources. Each resource is lazily constructed.

Initialise IpamService with an authenticated HTTP client.

Source code in src/ibx_nios_sdk/ipam/_service.py
def __init__(self, client: HttpClient) -> None:
    """Initialise IpamService with an authenticated HTTP client."""
    self._client = client

networkview cached property

networkview: NetworkviewResource

Entry point for NIOS IPAM network view resources.

network cached property

network: NetworkResource

Entry point for NIOS IPAM IPv4 network resources.

networkcontainer cached property

networkcontainer: NetworkcontainerResource

Entry point for NIOS IPAM IPv4 network container resources.

networktemplate cached property

networktemplate: NetworktemplateResource

Entry point for NIOS IPAM IPv4 network template resources.

ipv4address cached property

ipv4address: Ipv4addressResource

Entry point for NIOS IPAM IPv4 address resources.

ipv6network cached property

ipv6network: Ipv6networkResource

Entry point for NIOS IPAM IPv6 network resources.

ipv6networkcontainer cached property

ipv6networkcontainer: Ipv6networkcontainerResource

Entry point for NIOS IPAM IPv6 network container resources.

ipv6networktemplate cached property

ipv6networktemplate: Ipv6networktemplateResource

Entry point for NIOS IPAM IPv6 network template resources.

ipv6address cached property

ipv6address: Ipv6addressResource

Entry point for NIOS IPAM IPv6 address resources.

vlan cached property

vlan: VlanResource

Entry point for NIOS VLAN resources.

vlanview cached property

vlanview: VlanviewResource

Entry point for NIOS VLAN view resources.

vlanrange cached property

vlanrange: VlanrangeResource

Entry point for NIOS VLAN range resources.

bulkhost cached property

bulkhost: BulkhostResource

Entry point for NIOS IPAM bulk host resources.

bulkhostnametemplate cached property

bulkhostnametemplate: BulkhostnametemplateResource

Entry point for NIOS IPAM bulk host name template resources.

discovery_discoverytask cached property

discovery_discoverytask: DiscoverytaskResource

Entry point for NIOS network discovery task resources.

network_discovery cached property

network_discovery: NetworkDiscoveryResource

Entry point for NIOS network discovery result resources.

superhost cached property

superhost: SuperhostResource

Entry point for NIOS IPAM superhost resources.

superhostchild cached property

superhostchild: SuperhostchildResource

Entry point for NIOS IPAM superhost child resources.

hostnamerewritepolicy cached property

hostnamerewritepolicy: HostnamerewritepolicyResource

Entry point for NIOS IPAM hostname rewrite policy resources.

rir cached property

rir: RirResource

Entry point for NIOS Regional Internet Registry (RIR) resources.

rir_organization cached property

rir_organization: RirOrganizationResource

Entry point for NIOS RIR organization resources.

ipam_statistics cached property

ipam_statistics: IpamStatisticsResource

Entry point for NIOS IPAM statistics resources.

Resources

BulkhostResource

BulkhostResource(client: HttpClient)

Bases: WapiResource[Bulkhost]

Manage NIOS IPAM bulk host objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

BulkhostnametemplateResource

BulkhostnametemplateResource(client: HttpClient)

Bases: WapiResource[Bulkhostnametemplate]

Manage NIOS IPAM bulk host name templates.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

DiscoverytaskResource

DiscoverytaskResource(client: HttpClient)

Bases: WapiResource[Discoverytask]

Manage NIOS network discovery tasks.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

HostnamerewritepolicyResource

HostnamerewritepolicyResource(client: HttpClient)

Bases: WapiResource[Hostnamerewritepolicy]

Manage NIOS IPAM hostname rewrite policy configurations.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

IpamStatisticsResource

IpamStatisticsResource(client: HttpClient)

Bases: WapiResource[IpamStatistics]

Access NIOS IPAM statistics (read-only aggregate view).

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

Ipv4addressResource

Ipv4addressResource(client: HttpClient)

Bases: WapiResource[Ipv4address]

Manage NIOS IPAM IPv4 address objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

Ipv6addressResource

Ipv6addressResource(client: HttpClient)

Bases: WapiResource[Ipv6address]

Manage NIOS IPAM IPv6 address objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

Ipv6networkResource

Ipv6networkResource(client: HttpClient)

Bases: WapiResource[Ipv6network]

Manage NIOS IPAM IPv6 network objects with next_available_ip support.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

next_available_ip async

next_available_ip(ref: str, *, num: int = 1, exclude: list[str] | None = None) -> dict[str, Any]

Return the next available IPv6 address(es) within this IPv6 network.

Calls the WAPI next_available_ip function on the given IPv6 network ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference for the IPv6 network (e.g., "ipv6network/ZG5z...")

required
num int

Number of IPv6 addresses to allocate. Defaults to 1.

1
exclude list[str] | None

Optional list of IPv6 addresses to exclude from consideration.

None

Returns:

Name Type Description
dict[str, Any]

A dict with key "ips" containing a list of allocated IPv6 address strings.

Example dict[str, Any]

{"ips": ["2001:db8::5", "2001:db8::6"]}

Raises:

Type Description
WapiRequestError

If the WAPI call fails or no IPs are available.

Source code in src/ibx_nios_sdk/ipam/_ipv6network.py
async def next_available_ip(
    self,
    ref: str,
    *,
    num: int = 1,
    exclude: list[str] | None = None,
) -> dict[str, Any]:
    """Return the next available IPv6 address(es) within this IPv6 network.

    Calls the WAPI ``next_available_ip`` function on the given IPv6 network ref.

    Args:
        ref: The WAPI object reference for the IPv6 network
            (e.g., ``"ipv6network/ZG5z..."``)
        num: Number of IPv6 addresses to allocate. Defaults to 1.
        exclude: Optional list of IPv6 addresses to exclude from consideration.

    Returns:
        A dict with key ``"ips"`` containing a list of allocated IPv6 address strings.
        Example: ``{"ips": ["2001:db8::5", "2001:db8::6"]}``

    Raises:
        WapiRequestError: If the WAPI call fails or no IPs are available.
    """
    kwargs: dict[str, Any] = {"num": num}
    if exclude is not None:
        kwargs["exclude"] = exclude
    return await self.call_function(ref, "next_available_ip", **kwargs)

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

Ipv6networkcontainerResource

Ipv6networkcontainerResource(client: HttpClient)

Bases: WapiResource[Ipv6networkcontainer]

Manage NIOS IPAM IPv6 network containers with next_available_network support.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

next_available_network async

next_available_network(ref: str, *, cidr: int, num: int = 1, exclude: list[str] | None = None) -> dict[str, Any]

Carve out the next available IPv6 network(s) from this IPv6 container.

Calls the WAPI next_available_network function on the given container ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference for the IPv6 network container (e.g., "ipv6networkcontainer/ZG5z...")

required
cidr int

The prefix length for the new IPv6 network (e.g., 64 for /64).

required
num int

Number of networks to allocate. Defaults to 1.

1
exclude list[str] | None

Optional list of IPv6 network CIDRs to exclude from consideration.

None

Returns:

Name Type Description
dict[str, Any]

A dict with key "networks" containing a list of allocated IPv6 CIDR strings.

Example dict[str, Any]

{"networks": ["2001:db8::/64", "2001:db8:0:1::/64"]}

Raises:

Type Description
WapiRequestError

If the WAPI call fails or no networks are available.

Source code in src/ibx_nios_sdk/ipam/_ipv6networkcontainer.py
async def next_available_network(
    self,
    ref: str,
    *,
    cidr: int,
    num: int = 1,
    exclude: list[str] | None = None,
) -> dict[str, Any]:
    """Carve out the next available IPv6 network(s) from this IPv6 container.

    Calls the WAPI ``next_available_network`` function on the given container ref.

    Args:
        ref: The WAPI object reference for the IPv6 network container
            (e.g., ``"ipv6networkcontainer/ZG5z..."``)
        cidr: The prefix length for the new IPv6 network (e.g., 64 for /64).
        num: Number of networks to allocate. Defaults to 1.
        exclude: Optional list of IPv6 network CIDRs to exclude from consideration.

    Returns:
        A dict with key ``"networks"`` containing a list of allocated IPv6 CIDR strings.
        Example: ``{"networks": ["2001:db8::/64", "2001:db8:0:1::/64"]}``

    Raises:
        WapiRequestError: If the WAPI call fails or no networks are available.
    """
    kwargs: dict[str, Any] = {"cidr": cidr, "num": num}
    if exclude is not None:
        kwargs["exclude"] = exclude
    return await self.call_function(ref, "next_available_network", **kwargs)

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

Ipv6networktemplateResource

Ipv6networktemplateResource(client: HttpClient)

Bases: WapiResource[Ipv6networktemplate]

Manage NIOS IPAM IPv6 network templates.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

NetworkResource

NetworkResource(client: HttpClient)

Bases: WapiResource[Network]

Manage NIOS IPAM IPv4 network objects with next_available_ip support.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

next_available_ip async

next_available_ip(ref: str, *, num: int = 1, exclude: list[str] | None = None) -> dict[str, Any]

Return the next available IP address(es) within this IPv4 network.

Calls the WAPI next_available_ip function on the given network ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference for the network (e.g., "network/ZG5z...")

required
num int

Number of IP addresses to allocate. Defaults to 1.

1
exclude list[str] | None

Optional list of IP addresses to exclude from consideration.

None

Returns:

Name Type Description
dict[str, Any]

A dict with key "ips" containing a list of allocated IPv4 address strings.

Example dict[str, Any]

{"ips": ["192.168.1.5", "192.168.1.6"]}

Raises:

Type Description
WapiRequestError

If the WAPI call fails or no IPs are available.

Source code in src/ibx_nios_sdk/ipam/_network.py
async def next_available_ip(
    self,
    ref: str,
    *,
    num: int = 1,
    exclude: list[str] | None = None,
) -> dict[str, Any]:
    """Return the next available IP address(es) within this IPv4 network.

    Calls the WAPI ``next_available_ip`` function on the given network ref.

    Args:
        ref: The WAPI object reference for the network (e.g., ``"network/ZG5z..."``)
        num: Number of IP addresses to allocate. Defaults to 1.
        exclude: Optional list of IP addresses to exclude from consideration.

    Returns:
        A dict with key ``"ips"`` containing a list of allocated IPv4 address strings.
        Example: ``{"ips": ["192.168.1.5", "192.168.1.6"]}``

    Raises:
        WapiRequestError: If the WAPI call fails or no IPs are available.
    """
    kwargs: dict[str, Any] = {"num": num}
    if exclude is not None:
        kwargs["exclude"] = exclude
    return await self.call_function(ref, "next_available_ip", **kwargs)

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

NetworkDiscoveryResource

NetworkDiscoveryResource(client: HttpClient)

Bases: WapiResource[NetworkDiscovery]

Access NIOS network discovery results (read-only aggregate view).

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

NetworkcontainerResource

NetworkcontainerResource(client: HttpClient)

Bases: WapiResource[Networkcontainer]

Manage NIOS IPAM IPv4 network containers with next_available_network support.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

next_available_network async

next_available_network(ref: str, *, cidr: int, num: int = 1, exclude: list[str] | None = None) -> dict[str, Any]

Carve out the next available network(s) from this IPv4 container.

Calls the WAPI next_available_network function on the given container ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference for the network container (e.g., "networkcontainer/ZG5z...")

required
cidr int

The prefix length for the new network (e.g., 24 for /24).

required
num int

Number of networks to allocate. Defaults to 1.

1
exclude list[str] | None

Optional list of network CIDRs to exclude from consideration.

None

Returns:

Name Type Description
dict[str, Any]

A dict with key "networks" containing a list of allocated CIDR strings.

Example dict[str, Any]

{"networks": ["10.0.0.0/24", "10.0.1.0/24"]}

Raises:

Type Description
WapiRequestError

If the WAPI call fails or no networks are available.

Source code in src/ibx_nios_sdk/ipam/_networkcontainer.py
async def next_available_network(
    self,
    ref: str,
    *,
    cidr: int,
    num: int = 1,
    exclude: list[str] | None = None,
) -> dict[str, Any]:
    """Carve out the next available network(s) from this IPv4 container.

    Calls the WAPI ``next_available_network`` function on the given container ref.

    Args:
        ref: The WAPI object reference for the network container
            (e.g., ``"networkcontainer/ZG5z..."``)
        cidr: The prefix length for the new network (e.g., 24 for /24).
        num: Number of networks to allocate. Defaults to 1.
        exclude: Optional list of network CIDRs to exclude from consideration.

    Returns:
        A dict with key ``"networks"`` containing a list of allocated CIDR strings.
        Example: ``{"networks": ["10.0.0.0/24", "10.0.1.0/24"]}``

    Raises:
        WapiRequestError: If the WAPI call fails or no networks are available.
    """
    kwargs: dict[str, Any] = {"cidr": cidr, "num": num}
    if exclude is not None:
        kwargs["exclude"] = exclude
    return await self.call_function(ref, "next_available_network", **kwargs)

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

NetworktemplateResource

NetworktemplateResource(client: HttpClient)

Bases: WapiResource[Networktemplate]

Manage NIOS IPAM IPv4 network templates.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

NetworkviewResource

NetworkviewResource(client: HttpClient)

Bases: WapiResource[Networkview]

Manage NIOS IPAM network view objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

RirResource

RirResource(client: HttpClient)

Bases: WapiResource[Rir]

Manage NIOS Regional Internet Registry (RIR) configuration.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

RirOrganizationResource

RirOrganizationResource(client: HttpClient)

Bases: WapiResource[RirOrganization]

Manage NIOS RIR organizations.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

SuperhostResource

SuperhostResource(client: HttpClient)

Bases: WapiResource[Superhost]

Manage NIOS IPAM superhost objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

SuperhostchildResource

SuperhostchildResource(client: HttpClient)

Bases: WapiResource[Superhostchild]

Manage NIOS IPAM superhost child objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

VlanResource

VlanResource(client: HttpClient)

Bases: WapiResource[Vlan]

Manage NIOS VLAN objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

VlanrangeResource

VlanrangeResource(client: HttpClient)

Bases: WapiResource[Vlanrange]

Manage NIOS VLAN range objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})

VlanviewResource

VlanviewResource(client: HttpClient)

Bases: WapiResource[Vlanview]

Manage NIOS VLAN view objects.

Initialize the resource with an HTTP client.

Parameters:

Name Type Description Default
client HttpClient

The :class:~ibx_nios_sdk._http.HttpClient instance used to make WAPI requests.

required
Source code in src/ibx_nios_sdk/_resource.py
def __init__(self, client: HttpClient) -> None:
    """Initialize the resource with an HTTP client.

    Args:
        client: The :class:`~ibx_nios_sdk._http.HttpClient` instance used
            to make WAPI requests.
    """
    self._client = client

list_page async

list_page(*, page_id: str | None = None, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> tuple[list[TModel], str | None]

Fetch a single page of WAPI results.

Parameters:

Name Type Description Default
page_id str | None

Continuation token from a previous response. Pass None to start from the first page.

None
max_results int

Maximum number of records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields to add on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters using kwarg conventions (e.g. name="foo", comment__like="bar", extattr_Site="NYC").

{}

Returns:

Type Description
list[TModel]

A (rows, next_page_id) tuple. rows is a list of validated

str | None

model instances; next_page_id is the token for the next page, or

tuple[list[TModel], str | None]

None if this was the last page.

Raises:

Type Description
ValueError

If both return_fields and return_fields_plus are provided, or if an unknown filter operator suffix is used.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for WAPI errors.

Example

Fetch the first two pages manually::

rows, next_id = await resource.list_page(max_results=100)
if next_id:
    more, _ = await resource.list_page(page_id=next_id)
Source code in src/ibx_nios_sdk/_resource.py
async def list_page(
    self,
    *,
    page_id: str | None = None,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> tuple[list[TModel], str | None]:
    """Fetch a single page of WAPI results.

    Args:
        page_id: Continuation token from a previous response. Pass ``None``
            to start from the first page.
        max_results: Maximum number of records per page (WAPI
            ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields to add on top of
            ``_default_return_fields``; mutually exclusive with
            ``return_fields``.
        **filters: Field-level filters using kwarg conventions (e.g.
            ``name="foo"``, ``comment__like="bar"``,
            ``extattr_Site="NYC"``).

    Returns:
        A ``(rows, next_page_id)`` tuple. ``rows`` is a list of validated
        model instances; ``next_page_id`` is the token for the next page, or
        ``None`` if this was the last page.

    Raises:
        ValueError: If both ``return_fields`` and ``return_fields_plus`` are
            provided, or if an unknown filter operator suffix is used.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Fetch the first two pages manually::

            rows, next_id = await resource.list_page(max_results=100)
            if next_id:
                more, _ = await resource.list_page(page_id=next_id)
    """
    self._require_op("read")
    params: dict[str, str] = {
        "_paging": "1",
        "_return_as_object": "1",
        "_max_results": str(max_results),
    }
    params.update(build_filter_params(filters))
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    if page_id:
        params["_page_id"] = page_id

    data = await self._client.get(self._path(), params=params)
    body = data or {}
    rows = body.get("result", []) or []
    next_id = body.get("next_page_id") or None
    parsed = [self._model.model_validate(row) for row in rows]
    return parsed, next_id  # type: ignore[return-value]

list

list(*, max_results: int = 1000, return_fields: list[str] | None = None, return_fields_plus: list[str] | None = None, **filters: Any) -> AsyncPageIterator[TModel]

Return an auto-paginated async iterator over all matching objects.

Fetches pages on demand as the caller iterates. Use await .all() on the returned iterator to collect every record into a list at once.

Parameters:

Name Type Description Default
max_results int

Maximum records per page (WAPI _max_results).

1000
return_fields list[str] | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus list[str] | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Name Type Description
An AsyncPageIterator[TModel]

class:~ibx_nios_sdk._paging.AsyncPageIterator that yields

AsyncPageIterator[TModel]

validated model instances across all pages.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support reads of this object type. Raised by this call, not by the first iteration.

Example

Iterate lazily::

async for record in resource.list(name="example"):
    print(record.ref)

Collect all at once::

records = await resource.list(comment__like="prod").all()
Source code in src/ibx_nios_sdk/_resource.py
def list(
    self,
    *,
    max_results: int = 1000,
    return_fields: list[str] | None = None,
    return_fields_plus: list[str] | None = None,
    **filters: Any,
) -> AsyncPageIterator[TModel]:
    """Return an auto-paginated async iterator over all matching objects.

    Fetches pages on demand as the caller iterates. Use ``await .all()``
    on the returned iterator to collect every record into a list at once.

    Args:
        max_results: Maximum records per page (WAPI ``_max_results``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        An :class:`~ibx_nios_sdk._paging.AsyncPageIterator` that yields
        validated model instances across all pages.

    Raises:
        UnsupportedOperationError: If WAPI does not support reads of this
            object type. Raised by this call, not by the first iteration.

    Example:
        Iterate lazily::

            async for record in resource.list(name="example"):
                print(record.ref)

        Collect all at once::

            records = await resource.list(comment__like="prod").all()
    """

    self._require_op("read")

    async def _fetch(page_id: str | None) -> tuple[list[dict[str, Any]], str | None]:
        params: dict[str, str] = {
            "_paging": "1",
            "_return_as_object": "1",
            "_max_results": str(max_results),
        }
        params.update(build_filter_params(filters))
        params.update(
            build_return_fields_params(
                model_fields=self._default_return_fields,
                return_fields=return_fields,
                return_fields_plus=return_fields_plus,
            )
        )
        if page_id:
            params["_page_id"] = page_id
        data = await self._client.get(self._path(), params=params)
        body = data or {}
        return body.get("result", []) or [], body.get("next_page_id") or None

    return AsyncPageIterator(fetch=_fetch, model=self._model)  # type: ignore[arg-type]

find_one async

find_one(*, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None, **filters: Any) -> TModel | None

Return the first matching object, or None if no match is found.

Requests at most one result (max_results=1) to minimise data transfer.

Parameters:

Name Type Description Default
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None
**filters Any

Field-level filters (see :func:build_filter_params).

{}

Returns:

Type Description
TModel | None

The first matching validated model instance, or None if the

TModel | None

WAPI returns an empty result set.

Raises:

Type Description
NiosError

Or a subclass for WAPI errors.

Example

Look up a record by name::

record = await resource.find_one(name="foo.example.com")
if record is None:
    print("not found")
Source code in src/ibx_nios_sdk/_resource.py
async def find_one(
    self,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
    **filters: Any,
) -> TModel | None:
    """Return the first matching object, or None if no match is found.

    Requests at most one result (``max_results=1``) to minimise data
    transfer.

    Args:
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.
        **filters: Field-level filters (see :func:`build_filter_params`).

    Returns:
        The first matching validated model instance, or ``None`` if the
        WAPI returns an empty result set.

    Raises:
        NiosError: Or a subclass for WAPI errors.

    Example:
        Look up a record by name::

            record = await resource.find_one(name="foo.example.com")
            if record is None:
                print("not found")
    """
    rows, _ = await self.list_page(
        max_results=1,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
        **filters,
    )
    return rows[0] if rows else None

get async

get(ref: str, *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Fetch a single WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

The WAPI object reference string (e.g. "record:a/ZG5z...:1.2.3.4/default").

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the requested object.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support reads of this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Fetch a record by ref::

record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
print(record.ipv4addr)
Source code in src/ibx_nios_sdk/_resource.py
async def get(
    self,
    ref: str,
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Fetch a single WAPI object by its ``_ref``.

    Args:
        ref: The WAPI object reference string (e.g.
            ``"record:a/ZG5z...:1.2.3.4/default"``).
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the requested object.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support reads of this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Fetch a record by ref::

            record = await resource.get("record:a/ZG5z...:1.2.3.4/default")
            print(record.ipv4addr)
    """
    self._require_op("read")
    self._validate_ref(ref)
    params = build_return_fields_params(
        model_fields=self._default_return_fields,
        return_fields=return_fields,
        return_fields_plus=return_fields_plus,
    )
    data = await self._client.get(f"/{ref}", params=params or None)
    return self._model.model_validate(data or {})  # type: ignore[return-value]

create async

create(obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Create a new WAPI object and return the populated model.

Parameters:

Name Type Description Default
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict containing the fields for the new object. None values and the ref field are excluded from the POST body automatically.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance for the newly created object, populated

TModel

with the fields requested via _return_as_object=1.

Raises:

Type Description
UnsupportedOperationError

If WAPI does not support creating this object type.

ConflictError

If the object already exists.

BadRequestError

If the request body contains invalid fields.

NiosError

Or a subclass for other WAPI errors.

Example

Create an A record::

record = await resource.create(
    {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
)
print(record.ref)
Source code in src/ibx_nios_sdk/_resource.py
async def create(
    self,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Create a new WAPI object and return the populated model.

    Args:
        obj: A Pydantic model instance or plain dict containing the fields
            for the new object. ``None`` values and the ``ref`` field are
            excluded from the POST body automatically.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance for the newly created object, populated
        with the fields requested via ``_return_as_object=1``.

    Raises:
        UnsupportedOperationError: If WAPI does not support creating this
            object type.
        ConflictError: If the object already exists.
        BadRequestError: If the request body contains invalid fields.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Create an A record::

            record = await resource.create(
                {"name": "host.example.com", "ipv4addr": "1.2.3.4"}
            )
            print(record.ref)
    """
    self._require_op("create")
    payload = self._dump(obj, exclude_readonly=False)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.post(self._path(), params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

update async

update(ref: str, obj: BaseModel | dict[str, Any], *, return_fields: _StrList | None = None, return_fields_plus: _StrList | None = None) -> TModel

Update an existing WAPI object and return the refreshed model.

Sends a PUT request with _return_as_object=1. Read-only fields listed in _readonly_fields are stripped from the payload automatically.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to update.

required
obj BaseModel | dict[str, Any]

A Pydantic model instance or plain dict of fields to update. None values, ref, and read-only fields are excluded.

required
return_fields _StrList | None

Exact list of fields to return; mutually exclusive with return_fields_plus.

None
return_fields_plus _StrList | None

Extra fields on top of _default_return_fields; mutually exclusive with return_fields.

None

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object no longer exists in NIOS.

UnsupportedOperationError

If WAPI does not support updating this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Change the comment on a host record::

updated = await resource.update(
    "record:host/ZG5z...",
    {"comment": "updated by SDK"},
)
Source code in src/ibx_nios_sdk/_resource.py
async def update(
    self,
    ref: str,
    obj: BaseModel | dict[str, Any],
    *,
    return_fields: _StrList | None = None,
    return_fields_plus: _StrList | None = None,
) -> TModel:
    """Update an existing WAPI object and return the refreshed model.

    Sends a PUT request with ``_return_as_object=1``. Read-only fields
    listed in ``_readonly_fields`` are stripped from the payload
    automatically.

    Args:
        ref: WAPI object reference string identifying the object to update.
        obj: A Pydantic model instance or plain dict of fields to update.
            ``None`` values, ``ref``, and read-only fields are excluded.
        return_fields: Exact list of fields to return; mutually exclusive
            with ``return_fields_plus``.
        return_fields_plus: Extra fields on top of ``_default_return_fields``;
            mutually exclusive with ``return_fields``.

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object no longer exists in NIOS.
        UnsupportedOperationError: If WAPI does not support updating this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Change the comment on a host record::

            updated = await resource.update(
                "record:host/ZG5z...",
                {"comment": "updated by SDK"},
            )
    """
    self._require_op("update")
    self._validate_ref(ref)
    payload = self._dump(obj, exclude_readonly=True)
    params: dict[str, str] = {"_return_as_object": "1"}
    params.update(
        build_return_fields_params(
            model_fields=self._default_return_fields,
            return_fields=return_fields,
            return_fields_plus=return_fields_plus,
        )
    )
    data = await self._client.put(f"/{ref}", params=params, json=payload)
    if isinstance(data, dict) and list(data) == ["result"]:
        data = data["result"]
    return self._model.model_validate(data or {})  # type: ignore[return-value]

delete async

delete(ref: str) -> str

Delete a WAPI object by its _ref.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the object to delete.

required

Returns:

Type Description
str

The _ref of the deleted object as returned by NIOS, which may

str

differ from the input ref in some WAPI versions. Falls back to

str

the input ref if NIOS does not return a value.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NotFoundError

If the object does not exist in NIOS.

UnsupportedOperationError

If WAPI does not support deleting this object type.

NiosError

Or a subclass for other WAPI errors.

Example

Delete an A record::

deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
Source code in src/ibx_nios_sdk/_resource.py
async def delete(self, ref: str) -> str:
    """Delete a WAPI object by its ``_ref``.

    Args:
        ref: WAPI object reference string identifying the object to delete.

    Returns:
        The ``_ref`` of the deleted object as returned by NIOS, which may
        differ from the input ``ref`` in some WAPI versions. Falls back to
        the input ``ref`` if NIOS does not return a value.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NotFoundError: If the object does not exist in NIOS.
        UnsupportedOperationError: If WAPI does not support deleting this
            object type.
        NiosError: Or a subclass for other WAPI errors.

    Example:
        Delete an A record::

            deleted_ref = await resource.delete("record:a/ZG5z...:1.2.3.4/default")
    """
    self._require_op("delete")
    self._validate_ref(ref)
    data = await self._client.delete(f"/{ref}")
    if isinstance(data, dict) and "_value" in data:
        return str(data["_value"])
    return ref

call_function async

call_function(ref: str | None, function: str, **kwargs: Any) -> dict[str, Any]

Call a WAPI function on a specific object or on the object type.

Uses POST /<ref>?_function=<name> when ref is provided, or POST /<wapi_type>?_function=<name> for type-level functions. None kwarg values are excluded from the request body.

Parameters:

Name Type Description Default
ref str | None

WAPI object reference, or None to call a type-level function.

required
function str

WAPI function name (e.g. "nextavailableip").

required
**kwargs Any

Function arguments passed as the POST body.

{}

Returns:

Type Description
dict[str, Any]

The parsed JSON response body from the function call as a dict

dict[str, Any]

(empty dict if the WAPI returns no body).

Raises:

Type Description
ValueError

If ref is provided but does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Find the next available IP in a network::

result = await resource.call_function(
    "network/ZG5z...",
    "nextavailableip",
    num=1,
)
print(result["ips"])
Source code in src/ibx_nios_sdk/_resource.py
async def call_function(
    self,
    ref: str | None,
    function: str,
    **kwargs: Any,
) -> dict[str, Any]:
    """Call a WAPI function on a specific object or on the object type.

    Uses ``POST /<ref>?_function=<name>`` when ``ref`` is provided, or
    ``POST /<wapi_type>?_function=<name>`` for type-level functions.
    ``None`` kwarg values are excluded from the request body.

    Args:
        ref: WAPI object reference, or ``None`` to call a type-level
            function.
        function: WAPI function name (e.g. ``"nextavailableip"``).
        **kwargs: Function arguments passed as the POST body.

    Returns:
        The parsed JSON response body from the function call as a dict
        (empty dict if the WAPI returns no body).

    Raises:
        ValueError: If ``ref`` is provided but does not belong to this
            resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Find the next available IP in a network::

            result = await resource.call_function(
                "network/ZG5z...",
                "nextavailableip",
                num=1,
            )
            print(result["ips"])
    """
    if ref is not None:
        self._validate_ref(ref)
        path = f"/{ref}"
    else:
        path = self._path()
    params = {"_function": function}
    body = {k: v for k, v in kwargs.items() if v is not None}
    data = await self._client.post(path, params=params, json=body or None)
    return data or {}

set_extattrs async

set_extattrs(ref: str, **kwargs: Any) -> TModel

Set extensible attributes on a WAPI object.

Wraps kwarg key/value pairs into the WAPI extattrs nested shape ({"<name>": {"value": <val>}}) and delegates to :meth:update.

Parameters:

Name Type Description Default
ref str

WAPI object reference string identifying the target object.

required
**kwargs Any

Extensible-attribute name/value pairs to set (e.g. Site="NYC", Owner="ops-team").

{}

Returns:

Type Description
TModel

A validated model instance reflecting the object's state after the

TModel

update.

Raises:

Type Description
ValueError

If ref does not belong to this resource type.

NiosError

Or a subclass for WAPI errors.

Example

Tag a host record with a site attribute::

updated = await resource.set_extattrs(
    "record:host/ZG5z...",
    Site="NYC",
    Owner="ops-team",
)
Source code in src/ibx_nios_sdk/_resource.py
async def set_extattrs(self, ref: str, **kwargs: Any) -> TModel:
    """Set extensible attributes on a WAPI object.

    Wraps kwarg key/value pairs into the WAPI ``extattrs`` nested shape
    (``{"<name>": {"value": <val>}}``) and delegates to
    :meth:`update`.

    Args:
        ref: WAPI object reference string identifying the target object.
        **kwargs: Extensible-attribute name/value pairs to set (e.g.
            ``Site="NYC"``, ``Owner="ops-team"``).

    Returns:
        A validated model instance reflecting the object's state after the
        update.

    Raises:
        ValueError: If ``ref`` does not belong to this resource type.
        NiosError: Or a subclass for WAPI errors.

    Example:
        Tag a host record with a site attribute::

            updated = await resource.set_extattrs(
                "record:host/ZG5z...",
                Site="NYC",
                Owner="ops-team",
            )
    """
    extattrs = {name: {"value": value} for name, value in kwargs.items()}
    return await self.update(ref, {"extattrs": extattrs})