Low-level client for D-Wave APIs. A thin wrapper around `requests.Session` that handles API specifics such as authentication, response and error parsing, retrying, etc. Note: To make sure the session is closed, call :meth:`.close`, or use the context manager form (as sho
| 769 | |
| 770 | |
| 771 | class DWaveAPIClient: |
| 772 | """Low-level client for D-Wave APIs. A thin wrapper around |
| 773 | `requests.Session` that handles API specifics such as authentication, |
| 774 | response and error parsing, retrying, etc. |
| 775 | |
| 776 | Note: |
| 777 | To make sure the session is closed, call :meth:`.close`, or use the |
| 778 | context manager form (as show in the example below). |
| 779 | |
| 780 | Note: |
| 781 | Since :class:`requests.Session` is **not thread-safe**, neither is |
| 782 | :class:`DWaveAPIClient`. It's best to create (and dispose) a new client |
| 783 | on demand, in each thread. |
| 784 | |
| 785 | Example: |
| 786 | >>> with DWaveAPIClient(endpoint='...', timeout=(5, 600)) as client: # doctest: +SKIP |
| 787 | ... client.session.get('...') |
| 788 | |
| 789 | """ |
| 790 | |
| 791 | class DefaultSession(VersionedAPISessionMixin, |
| 792 | DeprecationAwareSessionMixin, |
| 793 | PayloadCompressingSessionMixin, |
| 794 | BaseUrlSessionMixin, |
| 795 | CachingSessionMixin, |
| 796 | LoggingSessionMixin, |
| 797 | requests.Session): |
| 798 | """Default session class is based on `requests.Session` extended with |
| 799 | base url, logging, compressing, API versioning and caching mixins. |
| 800 | """ |
| 801 | |
| 802 | DEFAULTS = { |
| 803 | 'session_class': DefaultSession, |
| 804 | |
| 805 | 'endpoint': None, |
| 806 | 'token': None, |
| 807 | 'cert': None, |
| 808 | |
| 809 | # (connect, read) timeout in sec |
| 810 | 'timeout': (60, 120), |
| 811 | |
| 812 | # urllib3.Retry options |
| 813 | 'retry': dict(total=10, backoff_factor=0.01, backoff_max=60), |
| 814 | |
| 815 | # optional additional headers |
| 816 | 'headers': None, |
| 817 | |
| 818 | # ssl verify |
| 819 | 'verify': True, |
| 820 | |
| 821 | # proxy urls, see :attr:`requests.Session.proxies` |
| 822 | 'proxies': None, |
| 823 | |
| 824 | # number of most recent request records to keep in :attr:`.session.history` |
| 825 | 'history_size': 0, |
| 826 | |
| 827 | # preemptive payload compression on upload requests, see :class:`PayloadCompressingSession` |
| 828 | 'compress': False, |
no outgoing calls