Skip to content

Retry settings

sparqlite includes automatic retry with exponential backoff for transient errors. This helps your application handle temporary failures gracefully.

By default, sparqlite will:

  • Retry up to 5 times on transient errors
  • Use exponential backoff with a factor of 0.5
from sparqlite import SPARQLClient
# Default settings: max_retries=5, backoff_factor=0.5
with SPARQLClient("https://dbpedia.org/sparql") as client:
result = client.query(query)

Set the maximum number of retry attempts:

# Retry up to 3 times
with SPARQLClient("https://dbpedia.org/sparql", max_retries=3) as client:
result = client.query(query)
# Disable retries entirely
with SPARQLClient("https://dbpedia.org/sparql", max_retries=0) as client:
result = client.query(query)

Control the delay between retries. The wait time is calculated as:

wait_time = backoff_factor * (2 ^ attempt)

Example with backoff_factor=0.5:

  • Attempt 1: wait 1 second (0.5 * 2^1)
  • Attempt 2: wait 2 seconds (0.5 * 2^2)
  • Attempt 3: wait 4 seconds (0.5 * 2^3)
  • Attempt 4: wait 8 seconds (0.5 * 2^4)
  • Attempt 5: wait 16 seconds (0.5 * 2^5)
# Faster retries
with SPARQLClient("https://dbpedia.org/sparql", backoff_factor=0.25) as client:
result = client.query(query)
# Slower retries
with SPARQLClient("https://dbpedia.org/sparql", backoff_factor=1.0) as client:
result = client.query(query)

sparqlite automatically retries on these transient errors:

Error typeDescription
HTTP 5xxServer errors (500, 502, 503, etc.)
Connection failureCannot connect to the endpoint
TimeoutRequest timed out

These errors fail immediately without retry:

Error typeDescription
HTTP 400Query syntax error (QueryError)
HTTP 4xxClient errors (401, 403, 404, etc.)
Parse errorInvalid response format