요청 API

This module provides low-level API request/response interfaces based on aiohttp.

Depending on the session object where the request is made from, Request and Response differentiate their behavior: works as plain Python functions or returns awaitables.

class ai.backend.client.request.Request(method='GET', path=None, content=None, *, content_type=None, params=None, reporthook=None, override_api_version=None)[소스]

The API request object.

with async with fetch(**kwargs) as Response[소스]

Sends the request to the server and reads the response.

You may use this method either with plain synchronous Session or AsyncSession. Both the followings patterns are valid:

from ai.backend.client.request import Request
from ai.backend.client.session import Session

with Session() as sess:
  rqst = Request('GET', ...)
  with rqst.fetch() as resp:
    print(resp.text())
from ai.backend.client.request import Request
from ai.backend.client.session import AsyncSession

async with AsyncSession() as sess:
  rqst = Request('GET', ...)
  async with rqst.fetch() as resp:
    print(await resp.text())
반환 형식

FetchContextManager

async with connect_websocket(**kwargs) as WebSocketResponse or its derivatives[소스]

Creates a WebSocket connection.

경고

This method only works with AsyncSession.

반환 형식

WebSocketContextManager

content

Retrieves the content in the original form. Private codes should NOT use this as it incurs duplicate encoding/decoding.

반환 형식

Union[bytes, bytearray, str, StreamReader, IOBase, None]

set_content(value, *, content_type=None)[소스]

Sets the content of the request.

반환 형식

None

set_json(value)[소스]

A shortcut for set_content() with JSON objects.

반환 형식

None

attach_files(files)[소스]

Attach a list of files represented as AttachedFile.

반환 형식

None

connect_events(**kwargs)[소스]

Creates a Server-Sent Events connection.

경고

This method only works with AsyncSession.

반환 형식

SSEContextManager

class ai.backend.client.request.Response(session, underlying_response, *, async_mode=False, **kwargs)[소스]
class ai.backend.client.request.WebSocketResponse(session, underlying_response, **kwargs)[소스]

A high-level wrapper of aiohttp.ClientWebSocketResponse.

class ai.backend.client.request.FetchContextManager(session, rqst_ctx_builder, *, response_cls=<class 'ai.backend.client.request.Response'>, check_status=True)[소스]

The context manager returned by Request.fetch().

It provides both synchronous and asynchronous context manager interfaces.

class ai.backend.client.request.WebSocketContextManager(session, ws_ctx_builder, *, on_enter=None, response_cls=<class 'ai.backend.client.request.WebSocketResponse'>)[소스]

The context manager returned by Request.connect_websocket().

class ai.backend.client.request.AttachedFile(filename, stream, content_type)

A struct that represents an attached file to the API request.

매개변수
  • filename (str) – The name of file to store. It may include paths and the server will create parent directories if required.

  • stream (Any) – A file-like object that allows stream-reading bytes.

  • content_type (str) – The content type for the stream. For arbitrary binary data, use “application/octet-stream”.

content_type

Alias for field number 2

count(value, /)

Return number of occurrences of value.

filename

Alias for field number 0

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.

stream

Alias for field number 1