Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Installing

pip install redfish

The asynchronous client has an optional ``aiohttp`` dependency:

.. code-block:: console

pip install redfish[aiohttp]

Building from zip file source
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -52,6 +58,8 @@ Required external packages:
requests-toolbelt
requests-unixsocket

The optional asynchronous client requires ``aiohttp>=3.9.0``.

If installing from GitHub, you may install the external packages by running:

.. code-block:: console
Expand Down Expand Up @@ -183,6 +191,48 @@ Each of the previous methods allows for the following arguments:
- This can be useful when a particular URI is known to take multiple retries.
- The default value is ``None``, which indicates the object-defined max retry count is used.

Asynchronous client
~~~~~~~~~~~~~~~~~~~

The additive asynchronous API uses ``aiohttp`` and does not change the existing synchronous client. The caller must provide an ``aiohttp.ClientSession`` and remains responsible for closing it. This allows an application to control connection pooling, TLS trust, proxy behavior, and session lifetime in one place.

The asynchronous client currently supports HTTP Basic authentication. It does not create a Redfish session or require a separate login call. Requests do not follow redirects, and advertised resource or action targets are accepted only when they resolve to the configured Redfish origin. These rules prevent credentials from being sent to another origin.

.. code-block:: python

import aiohttp

from redfish.aio import AsyncRedfishClient


async def get_systems():
async with aiohttp.ClientSession() as session:
client = AsyncRedfishClient(
base_url="https://bmc.example",
username="user",
password="password",
session=session,
timeout=10,
discovery_timeout=60,
)

service_root = await client.get_service_root()
systems = await client.get_systems()
return service_root, systems

``get``, ``head``, ``post``, ``put``, ``patch``, and ``delete`` are coroutines with the same ``path``, ``args``, ``body``, ``headers``, and ``timeout`` concepts as the synchronous methods. The returned response is fully read and cached before the coroutine returns, so it can be inspected after the underlying aiohttp response closes.

``get_systems`` follows the standard ServiceRoot ``Systems`` link, collection pagination, ComputerSystem member links, and reset ActionInfo resources. It returns ``ComputerSystem`` objects containing standard identity, metadata, power state, reset target, and advertised standard reset types. ``reset_system`` sends an advertised reset type to that system's advertised reset target:

.. code-block:: python

systems = await client.get_systems()
system = systems["1"]
if "On" in system.reset_types:
await client.reset_system(system, "On")

The optional request ``timeout`` bounds each HTTP request. ``discovery_timeout`` defaults to 60 seconds and bounds the complete ServiceRoot, collection, member, and ActionInfo discovery operation. TLS verification is controlled entirely by the injected ``ClientSession``. Configure that session with an appropriate CA certificate or SSL context for a Redfish service using a private or self-signed certificate.

Working with tasks
~~~~~~~~~~~~~~~~~~

Expand Down
38 changes: 38 additions & 0 deletions examples/async_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright Notice:
# Copyright 2016-2026 DMTF. All rights reserved.
# License: BSD 3-Clause License. For full text see link:
# https://github.com/DMTF/python-redfish-library/blob/main/LICENSE.md

"""Discover ComputerSystem resources with the asynchronous Redfish client."""

import asyncio
import os

import aiohttp

from redfish.aio import AsyncRedfishClient


async def main():
"""Discover and display Redfish ComputerSystem resources."""
async with aiohttp.ClientSession() as session:
client = AsyncRedfishClient(
base_url=os.environ["REDFISH_BASE_URL"],
username=os.environ["REDFISH_USERNAME"],
password=os.environ["REDFISH_PASSWORD"],
session=session,
timeout=10,
)
systems = await client.get_systems()
for system in systems.values():
print(
"{}: power={}, reset_types={}".format(
system.name or system.system_id,
system.power_state,
sorted(system.reset_types),
)
)


if __name__ == "__main__":
asyncio.run(main())
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aiohttp>=3.9.0
jsonpatch<=1.24 ; python_version == '3.4'
jsonpatch ; python_version >= '3.5'
jsonpath_ng
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
'requests-unixsocket'
],
extras_require={
'aiohttp': [
'aiohttp>=3.9.0'
],
':python_version == "3.4"': [
'jsonpatch<=1.24'
],
Expand Down
45 changes: 45 additions & 0 deletions src/redfish/aio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright Notice:
# Copyright 2016-2026 DMTF. All rights reserved.
# License: BSD 3-Clause License. For full text see link:
# https://github.com/DMTF/python-redfish-library/blob/main/LICENSE.md

"""Asynchronous Redfish client API."""

from .client import AsyncRedfishClient
from .exceptions import (
RedfishAuthenticationError,
RedfishConnectionError,
RedfishError,
RedfishHTTPError,
RedfishInvalidTargetError,
RedfishProtocolError,
RedfishTimeoutError,
RedfishUnsupportedResetError,
)
from .models import (
STANDARD_RESET_TYPES,
ComputerSystem,
get_reset_action_info_target,
parse_computer_system,
parse_reset_action_info,
)
from .response import AsyncRestRequest, AsyncRestResponse

__all__ = [
"AsyncRedfishClient",
"AsyncRestRequest",
"AsyncRestResponse",
"ComputerSystem",
"RedfishAuthenticationError",
"RedfishConnectionError",
"RedfishError",
"RedfishHTTPError",
"RedfishInvalidTargetError",
"RedfishProtocolError",
"RedfishTimeoutError",
"RedfishUnsupportedResetError",
"STANDARD_RESET_TYPES",
"get_reset_action_info_target",
"parse_computer_system",
"parse_reset_action_info",
]
Loading