:class:`~.CasJobsUrllib3Client` ==================================================================================================================================================== .. py:class:: astropathdb.db_io.dbconnect.CasJobsUrllib3Client :single-line-parameter-list: Bases: :class:`~.CasJobsTask` Execute queries against CasJobs RESTAPI using ``urllib3``. We optimize request to allow for use with ``urllib3`` and allow submission of a list of queries to be passed in parallel. This class will keep the connection pool open so that requests do not need a new connection. .. danger:: As noted throughout this module, this was not designed as a user facing module or as a replacement for the ``SciScript-Python``. :class:`~.astropathdb.db_io.dbconnect.CasJobsUrllib3Client` *Attributes* ---------------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.dbconnect.CasJobsUrllib3Client.http :class:`~.astropathdb.db_io.dbconnect.CasJobsUrllib3Client` *Methods* ---------------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.dbconnect.CasJobsUrllib3Client.execute_query_single astropathdb.db_io.dbconnect.CasJobsUrllib3Client.execute_query_futures astropathdb.db_io.dbconnect.CasJobsUrllib3Client.execute_query astropathdb.db_io.dbconnect.CasJobsUrllib3Client.get_taskname astropathdb.db_io.dbconnect.CasJobsUrllib3Client.set_headers astropathdb.db_io.dbconnect.CasJobsUrllib3Client.format_data :class:`~.astropathdb.db_io.dbconnect.CasJobsUrllib3Client` *References* ---------------------------------------------------------------------------------------------------------------------------------------------------- .. py:currentmodule:: astropathdb.db_io.dbconnect.CasJobsUrllib3Client *Attribute Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:attribute:: http Shared connection pool so requests reuse open connections. Holds up to 30 connections and blocks when all are in use. 'Service Unavailable' (503) responses to POST requests are retried up to 15 times with jittered backoff. Verifies TLS against the operating system's trust store and the ``certifi`` bundle. *Method Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:method:: execute_query_single(sql, context = CASJOBSDCONST.DEFAULT_DATABASE, _format = CASJOBSDCONST.DEFAULT_RETURNTYPE, *, _futures = False, **_) :single-line-parameter-list: Execute one synchronous SQL query in a ``CasJobs`` database context. Extra keyword arguments, such as ``nthreads`` forwarded by :meth:`~.CasJobsUrllib3Client.execute_query`, are ignored. :param sql: The SQL query. :param context: The database context. :param _format: The output format name. See :meth:`~.SciBase.query` for the output formats. :param _futures: Whether the request runs inside :meth:`~.CasJobsUrllib3Client.execute_query_futures`. If ``True``, reuses the headers already set and returns the first raw result set dictionary unformatted. :returns: The result sets in the ``_format`` output format. :raises CasJobsRequestError: The request did not complete, for example because retries were exhausted or the connection dropped. :raises CasJobsConnectionError: The CasJobs API returned an error status. :raises CasJobsConnectionRefusedError: The CasJobs API refused the authentication token. .. seealso:: ``SciServer.CasJobs.executeQuery`` for the ``SciScript-Python`` equivalent. .. py:method:: execute_query_futures(sql, context = CASJOBSDCONST.DEFAULT_DATABASE, _format = CASJOBSDCONST.DEFAULT_RETURNTYPE, nthreads = CASJOBSDCONST.DEFAULT_THREADS) :single-line-parameter-list: Execute SQL queries in parallel in a ``CasJobs`` database context. Only the first result set of each query is kept. Results are gathered in completion order, not input order. :param sql: The SQL queries. :param context: The database context. :param _format: The output format name. See :meth:`~.SciBase.query` for the output formats. :param nthreads: Number of threads used to run the queries. :returns: The result sets in the ``_format`` output format. :raises CasJobsFuturesConnectionError: One or more queries failed; holds each query's error. .. seealso:: :meth:`~.CasJobsUrllib3Client.execute_query_single` .. py:method:: execute_query(sql, *args, **kwargs) :single-line-parameter-list: Execute one SQL query, or a sequence of queries in parallel. A string runs through :meth:`~.CasJobsUrllib3Client.execute_query_single`; any other iterable runs through :meth:`~.CasJobsUrllib3Client.execute_query_futures`. :param sql: The SQL query or queries. :param args: Positional arguments for the selected method. :param kwargs: Keyword arguments for the selected method. :returns: The result sets in the requested output format. :raises InvalidSQLFormatError: ``sql`` is neither a string nor an iterable. .. py:method:: get_taskname(task_id) :single-line-parameter-list: :staticmethod: Get the ``CasJobs`` task name for a local or SciServer compute client. :param task_id: The task id (ex: 'executeQuery'). :returns: ``'Compute.SciScript-Python.CasJobs.'`` in a SciServer compute environment, otherwise ``'SciScript-Python.CasJobs.'``. .. py:method:: set_headers(accept_format) :single-line-parameter-list: Set the token and 'Accept' in :attr:`~.CasJobsTask._headers` for next requests. :param accept_format: The output format name. See :meth:`~.SciBase.query` for the output formats. .. py:method:: format_data(sql, task_id) :single-line-parameter-list: :staticmethod: Format ``sql`` and ``task_id`` as a JSON request body. :param sql: The SQL query to pass. :param task_id: The task name for the query. :returns: The JSON-encoded request body. *Private Method Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:method:: _validate_response(response) :single-line-parameter-list: Raise if the response status is not 'OK' (200). :raises CasJobsConnectionRefusedError: The token was refused (401) outside a SciServer compute environment. :raises CasJobsConnectionError: Any other non-200 status.