aas_client3_2.http

Define the protocol between the client and the HTTP implementation.

The client builds the complete Request itself, including the URL with the encoded identifiers and query, the headers and the body. A Transport only moves the bytes over the wire, so that the client does not depend on any HTTP library.

class aas_client3_2.http.StreamedBody(chunks: Callable[[], Iterator[bytes]], length: int)[source]

Represent a request body which is sent in chunks.

The body is iterable and reports its length through __len__, so that the HTTP libraries can send it as it is, with Content-Length and without chunked transfer encoding. Each iteration starts from the beginning of the body.

chunks: Callable[[], Iterator[bytes]]

Start a new iteration over the chunks of the body from its beginning. Every call must yield the same bytes, so that the request can be replayed. This is a contract which the types can not enforce; whoever constructs the body is responsible for it.

length: int

Length of the body in bytes, sent as Content-Length

__post_init__() → None[source]

Check that the length is positive.

__iter__() → Iterator[bytes][source]

Start a new iteration over the chunks from the beginning of the body.

__len__() → int[source]

Give the length of the body in bytes.

__dataclass_fields__ = {'chunks': Field(name='chunks',type=typing.Callable[[], typing.Iterator[bytes]],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'length': Field(name='length',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=True,match_args=True,kw_only=False,slots=False,weakref_slot=False)
__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(chunks: Callable[[], Iterator[bytes]], length: int) → None
__match_args__ = ('chunks', 'length')
__repr__()

Return repr(self).

__setattr__(name, value)

Implement setattr(self, name, value).

class aas_client3_2.http.Request(method: str, url: str, headers: Mapping[str, str], body: bytes | StreamedBody | None, follow_redirects: bool = True)[source]

Represent a complete HTTP request as built by the client.

method: str

HTTP method in upper case, such as GET

url: str

Complete URL including the encoded query

headers: Mapping[str, str]

Headers of the request

body: bytes | StreamedBody | None

Body of the request, if any

follow_redirects: bool = True

Whether the transport follows the redirects, if it can follow them at all.

The client turns this off only for the requests where it has to see the redirect itself, such as the status of a bulk operation, whose result the server may delete once it has been fetched.

__dataclass_fields__ = {'body': Field(name='body',type=typing.Union[bytes, aas_client3_2.http.StreamedBody, NoneType],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'follow_redirects': Field(name='follow_redirects',type=<class 'bool'>,default=True,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'headers': Field(name='headers',type=typing.Mapping[str, str],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'method': Field(name='method',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'url': Field(name='url',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=True,match_args=True,kw_only=False,slots=False,weakref_slot=False)
__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(method: str, url: str, headers: Mapping[str, str], body: bytes | StreamedBody | None, follow_redirects: bool = True) → None
__match_args__ = ('method', 'url', 'headers', 'body', 'follow_redirects')
__repr__()

Return repr(self).

__setattr__(name, value)

Implement setattr(self, name, value).

class aas_client3_2.http.Response(status_code: int, headers: Mapping[str, str], body: bytes)[source]

Represent an HTTP response whose body has been read completely.

status_code: int

HTTP status code

headers: Mapping[str, str]

Headers of the response; look them up with find_header()

body: bytes

Complete body of the response

__dataclass_fields__ = {'body': Field(name='body',type=<class 'bytes'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'headers': Field(name='headers',type=typing.Mapping[str, str],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'status_code': Field(name='status_code',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=True,match_args=True,kw_only=False,slots=False,weakref_slot=False)
__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(status_code: int, headers: Mapping[str, str], body: bytes) → None
__match_args__ = ('status_code', 'headers', 'body')
__repr__()

Return repr(self).

__setattr__(name, value)

Implement setattr(self, name, value).

class aas_client3_2.http.StreamedResponse(status_code: int, headers: Mapping[str, str], chunks: Iterator[bytes])[source]

Represent an HTTP response whose body is read in chunks.

status_code: int

HTTP status code

headers: Mapping[str, str]

Headers of the response; look them up with find_header()

chunks: Iterator[bytes]

Chunks of the body, which can be iterated only once

__dataclass_fields__ = {'chunks': Field(name='chunks',type=typing.Iterator[bytes],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'headers': Field(name='headers',type=typing.Mapping[str, str],default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'status_code': Field(name='status_code',type=<class 'int'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=True,match_args=True,kw_only=False,slots=False,weakref_slot=False)
__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(status_code: int, headers: Mapping[str, str], chunks: Iterator[bytes]) → None
__match_args__ = ('status_code', 'headers', 'chunks')
__repr__()

Return repr(self).

__setattr__(name, value)

Implement setattr(self, name, value).

class aas_client3_2.http.Download(content_type: str | None, content_length: int | None, file_name: str | None, chunks: Iterator[bytes])[source]

Represent the binary content of a file which the server is sending.

A download is valid only within the context in which the client gave it, since the connection is released when the context is exited. The content can be read only once, either with iter_chunks() or with write_to().

__init__(content_type: str | None, content_length: int | None, file_name: str | None, chunks: Iterator[bytes]) → None[source]

Initialize with the given values.

content_type: str | None

Content type of the file as given by the server, if any

content_length: int | None

Size of the content in bytes as announced by the server, if any

file_name: str | None

Name of the file from the header Content-Disposition, if any

iter_chunks() → Iterator[bytes][source]

Iterate over the chunks of the content.

Raises:

RuntimeError if the content has already been read

write_to(destination: IO[bytes]) → int[source]

Copy the content to destination.

Parameters:

destination – binary file object to write to

Returns:

number of the written bytes

Raises:

RuntimeError if the content has already been read

class aas_client3_2.http.Transport(*args, **kwargs)[source]

Send the requests over the wire.

Network errors (timeouts, refused connections, TLS errors, …) are raised by the transport and propagate unchanged through the client.

send(request: Request) → ContextManager[StreamedResponse][source]

Send the request, and give the response with the body in chunks.

The connection is released when the context is exited, also when the body has not been read to the end.

The transport must not follow the redirects if Request.follow_redirects is off, but give the redirect itself.

__init__(*args, **kwargs)
__parameters__ = ()
__protocol_attrs__ = {'send'}
classmethod __subclasshook__(other)

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

aas_client3_2.http.send(transport: Transport, request: Request) → Response[source]

Send request through transport, and read the whole body.

Parameters:
  • transport – transport to send the request through

  • request – request to be sent

Returns:

the response with the complete body

class aas_client3_2.http.Server(transport: Transport, base_url: str)[source]

Bundle a transport with the base URL of a server.

transport: Transport

Transport to send the requests through

base_url: str

Base URL of the server, such as https://example.com/api/v3.2

__dataclass_fields__ = {'base_url': Field(name='base_url',type=<class 'str'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'transport': Field(name='transport',type=<class 'aas_client3_2.http.Transport'>,default=<dataclasses._MISSING_TYPE object>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=True,match_args=True,kw_only=False,slots=False,weakref_slot=False)
__delattr__(name)

Implement delattr(self, name).

__eq__(other)

Return self==value.

__hash__()

Return hash(self).

__init__(transport: Transport, base_url: str) → None
__match_args__ = ('transport', 'base_url')
__repr__()

Return repr(self).

__setattr__(name, value)

Implement setattr(self, name, value).

aas_client3_2.http.find_header(headers: Mapping[str, str], name: str) → str | None[source]

Look up the header name case-insensitively.

Parameters:
  • headers – headers of a request or a response

  • name – name of the header

Returns:

value of the header, or None if it is missing

>>> find_header({"Content-Type": "application/json"}, "content-type")
'application/json'
>>> find_header({"Content-Type": "application/json"}, "Location") is None
True
aas_client3_2.http.has_media_type(headers: Mapping[str, str], media_type: str) → bool[source]

Check that the Content-Type in headers is media_type.

The parameters, such as charset=utf-8, are ignored, and the media types are compared regardless of the case, as RFC 9110 prescribes.

>>> has_media_type(
...     {"content-type": "Application/JSON; charset=utf-8"}, "application/json"
... )
True
>>> has_media_type({"Content-Type": "text/html"}, "application/json")
False
>>> has_media_type({}, "application/json")
False
Parameters:
  • headers – headers of a response

  • media_type – expected media type in lower case, such as application/json

Returns:

True if the content type is media_type

aas_client3_2.http.encode_base64url(text: str) → str[source]

Encode text as UTF-8 in base64url without padding.

The specification requires this encoding for the identifiers in the paths, and for the JSON-serialized references and key-value pairs in the query.

Parameters:

text – text to be encoded

Returns:

encoded text

>>> encode_base64url("urn:example:submodel:1")
'dXJuOmV4YW1wbGU6c3VibW9kZWw6MQ'
aas_client3_2.http.decode_base64url(text: str) → str[source]

Decode the UTF-8 text from text in base64url, with or without padding.

Parameters:

text – encoded text

Returns:

decoded text

Raises:

ValueError if text is not valid base64url, or if the decoded bytes are not valid UTF-8

>>> decode_base64url("dXJuOmV4YW1wbGU6c3VibW9kZWw6MQ")
'urn:example:submodel:1'
aas_client3_2.http.encode_id_short_path(id_short_path: str) → str[source]

Percent-encode id_short_path as a single segment of a path.

The specification requires the ID-short paths to be URL-encoded, since they can contain square brackets.

Parameters:

id_short_path – ID-short path such as sme1.sme2[0].p1

Returns:

encoded path segment

>>> encode_id_short_path("sme1.sme2[0].p1")
'sme1.sme2%5B0%5D.p1'
aas_client3_2.http.encode_date_time(value: datetime) → str[source]

Encode value in ISO 8601 for a query parameter.

Parameters:

value – date and time with a time zone

Returns:

encoded date and time, not yet URL-encoded

Raises:

ValueError if value has no time zone, since the server would interpret it in a time zone of its own

>>> encode_date_time(
...     datetime.datetime(2026, 10, 29, 12, 30, tzinfo=datetime.timezone.utc)
... )
'2026-10-29T12:30:00+00:00'
aas_client3_2.http.build_url(base_url: str, path: str, query: Sequence[Tuple[str, str]] | None = None) → str[source]

Join base_url and path, and append the query.

Parameters:
  • base_url – base URL of the server, with or without the trailing slash

  • path – path starting with a slash, with the segments already encoded, or empty for the base URL itself, such as the endpoint of a submodel

  • query – pairs of names and values of the query parameters, not yet encoded

Returns:

complete URL

>>> build_url("https://example.com/api/", "/submodels", [("limit", "10")])
'https://example.com/api/submodels?limit=10'
>>> build_url("https://example.com", "/description")
'https://example.com/description'
>>> build_url("https://example.com/submodels/dXJuOnNtOjE/", "", [("level", "core")])
'https://example.com/submodels/dXJuOnNtOjE?level=core'