alexapy.aiohttp

Submodules

Functions

alexapy.aiohttp.request(method: str, url: Union[str, yarl.URL], *, params: Optional[Mapping[str, str]] = None, data: Any = None, json: Any = None, headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, skip_auto_headers: Optional[Iterable[str]] = None, auth: Optional[alexapy.aiohttp.helpers.BasicAuth] = None, allow_redirects: bool = True, max_redirects: int = 10, compress: Optional[str] = None, chunked: Optional[bool] = None, expect100: bool = False, raise_for_status: Optional[bool] = None, read_until_eof: bool = True, proxy: Optional[Union[str, yarl.URL]] = None, proxy_auth: Optional[alexapy.aiohttp.helpers.BasicAuth] = None, timeout: Union[alexapy.aiohttp.client.ClientTimeout, object] = <object object>, cookies: Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]] = None, version: alexapy.aiohttp.http_writer.HttpVersion = HttpVersion(major=1, minor=1), connector: Optional[alexapy.aiohttp.connector.BaseConnector] = None, read_bufsize: Optional[int] = None, loop: Optional[asyncio.events.AbstractEventLoop] = None)alexapy.aiohttp.client._SessionRequestContextManager

Constructs and sends a request. Returns response object. method - HTTP method url - request url params - (optional) Dictionary or bytes to be sent in the query

string of the new request

data - (optional) Dictionary, bytes, or file-like object to

send in the body of the request

json - (optional) Any json compatible python object headers - (optional) Dictionary of HTTP Headers to send with

the request

cookies - (optional) Dict object to send with the request auth - (optional) BasicAuth named tuple represent HTTP Basic Auth auth - aiohttp.helpers.BasicAuth allow_redirects - (optional) If set to False, do not follow

redirects

version - Request HTTP version. compress - Set to True if request has to be compressed

with deflate encoding.

chunked - Set to chunk size for chunked transfer encoding. expect100 - Expect 100-continue response from server. connector - BaseConnector sub-class instance to support

connection pooling.

read_until_eof - Read response until eof if response

does not have Content-Length header.

loop - Optional event loop. timeout - Optional ClientTimeout settings structure, 5min

total timeout by default.

Usage::
>>> import aiohttp
>>> resp = await aiohttp.request('GET', 'http://python.org/')
>>> resp
<ClientResponse(python.org/) [200]>
>>> data = await resp.read()
alexapy.aiohttp.content_disposition_filename(params: Mapping[str, str], name: str = 'filename')Optional[str]
alexapy.aiohttp.parse_content_disposition(header: Optional[str])Tuple[Optional[str], Dict[str, str]]
alexapy.aiohttp.get_payload(data: Any, *args: Any, **kwargs: Any)alexapy.aiohttp.payload.Payload

Classes

class alexapy.aiohttp.BaseConnector(*, keepalive_timeout: Union[object, None, float] = <object object>, force_close: bool = False, limit: int = 100, limit_per_host: int = 0, enable_cleanup_closed: bool = False, loop: Optional[asyncio.events.AbstractEventLoop] = None)

Base connector class.

keepalive_timeout - (optional) Keep-alive timeout. force_close - Set to True to force close and do reconnect

after each request (and between redirects).

limit - The total number of simultaneous connections. limit_per_host - Number of simultaneous connections to one host. enable_cleanup_closed - Enables clean-up closed ssl transports.

Disabled by default.

loop - Optional event loop.

Inheritance

Inheritance diagram of BaseConnector

close()Awaitable[None]

Close all opened transports.

property closed

Is connector closed.

A readonly property.

async connect(req: ClientRequest, traces: List[Trace], timeout: ClientTimeout)alexapy.aiohttp.connector.Connection

Get from pool or create new connection.

property force_close

Ultimately close connection on releasing if True.

property limit

The total number for simultaneous connections.

If limit is 0 the connector has no limit. The default limit size is 100.

property limit_per_host

The limit_per_host for simultaneous connections to the same endpoint.

Endpoints are the same if they are have equal (host, port, is_ssl) triple.

class alexapy.aiohttp.ClientResponse(method: str, url: yarl.URL, *, writer: asyncio.Task[None], continue100: Optional[asyncio.Future[bool]], timer: alexapy.aiohttp.helpers.BaseTimerContext, request_info: alexapy.aiohttp.client_reqrep.RequestInfo, traces: List[Trace], loop: asyncio.events.AbstractEventLoop, session: ClientSession)

Inheritance

Inheritance diagram of ClientResponse

history

A sequence of of responses, if redirects occurred.

async json(*, encoding: Optional[str] = None, loads: Callable[[str], Any] = <function loads>, content_type: Optional[str] = 'application/json')Any

Read and decodes JSON response.

property ok

Returns True if status is less than 400, False if not.

This is not a check for 200 OK but a check that the response status is under 400.

async read()bytes

Read response payload.

