Skip to content
Client and Config

Client and Config

scixplorer.config

The Config instance every client uses unless it is given its own. Written config; change its attributes to change the settings.

SettingDefaultMeaning
tokenNoneYour API token, or None to look in the environment and the token files.
api_url'https://api.scixplorer.org/v1'The base URL of the API.
timeout30.0Seconds allowed for each HTTP request.
max_retries3How many times a transient failure is retried.
retry_backoff1.0Seconds before the first retry; each later retry waits twice as long.
page_size200Documents requested per search request (at most 2000 are used).
max_inline_bibcodes50Larger bibcode sets are uploaded to /search/bigquery or excluded client-side.
library_membership'docs'"docs": SciX tests library membership with docs(library/<id>); "bibcodes": the client fetches the library’s bibcodes first.
collectionNoneLimit open document searches to a collection (a str) or several (a list); None for all.

scixplorer._config.Config

Written Config after from scixplorer import Config.

Config(token=None, api_url='https://api.scixplorer.org/v1', timeout=30.0, max_retries=3, retry_backoff=1.0, page_size=200, max_inline_bibcodes=50, library_membership='docs', collection=None)

class

Settings for talking to the SciX API.

The module-level instance is config. The HTTP client reads it at send time, so changing an attribute affects every later request. token is your API token; it is excluded from repr, so it never ends up in logs or tracebacks. collection limits open document searches to one SciX collection or several (see resolve_collections); None, the default, searches them all. The table of settings is above.

scixplorer._config.Config.resolve_token

resolve_token()

Return the API token to use, or None if none can be found.

Sources are checked in order and the first that yields a token wins: token, the environment variables SCIX_API_TOKEN, ADS_API_TOKEN and ADS_DEV_KEY, then the first line of ~/.scix/token, ~/.ads/token and ~/.ads/dev_key. Values are whitespace-stripped and empty values are skipped. The environment and the files are read on every call.

scixplorer._config.Config.resolve_collections

resolve_collections()

Return the collections that open document searches are limited to; empty for all.

collection is None, a str or a sequence of str. Names are whitespace-stripped, blank ones dropped and duplicates dropped keeping the first; they are not checked against the collections SciX has. Raises TypeError for any other value.

scixplorer.client.Client

Written Client after from scixplorer import Client.

Client(token=None, *, config=None, transport=None, async_transport=None, sleep=time.sleep, async_sleep=asyncio.tasks.sleep, now=scixplorer.client._utcnow)

class

Executes Request objects against the SciX API, sync or async.

The underlying httpx.Client and httpx.AsyncClient are created on first use. close() closes the sync one; aclose() closes both. A closed Client creates fresh ones if used again. A Client is not thread-safe: lazy creation and the rate-limit bookkeeping are unsynchronised.

Parameters

  • token: your API token. If omitted or blank, config.resolve_token() is used. The token is resolved on every request and never appears in repr or exception messages.
  • config: settings to use; defaults to the module-level config. Its api_url, timeout, max_retries and retry_backoff are read on every request.
  • transport: optional httpx transport for the sync client.
  • async_transport: optional httpx transport for the async client.
  • sleep: called with the delay between sync retries.
  • async_sleep: awaited with the delay between async retries.
  • now: returns the current time as an aware UTC datetime; compared with rate-limit reset times.

scixplorer.client.Client.send

send(request)

Execute request and return its response, retrying transient failures.

Idempotent requests are retried after connection errors, timeouts and HTTP 502/503/504. Non-idempotent requests (see Request.is_idempotent) are retried only if the connection could not be made, since otherwise the server may already have applied them.

Raises exceptions.AuthenticationError if there is no token or SciX rejects it, exceptions.RateLimitExceeded when the rate limit for the request’s service is used up (without sending the request if that is already known), and exceptions.APIError for any other failure.

scixplorer.client.Client.asend

async def asend(request)

Asynchronous send; identical behaviour and exceptions.

scixplorer.client.Client.close

close()

Close the underlying sync httpx.Client, if one was created.

scixplorer.client.Client.aclose

async def aclose()

Close the underlying httpx clients (async and sync), if created.

scixplorer.client.Client.rate_limits

attribute rate_limits

A dict from service (such as "search/query") to the RateLimit SciX last reported for it.

scixplorer.client.get_default_client

Written get_default_client after from scixplorer import get_default_client.

get_default_client()

Return the shared default Client, creating it on first use.

The default client uses the module-level config (scixplorer._config.config).

scixplorer.client.set_default_client

Written set_default_client after from scixplorer import set_default_client.

set_default_client(client)

Replace the shared default client; None makes the next get_default_client call create a fresh one. The previous client is not closed.

scixplorer.client.Request

Request(method, path, params=None, json=None, content=None, headers=None, idempotent=None)

class

One HTTP request to the ADS API, described without performing it.

path is relative to Config.api_url (a leading slash is optional). params values may be str, int, float, bool or None; None values are dropped and booleans are sent as true/false. At most one of json (a JSON body) and content (a raw body, sent with the caller’s Content-Type header) may be given; json=None means no JSON body. Construction raises TypeError for an unsupported parameter value and ValueError if both bodies are given.

idempotent says whether sending the request twice has the same effect as sending it once, which decides how it may be retried (see Client.send). None infers it from the method (see is_idempotent); set it to True for a POST that only reads, such as /search/bigquery.

scixplorer.client.Request.is_idempotent

property is_idempotent

idempotent if set, else whether the method is in IDEMPOTENT_METHODS.

So GET, HEAD, PUT and DELETE are idempotent by default; POST and PATCH are not.

scixplorer.client.Response

Response(status_code, headers, data)

class

The parts of an HTTP response that backends need.

headers is a plain dict with lower-cased keys (repeated headers are joined with ", "), so look headers up in lower case. data is the parsed JSON body if the body is valid JSON (whatever the declared content type), otherwise the body text, or None if the body is empty.

scixplorer.client.RateLimit

RateLimit(limit, remaining, reset)

class

The rate-limit state ADS last reported for one service.