Retry settings
sparqlite includes automatic retry with exponential backoff for transient errors. This helps your application handle temporary failures gracefully.
Default behavior
Section titled “Default behavior”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.5with SPARQLClient("https://dbpedia.org/sparql") as client: result = client.query(query)Configuring retries
Section titled “Configuring retries”max_retries
Section titled “max_retries”Set the maximum number of retry attempts:
# Retry up to 3 timeswith SPARQLClient("https://dbpedia.org/sparql", max_retries=3) as client: result = client.query(query)
# Disable retries entirelywith SPARQLClient("https://dbpedia.org/sparql", max_retries=0) as client: result = client.query(query)backoff_factor
Section titled “backoff_factor”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 retrieswith SPARQLClient("https://dbpedia.org/sparql", backoff_factor=0.25) as client: result = client.query(query)
# Slower retrieswith SPARQLClient("https://dbpedia.org/sparql", backoff_factor=1.0) as client: result = client.query(query)What triggers retry
Section titled “What triggers retry”sparqlite automatically retries on these transient errors:
| Error type | Description |
|---|---|
| HTTP 5xx | Server errors (500, 502, 503, etc.) |
| Connection failure | Cannot connect to the endpoint |
| Timeout | Request timed out |
What does NOT trigger retry
Section titled “What does NOT trigger retry”These errors fail immediately without retry:
| Error type | Description |
|---|---|
| HTTP 400 | Query syntax error (QueryError) |
| HTTP 4xx | Client errors (401, 403, 404, etc.) |
| Parse error | Invalid response format |