async start(connection: Connection)ClientResponse

Start response processing.

async text(encoding: Optional[str] = None, errors: str = 'strict')str

Read response payload and decode.

class alexapy.aiohttp.ClientRequest(method: str, url: yarl.URL, *, params: Optional[Mapping[str, str]] = None, headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, skip_auto_headers: Iterable[str] = frozenset({}), data: Any = None, cookies: Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]] = None, auth: Optional[alexapy.aiohttp.helpers.BasicAuth] = None, version: alexapy.aiohttp.http_writer.HttpVersion = HttpVersion(major=1, minor=1), compress: Optional[str] = None, chunked: Optional[bool] = None, expect100: bool = False, loop: Optional[asyncio.events.AbstractEventLoop] = None, response_class: Optional[Type[ClientResponse]] = None, proxy: Optional[yarl.URL] = None, proxy_auth: Optional[alexapy.aiohttp.helpers.BasicAuth] = None, timer: Optional[alexapy.aiohttp.helpers.BaseTimerContext] = None, session: Optional[ClientSession] = None, ssl: Optional[Union[ssl.SSLContext, bool, alexapy.aiohttp.client_reqrep.Fingerprint]] = None, proxy_headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, traces: Optional[List[Trace]] = None)

Inheritance

Inheritance diagram of ClientRequest

update_auth(auth: Optional[alexapy.aiohttp.helpers.BasicAuth])None

Set basic auth.

update_content_encoding(data: Any)None

Set request content encoding.

update_cookies(cookies: Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]])None

Update request cookies header.

update_headers(headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]])None

Update request headers.

update_host(url: yarl.URL)None

Update destination host, port and connection type (ssl).

update_transfer_encoding()None

Analyze transfer-encoding header.

update_version(version: Union[alexapy.aiohttp.http_writer.HttpVersion, str])None

Convert request version to two elements tuple.

parser HTTP version ‘1.1’ => (1, 1)

async write_bytes(writer: alexapy.aiohttp.abc.AbstractStreamWriter, conn: Connection)None

Support coroutines that yields bytes objects.

class alexapy.aiohttp.ClientSession(*, connector: Optional[alexapy.aiohttp.connector.BaseConnector] = None, loop: Optional[asyncio.events.AbstractEventLoop] = None, cookies: Optional[Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]]] = None, headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, skip_auto_headers: Optional[Iterable[str]] = None, auth: Optional[alexapy.aiohttp.helpers.BasicAuth] = None, json_serialize: Callable[[Any], str] = <function dumps>, request_class: Type[alexapy.aiohttp.client_reqrep.ClientRequest] = <class 'alexapy.aiohttp.client_reqrep.ClientRequest'>, response_class: Type[alexapy.aiohttp.client_reqrep.ClientResponse] = <class 'alexapy.aiohttp.client_reqrep.ClientResponse'>, ws_response_class: Type[alexapy.aiohttp.client_ws.ClientWebSocketResponse] = <class 'alexapy.aiohttp.client_ws.ClientWebSocketResponse'>, version: alexapy.aiohttp.http_writer.HttpVersion = HttpVersion(major=1, minor=1), cookie_jar: Optional[alexapy.aiohttp.abc.AbstractCookieJar] = None, connector_owner: bool = True, raise_for_status: bool = False, read_timeout: Union[float, object] = <object object>, conn_timeout: Optional[float] = None, timeout: Union[object, alexapy.aiohttp.client.ClientTimeout] = <object object>, auto_decompress: bool = True, trust_env: bool = False, requote_redirect_url: bool = True, trace_configs: Optional[List[alexapy.aiohttp.tracing.TraceConfig]] = None, read_bufsize: int = 65536)

First-class interface for making HTTP requests.

Inheritance

Inheritance diagram of ClientSession

property auth

An object that represents HTTP Basic Authorization

property auto_decompress

Should the body response be automatically decompressed

async close()None

Close underlying connector.

Release all acquired resources.

property closed

Is client session closed.

A readonly property.

property connector

Connector instance used for the session.

property connector_owner

Should connector be closed on session closing

property cookie_jar

The session cookies.

