<commit_before>.. _aiohttp-client-reference:

HTTP Client Reference
=====================

.. module:: aiohttp

.. currentmodule:: aiohttp


Client Session
--------------

Client session is the recommended interface for making HTTP requests.

Session encapsulates *connection pool* (*connector* instance) and
supports keepalives by default.

Usage example::

     import aiohttp
     import asyncio

     async def fetch(client):
         async with client.get('http://python.org') as resp:
             assert resp.status == 200
             print(await resp.text())

     with aiohttp.ClientSession() as client:
         asyncio.get_event_loop().run_until_complete(fetch(client))

.. versionadded:: 0.17

The client session supports context manager protocol for self closing.

.. class:: ClientSession(*, connector=None, loop=None, cookies=None,\
                         headers=None, skip_auto_headers=None, \
                         auth=None, request_class=ClientRequest,\
                         response_class=ClientResponse, \
                         ws_response_class=ClientWebSocketResponse)

   The class for creating client sessions and making requests.

   :param aiohttp.connector.BaseConnector connector: BaseConnector
      sub-class instance to support connection pooling.

   :param loop: :ref:`event loop<asyncio-event-loop>` used for
      processing HTTP requests.

      If *loop* is ``None`` the constructor
      borrows it from *connector* if specified.

      :func:`asyncio.get_event_loop` is used for getting default event
      loop otherwise.

   :param dict cookies: Cookies to send with the request (optional)

   :param headers: HTTP Headers to send with
                   the request (optional).

                   May be either *iterable of key-value pairs* or<commit_msg> Show how the caller can get back the HTML text (#937)<commit_after>.. _aiohttp-client-reference:

HTTP Client Reference
=====================

.. module:: aiohttp

.. currentmodule:: aiohttp


Client Session
--------------

Client session is the recommended interface for making HTTP requests.

Session encapsulates *connection pool* (*connector* instance) and
supports keepalives by default.

Usage example::

     import aiohttp
     import asyncio

     async def fetch(client):
         async with client.get('http://python.org') as resp:
             assert resp.status == 200
             return await resp.text()

     with aiohttp.ClientSession() as client:
         html = asyncio.get_event_loop().run_until_complete(fetch(client))
         print(html)

.. versionadded:: 0.17

The client session supports context manager protocol for self closing.

.. class:: ClientSession(*, connector=None, loop=None, cookies=None, \
                         headers=None, skip_auto_headers=None, \
                         auth=None, request_class=ClientRequest, \
                         response_class=ClientResponse, \
                         ws_response_class=ClientWebSocketResponse)

   The class for creating client sessions and making requests.

   :param aiohttp.connector.BaseConnector connector: BaseConnector
      sub-class instance to support connection pooling.

   :param loop: :ref:`event loop<asyncio-event-loop>` used for
      processing HTTP requests.

      If *loop* is ``None`` the constructor
      borrows it from *connector* if specified.

      :func:`asyncio.get_event_loop` is used for getting default event
      loop otherwise.

   :param dict cookies: Cookies to send with the request (optional)

   :param headers: HTTP Headers to send with
                   the request (optional).

                   May be either *iterable of key-value pairs* or
{'fraction_non_alphanumeric': 0.09521233432512849, 'fraction_numerical': 0.004057343792263998, 'mean_word_length': 2.6361848574237956, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686222', 'n_tokens_mistral': 961, 'n_tokens_neox': 897, 'n_words': 325}