delete(url: Union[str, yarl.URL], **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP DELETE request.

detach()None

Detach connector from session without closing the former.

Session is switched to closed state anyway.

get(url: Union[str, yarl.URL], *, allow_redirects: bool = True, **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP GET request.

head(url: Union[str, yarl.URL], *, allow_redirects: bool = False, **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP HEAD request.

property headers

The default headers of the client session.

property json_serialize

Json serializer callable

property loop

Session’s loop.

options(url: Union[str, yarl.URL], *, allow_redirects: bool = True, **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP OPTIONS request.

patch(url: Union[str, yarl.URL], *, data: Optional[Any] = None, **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP PATCH request.

post(url: Union[str, yarl.URL], *, data: Optional[Any] = None, **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP POST request.

put(url: Union[str, yarl.URL], *, data: Optional[Any] = None, **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP PUT request.

property raise_for_status

Should ClientResponse.raise_for_status() be called for each response

request(method: str, url: Union[str, yarl.URL], **kwargs: Any)alexapy.aiohttp.client._RequestContextManager

Perform HTTP request.

property requote_redirect_url

Do URL requoting on redirection handling.

property skip_auto_headers

Headers for which autogeneration should be skipped

property timeout

Timeout for the session.

property trace_configs

A list of TraceConfig instances used for client tracing

property trust_env

Should get proxies information from HTTP_PROXY / HTTPS_PROXY environment variables or ~/.netrc file if present

property version

The session HTTP protocol version.

ws_connect(url: Union[str, yarl.URL], *, method: str = 'GET', protocols: Iterable[str] = (), timeout: float = 10.0, receive_timeout: Optional[float] = None, autoclose: bool = True, autoping: bool = True, heartbeat: Optional[float] = None, auth: Optional[alexapy.aiohttp.helpers.BasicAuth] = None, origin: Optional[str] = None, headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, proxy: Optional[Union[str, yarl.URL]] = None, proxy_auth: Optional[alexapy.aiohttp.helpers.BasicAuth] = None, ssl: Union[ssl.SSLContext, bool, None, alexapy.aiohttp.client_reqrep.Fingerprint] = None, verify_ssl: Optional[bool] = None, fingerprint: Optional[bytes] = None, ssl_context: Optional[ssl.SSLContext] = None, proxy_headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None, compress: int = 0, max_msg_size: int = 4194304)alexapy.aiohttp.client._WSRequestContextManager

Initiate websocket connection.

class alexapy.aiohttp.ClientTimeout(total: Optional[float] = None, connect: Optional[float] = None, sock_read: Optional[float] = None, sock_connect: Optional[float] = None)

Inheritance

Inheritance diagram of ClientTimeout

class alexapy.aiohttp.ClientWebSocketResponse(reader: alexapy.aiohttp.streams.FlowControlDataQueue[alexapy.aiohttp.http_websocket.WSMessage], writer: alexapy.aiohttp.http_websocket.WebSocketWriter, protocol: Optional[str], response: alexapy.aiohttp.client_reqrep.ClientResponse, timeout: float, autoclose: bool, autoping: bool, loop: asyncio.events.AbstractEventLoop, *, receive_timeout: Optional[float] = None, heartbeat: Optional[float] = None, compress: int = 0, client_notakeover: bool = False)

Inheritance

Inheritance diagram of ClientWebSocketResponse

get_extra_info(name: str, default: Optional[Any] = None)Any

extra info from connection transport

class alexapy.aiohttp.Fingerprint(fingerprint: bytes)

Inheritance

Inheritance diagram of Fingerprint

class alexapy.aiohttp.RequestInfo(url: yarl.URL, method: str, headers: CIMultiDictProxy[str], real_url: yarl.URL = NOTHING)

Inheritance

Inheritance diagram of RequestInfo

class alexapy.aiohttp.TCPConnector(*, verify_ssl: bool = True, fingerprint: Optional[bytes] = None, use_dns_cache: bool = True, ttl_dns_cache: Optional[int] = 10, family: int = 0, ssl_context: Optional[ssl.SSLContext] = None, ssl: Union[ssl.SSLContext, bool, None, alexapy.aiohttp.client_reqrep.Fingerprint] = None, local_addr: Optional[Tuple[str, int]] = None, resolver: Optional[alexapy.aiohttp.abc.AbstractResolver] = None, keepalive_timeout: Union[None, float, object] = <object object>, force_close: bool = False, limit: int = 100, limit_per_host: int = 0, enable_cleanup_closed: bool = False, loop: Optional[asyncio.events.AbstractEventLoop] = None)

TCP connector.

verify_ssl - Set to True to check ssl certifications. fingerprint - Pass the binary sha256

digest of the expected certificate in DER format to verify that the certificate the server presents matches. See also https://en.wikipedia.org/wiki/Transport_Layer_Security#Certificate_pinning

resolver - Enable DNS lookups and use this

resolver

use_dns_cache - Use memory cache for DNS lookups. ttl_dns_cache - Max seconds having cached a DNS entry, None forever. family - socket address family local_addr - local tuple of (host, port) to bind socket to

keepalive_timeout - (optional) Keep-alive timeout. force_close - Set to True to force close and do reconnect

after each request (and between redirects).

limit - The total number of simultaneous connections. limit_per_host - Number of simultaneous connections to one host. enable_cleanup_closed - Enables clean-up closed ssl transports.

Disabled by default.

loop - Optional event loop.

Inheritance

Inheritance diagram of TCPConnector

clear_dns_cache(host: Optional[str] = None, port: Optional[int] = None)None

Remove specified host/port or clear all dns local cache.

close()Awaitable[None]

Close all ongoing DNS calls.

property family

Socket family like AF_INET.

property use_dns_cache

True if local DNS caching is enabled.

class alexapy.aiohttp.UnixConnector(path: str, force_close: bool = False, keepalive_timeout: Optional[Union[object, float]] = <object object>, limit: int = 100, limit_per_host: int = 0, loop: Optional[asyncio.events.AbstractEventLoop] = None)

Unix socket connector.

path - Unix socket path. keepalive_timeout - (optional) Keep-alive timeout. force_close - Set to True to force close and do reconnect

after each request (and between redirects).

limit - The total number of simultaneous connections. limit_per_host - Number of simultaneous connections to one host. loop - Optional event loop.

Inheritance

Inheritance diagram of UnixConnector

property path

Path to unix socket.

class alexapy.aiohttp.NamedPipeConnector(path: str, force_close: bool = False, keepalive_timeout: Optional[Union[object, float]] = <object object>, limit: int = 100, limit_per_host: int = 0, loop: Optional[asyncio.events.AbstractEventLoop] = None)

Named pipe connector.

Only supported by the proactor event loop. See also: https://docs.python.org/3.7/library/asyncio-eventloop.html

path - Windows named pipe path. keepalive_timeout - (optional) Keep-alive timeout. force_close - Set to True to force close and do reconnect

after each request (and between redirects).

limit - The total number of simultaneous connections. limit_per_host - Number of simultaneous connections to one host. loop - Optional event loop.

Inheritance

Inheritance diagram of NamedPipeConnector

property path

Path to the named pipe.

class alexapy.aiohttp.CookieJar(*, unsafe: bool = False, quote_cookie: bool = True, loop: Optional[asyncio.events.AbstractEventLoop] = None)

Implements cookie storage adhering to RFC 6265.

Inheritance

Inheritance diagram of CookieJar

clear()None

Clear all cookies.

filter_cookies(request_url: yarl.URL = URL(''))Union[BaseCookie[str], SimpleCookie[str]]

Returns this jar’s cookies filtered by their attributes.

update_cookies(cookies: Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]], response_url: yarl.URL = URL(''))None

Update cookies.

class alexapy.aiohttp.DummyCookieJar(*, loop: Optional[asyncio.events.AbstractEventLoop] = None)

Implements a dummy cookie storage.

It can be used with the ClientSession when no cookie processing is needed.

Inheritance

Inheritance diagram of DummyCookieJar

clear()None

Clear all cookies.

filter_cookies(request_url: yarl.URL)BaseCookie[str]

Return the jar’s cookies filtered by their attributes.

update_cookies(cookies: Union[Mapping[str, Union[str, BaseCookie[str], Morsel[Any]]], Iterable[Tuple[str, Union[str, BaseCookie[str], Morsel[Any]]]], BaseCookie[str]], response_url: yarl.URL = URL(''))None

Update cookies.

class alexapy.aiohttp.FormData(fields: Iterable[Any] = (), quote_fields: bool = True, charset: Optional[str] = None)

Helper class for multipart/form-data and application/x-www-form-urlencoded body generation.

Inheritance

Inheritance diagram of FormData

class alexapy.aiohttp.BasicAuth(login: str, password: str = '', encoding: str = 'latin1')

Http basic authentication helper.

Inheritance

Inheritance diagram of BasicAuth

classmethod decode(auth_header: str, encoding: str = 'latin1')alexapy.aiohttp.helpers.BasicAuth

Create a BasicAuth object from an Authorization HTTP header.

encode()str

Encode credentials.

classmethod from_url(url: yarl.URL, *, encoding: str = 'latin1')Optional[alexapy.aiohttp.helpers.BasicAuth]

Create BasicAuth from url.

class alexapy.aiohttp.ChainMapProxy(maps: Iterable[Mapping[str, Any]])

Inheritance

Inheritance diagram of ChainMapProxy

get(k[, d])D[k] if k in D, else d.  d defaults to None.
class alexapy.aiohttp.HttpVersion(major, minor)

Inheritance

Inheritance diagram of HttpVersion

property major

Alias for field number 0

property minor

Alias for field number 1

class alexapy.aiohttp.WSMsgType(value)

An enumeration.

Inheritance

Inheritance diagram of WSMsgType

class alexapy.aiohttp.WSCloseCode(value)

An enumeration.

Inheritance

Inheritance diagram of WSCloseCode

class alexapy.aiohttp.WSMessage(type, data, extra)

Inheritance

Inheritance diagram of WSMessage

json(*, loads: Callable[[Any], Any] = <function loads>)Any

Return parsed JSON data.

New in version 0.22.

class alexapy.aiohttp.BodyPartReader(boundary: bytes, headers: multidict._multidict.CIMultiDictProxy, content: alexapy.aiohttp.streams.StreamReader)

Multipart reader for single body part.

Inheritance

Inheritance diagram of BodyPartReader

at_eof()bool

Returns True if the boundary was reached or False otherwise.

decode(data: bytes)bytes

Decodes data according the specified Content-Encoding or Content-Transfer-Encoding headers value.

filename

Returns filename specified in Content-Disposition header or None if missed or header is malformed.

async form(*, encoding: Optional[str] = None)List[Tuple[str, str]]

Like read(), but assumes that body parts contains form urlencoded data.

get_charset(default: str)str

Returns charset parameter from Content-Type header or default.

async json(*, encoding: Optional[str] = None)Optional[Dict[str, Any]]

Like read(), but assumes that body parts contains JSON data.

name

Returns name specified in Content-Disposition header or None if missed or header is malformed.

async read(*, decode: bool = False)bytes

Reads body part data.

decode: Decodes data following by encoding

method from Content-Encoding header. If it missed data remains untouched

async read_chunk(size: int = 8192)bytes

Reads body part content chunk of the specified size.

size: chunk size

async readline()bytes

Reads body part by line by line.

async release()None

Like read(), but reads all the data to the void.

async text(*, encoding: Optional[str] = None)str

Like read(), but assumes that body part contains text data.

class alexapy.aiohttp.MultipartReader(headers: Mapping[str, str], content: alexapy.aiohttp.streams.StreamReader)

Multipart body reader.

Inheritance

Inheritance diagram of MultipartReader

at_eof()bool

Returns True if the final boundary was reached or False otherwise.

async fetch_next_part()Union[alexapy.aiohttp.multipart.MultipartReader, alexapy.aiohttp.multipart.BodyPartReader]

Returns the next body part reader.

classmethod from_response(response: ClientResponse)alexapy.aiohttp.multipart.MultipartResponseWrapper

Constructs reader instance from HTTP response.

Parameters

responseClientResponse instance

multipart_reader_cls = None

Multipart reader class, used to handle multipart/* body parts. None points to type(self)

async next()Optional[Union[alexapy.aiohttp.multipart.MultipartReader, alexapy.aiohttp.multipart.BodyPartReader]]

Emits the next multipart body part.

part_reader_cls

Body part reader class for non multipart/* content types.

alias of alexapy.aiohttp.multipart.BodyPartReader

async release()None

Reads all the body parts to the void till the final boundary.

response_wrapper_cls

Response wrapper, used when multipart readers constructs from response.

alias of alexapy.aiohttp.multipart.MultipartResponseWrapper

class alexapy.aiohttp.MultipartWriter(subtype: str = 'mixed', boundary: Optional[str] = None)

Multipart body writer.

Inheritance

Inheritance diagram of MultipartWriter

append_form(obj: Union[Sequence[Tuple[str, str]], Mapping[str, str]], headers: Optional[multidict._abc.MultiMapping] = None)alexapy.aiohttp.payload.Payload

Helper to append form urlencoded part.

append_json(obj: Any, headers: Optional[multidict._abc.MultiMapping] = None)alexapy.aiohttp.payload.Payload

Helper to append JSON part.

append_payload(payload: alexapy.aiohttp.payload.Payload)alexapy.aiohttp.payload.Payload

Adds a new body part to multipart writer.

property size

Size of the payload.

async write(writer: Any, close_boundary: bool = True)None

Write body.

class alexapy.aiohttp.AsyncIterablePayload(value: collections.abc.AsyncIterable, *args: Any, **kwargs: Any)

Inheritance

Inheritance diagram of AsyncIterablePayload

async write(writer: alexapy.aiohttp.abc.AbstractStreamWriter)None

Write payload.

writer is an AbstractStreamWriter instance:

class alexapy.aiohttp.BufferedReaderPayload(value: IO[Any], disposition: str = 'attachment', *args: Any, **kwargs: Any)

Inheritance

Inheritance diagram of BufferedReaderPayload

property size

Size of the payload.

class alexapy.aiohttp.BytesIOPayload(value: IO[Any], disposition: str = 'attachment', *args: Any, **kwargs: Any)

Inheritance

Inheritance diagram of BytesIOPayload

property size

Size of the payload.

class alexapy.aiohttp.BytesPayload(value: ByteString, *args: Any, **kwargs: Any)

Inheritance

Inheritance diagram of BytesPayload

async write(writer: alexapy.aiohttp.abc.AbstractStreamWriter)None

Write payload.

writer is an AbstractStreamWriter instance:

class alexapy.aiohttp.IOBasePayload(value: IO[Any], disposition: str = 'attachment', *args: Any, **kwargs: Any)

Inheritance

Inheritance diagram of IOBasePayload

async write(writer: alexapy.aiohttp.abc.AbstractStreamWriter)None

Write payload.

writer is an AbstractStreamWriter instance:

class alexapy.aiohttp.JsonPayload(value: Any, encoding: str = 'utf-8', content_type: str = 'application/json', dumps: Callable[[Any], str] = <function dumps>, *args: Any, **kwargs: Any)

Inheritance

Inheritance diagram of JsonPayload

class alexapy.aiohttp.Payload(value: Any, headers: Optional[Union[multidict._multidict.CIMultiDict, Dict[str, str], Iterable[Tuple[str, str]]]] = None, content_type: Optional[str] = <object object>, filename: Optional[str] = None, encoding: Optional[str] = None, **kwargs: Any)

Inheritance

Inheritance diagram of Payload

property content_type

Content type

property encoding

Payload encoding

property filename

Filename of the payload.

property headers

Custom item headers

set_content_disposition(disptype: str, quote_fields: bool = True, **params: Any)None

Sets Content-Disposition header.

property size

Size of the payload.

abstract async write(writer: alexapy.aiohttp.abc.AbstractStreamWriter)None

Write payload.

writer is an AbstractStreamWriter instance:

class alexapy.aiohttp.StringIOPayload(value: IO[str], *args: Any, **kwargs: Any)

Inheritance

Inheritance diagram of StringIOPayload

class alexapy.aiohttp.StringPayload(value: str, *args: Any, encoding: Optional[str] = None, content_type: Optional[str] = None, **kwargs: Any)

Inheritance

Inheritance diagram of StringPayload

class alexapy.aiohttp.TextIOPayload(value: TextIO, *args: Any, encoding: Optional[str] = None, content_type: Optional[str] = None, **kwargs: Any)

Inheritance

Inheritance diagram of TextIOPayload

property size

Size of the payload.

async write(writer: alexapy.aiohttp.abc.AbstractStreamWriter)None

Write payload.

writer is an AbstractStreamWriter instance:

class alexapy.aiohttp.payload_type(type: Any, *, order: alexapy.aiohttp.payload.Order = <Order.normal: 'normal'>)

Inheritance

Inheritance diagram of payload_type

class alexapy.aiohttp.streamer(coro: Callable[[], Awaitable[None]])

Inheritance

Inheritance diagram of streamer

class alexapy.aiohttp.AsyncResolver(loop: Optional[asyncio.events.AbstractEventLoop] = None, *args: Any, **kwargs: Any)

Use the aiodns package to make asynchronous DNS lookups

Inheritance

Inheritance diagram of AsyncResolver

async close()None

Release resolver

async resolve(host: str, port: int = 0, family: int = <AddressFamily.AF_INET: 2>)List[Dict[str, Any]]

Return IP address for given hostname

alexapy.aiohttp.DefaultResolver

alias of alexapy.aiohttp.resolver.ThreadedResolver

class alexapy.aiohttp.ThreadedResolver(loop: Optional[asyncio.events.AbstractEventLoop] = None)

Use Executor for synchronous getaddrinfo() calls, which defaults to concurrent.futures.ThreadPoolExecutor.

Inheritance

Inheritance diagram of ThreadedResolver

async close()None

Release resolver

async resolve(hostname: str, port: int = 0, family: int = <AddressFamily.AF_INET: 2>)List[Dict[str, Any]]

Return IP address for given hostname

class alexapy.aiohttp.Signal(owner)

Coroutine-based signal implementation.

To connect a callback to a signal, use any list method.

Signals are fired using the send() coroutine, which takes named arguments.

Inheritance

Inheritance diagram of Signal

async send(*args, **kwargs)

Sends data to all registered receivers.

class alexapy.aiohttp.DataQueue(loop: asyncio.events.AbstractEventLoop)

DataQueue is a general-purpose blocking queue with one reader.

Inheritance

Inheritance diagram of DataQueue

class alexapy.aiohttp.FlowControlDataQueue(protocol: alexapy.aiohttp.base_protocol.BaseProtocol, limit: int, *, loop: asyncio.events.AbstractEventLoop)

FlowControlDataQueue resumes and pauses an underlying stream.

It is a destination for parsed data.

Inheritance

Inheritance diagram of FlowControlDataQueue

class alexapy.aiohttp.StreamReader(protocol: alexapy.aiohttp.base_protocol.BaseProtocol, limit: int, *, timer: Optional[alexapy.aiohttp.helpers.BaseTimerContext] = None, loop: Optional[asyncio.events.AbstractEventLoop] = None)

An enhancement of asyncio.StreamReader.

Supports asynchronous iteration by line, chunk or as available:

async for line in reader:
    ...
async for chunk in reader.iter_chunked(1024):
    ...
async for slice in reader.iter_any():
    ...

Inheritance

Inheritance diagram of StreamReader

at_eof()bool

Return True if the buffer is empty and ‘feed_eof’ was called.

is_eof()bool

Return True if ‘feed_eof’ was called.

async readchunk()Tuple[bytes, bool]

Returns a tuple of (data, end_of_http_chunk). When chunked transfer encoding is used, end_of_http_chunk is a boolean indicating if the end of the data corresponds to the end of a HTTP chunk , otherwise it is always False.

unread_data(data: bytes)None

rollback reading some data from stream, inserting it to buffer head.

class alexapy.aiohttp.TraceConfig(trace_config_ctx_factory: Type[types.SimpleNamespace] = <class 'types.SimpleNamespace'>)

First-class used to trace requests launched via ClientSession objects.

Inheritance

Inheritance diagram of TraceConfig

trace_config_ctx(trace_request_ctx: Optional[types.SimpleNamespace] = None)types.SimpleNamespace

Return a new trace_config_ctx instance

class alexapy.aiohttp.TraceConnectionCreateEndParams

Parameters sent by the on_connection_create_end signal

Inheritance

Inheritance diagram of TraceConnectionCreateEndParams

class alexapy.aiohttp.TraceConnectionCreateStartParams

Parameters sent by the on_connection_create_start signal

Inheritance

Inheritance diagram of TraceConnectionCreateStartParams

class alexapy.aiohttp.TraceConnectionQueuedEndParams

Parameters sent by the on_connection_queued_end signal

Inheritance

Inheritance diagram of TraceConnectionQueuedEndParams

class alexapy.aiohttp.TraceConnectionQueuedStartParams

Parameters sent by the on_connection_queued_start signal

Inheritance

Inheritance diagram of TraceConnectionQueuedStartParams

class alexapy.aiohttp.TraceConnectionReuseconnParams

Parameters sent by the on_connection_reuseconn signal

Inheritance

Inheritance diagram of TraceConnectionReuseconnParams

class alexapy.aiohttp.TraceDnsCacheHitParams(host: str)

Parameters sent by the on_dns_cache_hit signal

Inheritance

Inheritance diagram of TraceDnsCacheHitParams

class alexapy.aiohttp.TraceDnsCacheMissParams(host: str)

Parameters sent by the on_dns_cache_miss signal

Inheritance

Inheritance diagram of TraceDnsCacheMissParams

class alexapy.aiohttp.TraceDnsResolveHostEndParams(host: str)

Parameters sent by the on_dns_resolvehost_end signal

Inheritance

Inheritance diagram of TraceDnsResolveHostEndParams

class alexapy.aiohttp.TraceDnsResolveHostStartParams(host: str)

Parameters sent by the on_dns_resolvehost_start signal

Inheritance

Inheritance diagram of TraceDnsResolveHostStartParams

class alexapy.aiohttp.TraceRequestChunkSentParams(method: str, url: yarl.URL, chunk: bytes)

Parameters sent by the on_request_chunk_sent signal

Inheritance

Inheritance diagram of TraceRequestChunkSentParams

class alexapy.aiohttp.TraceRequestEndParams(method: str, url: yarl.URL, headers: CIMultiDict[str], response: alexapy.aiohttp.client_reqrep.ClientResponse)

Parameters sent by the on_request_end signal

Inheritance

Inheritance diagram of TraceRequestEndParams

class alexapy.aiohttp.TraceRequestExceptionParams(method: str, url: yarl.URL, headers: CIMultiDict[str], exception: BaseException)

Parameters sent by the on_request_exception signal

Inheritance

Inheritance diagram of TraceRequestExceptionParams

class alexapy.aiohttp.TraceRequestRedirectParams(method: str, url: yarl.URL, headers: CIMultiDict[str], response: alexapy.aiohttp.client_reqrep.ClientResponse)

Parameters sent by the on_request_redirect signal

Inheritance

Inheritance diagram of TraceRequestRedirectParams

class alexapy.aiohttp.TraceRequestStartParams(method: str, url: yarl.URL, headers: CIMultiDict[str])

Parameters sent by the on_request_start signal

Inheritance

Inheritance diagram of TraceRequestStartParams

class alexapy.aiohttp.TraceResponseChunkReceivedParams(method: str, url: yarl.URL, chunk: bytes)

Parameters sent by the on_response_chunk_received signal

Inheritance

Inheritance diagram of TraceResponseChunkReceivedParams

Exceptions

exception alexapy.aiohttp.ClientConnectionError

Base class for client socket errors.

Inheritance

Inheritance diagram of ClientConnectionError

exception alexapy.aiohttp.ClientConnectorCertificateError(connection_key: None, certificate_error: Exception)

Response certificate error.

Inheritance

Inheritance diagram of ClientConnectorCertificateError

exception alexapy.aiohttp.ClientConnectorError(connection_key: None, os_error: OSError)

Client connector error.

Raised in aiohttp.connector.TCPConnector if

connection to proxy can not be established.

Inheritance

Inheritance diagram of ClientConnectorError

exception alexapy.aiohttp.ClientConnectorSSLError(connection_key: None, os_error: OSError)

Response ssl error.

Inheritance

Inheritance diagram of ClientConnectorSSLError

exception alexapy.aiohttp.ClientError

Base class for client connection errors.

Inheritance

Inheritance diagram of ClientError

exception alexapy.aiohttp.ClientHttpProxyError(request_info: None, history: Tuple[None, ], *, code: Optional[int] = None, status: Optional[int] = None, message: str = '', headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None)

HTTP proxy error.

Raised in aiohttp.connector.TCPConnector if proxy responds with status other than 200 OK on CONNECT request.

Inheritance

Inheritance diagram of ClientHttpProxyError

exception alexapy.aiohttp.ClientOSError

OSError error.

Inheritance

Inheritance diagram of ClientOSError

exception alexapy.aiohttp.ClientPayloadError

Response payload error.

Inheritance

Inheritance diagram of ClientPayloadError

exception alexapy.aiohttp.ClientProxyConnectionError(connection_key: None, os_error: OSError)

Proxy connection error.

Raised in aiohttp.connector.TCPConnector if

connection to proxy can not be established.

Inheritance

Inheritance diagram of ClientProxyConnectionError

exception alexapy.aiohttp.ClientResponseError(request_info: None, history: Tuple[None, ], *, code: Optional[int] = None, status: Optional[int] = None, message: str = '', headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None)

Connection error during reading response.

request_info: instance of RequestInfo

Inheritance

Inheritance diagram of ClientResponseError

exception alexapy.aiohttp.ClientSSLError(connection_key: None, os_error: OSError)

Base error for ssl.*Errors.

Inheritance

Inheritance diagram of ClientSSLError

exception alexapy.aiohttp.ContentTypeError(request_info: None, history: Tuple[None, ], *, code: Optional[int] = None, status: Optional[int] = None, message: str = '', headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None)

ContentType found is not valid.

Inheritance

Inheritance diagram of ContentTypeError

exception alexapy.aiohttp.InvalidURL(url: Any)

Invalid URL.

URL used for fetching is malformed, e.g. it doesn’t contains host part.

Inheritance

Inheritance diagram of InvalidURL

exception alexapy.aiohttp.ServerConnectionError

Server connection errors.

Inheritance

Inheritance diagram of ServerConnectionError

exception alexapy.aiohttp.ServerDisconnectedError(message: Optional[str] = None)

Server disconnected.

Inheritance

Inheritance diagram of ServerDisconnectedError

exception alexapy.aiohttp.ServerFingerprintMismatch(expected: bytes, got: bytes, host: str, port: int)

SSL certificate does not match expected fingerprint.

Inheritance

Inheritance diagram of ServerFingerprintMismatch

exception alexapy.aiohttp.ServerTimeoutError

Server timeout error.

Inheritance

Inheritance diagram of ServerTimeoutError

exception alexapy.aiohttp.TooManyRedirects(request_info: None, history: Tuple[None, ], *, code: Optional[int] = None, status: Optional[int] = None, message: str = '', headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None)

Client was redirected too many times.

Inheritance

Inheritance diagram of TooManyRedirects

exception alexapy.aiohttp.WSServerHandshakeError(request_info: None, history: Tuple[None, ], *, code: Optional[int] = None, status: Optional[int] = None, message: str = '', headers: Optional[Union[Mapping[Union[str, multidict._multidict.istr], str], multidict._multidict.CIMultiDict, multidict._multidict.CIMultiDictProxy]] = None)

websocket server handshake error.

Inheritance

Inheritance diagram of WSServerHandshakeError

exception alexapy.aiohttp.WebSocketError(code: int, message: str)

WebSocket protocol parser error.

Inheritance

Inheritance diagram of WebSocketError

exception alexapy.aiohttp.BadContentDispositionHeader

Inheritance

Inheritance diagram of BadContentDispositionHeader

exception alexapy.aiohttp.BadContentDispositionParam

Inheritance

Inheritance diagram of BadContentDispositionParam

exception alexapy.aiohttp.EofStream

eof stream indication.

Inheritance

Inheritance diagram of EofStream

Variables

alexapy.aiohttp.hdrs

HTTP Headers constants.

<module 'alexapy.aiohttp.hdrs' from '/home/docs/checkouts/readthedocs.org/user_builds/alexapy/checkouts/latest/alexapy/aiohttp/hdrs.py'>
alexapy.aiohttp.HttpVersion10

HttpVersion(major, minor)

HttpVersion(major=1, minor=0)
alexapy.aiohttp.HttpVersion11

HttpVersion(major, minor)

HttpVersion(major=1, minor=1)
alexapy.aiohttp.PAYLOAD_REGISTRY

Payload registry.

note: we need zope.interface for more efficient adapter search

<alexapy.aiohttp.payload.PayloadRegistry object at 0x7fb4b798d190>
alexapy.aiohttp.EMPTY_PAYLOAD
<alexapy.aiohttp.streams.EmptyStreamReader object at 0x7fb4b79aac50>