Skip to content

HTTP methods

sparqlite supports both GET and POST HTTP methods for SPARQL requests, following the SPARQL 1.1 Protocol specification.

Each query type uses a default HTTP method:

Query typeDefault methodReason
SELECTGETRead operation, cacheable
ASKGETRead operation, cacheable
CONSTRUCTGETRead operation, cacheable
DESCRIBEGETRead operation, cacheable
UPDATEPOSTWrite operation (required by spec)

GET requests pass the query as a URL parameter (?query=...). POST requests pass the query in the request body as form-encoded data.

All read query methods accept a method keyword argument:

from sparqlite import SPARQLClient
with SPARQLClient("https://opencitations.net/meta/sparql") as client:
# Use POST for a long SELECT query that may exceed URL length limits
result = client.query(long_query, method="POST")
# Use POST for ASK
exists = client.ask(query, method="POST")
# Use POST for CONSTRUCT
triples = client.construct(query, method="POST")
# Use POST for DESCRIBE
data = client.describe(query, method="POST")

Use method="POST" when:

  • The query string is very long and may exceed URL length limits (typically 2000-8000 characters depending on the server)
  • You want to avoid caching of results
with SPARQLClient("https://opencitations.net/meta/sparql") as client:
long_query = "SELECT * WHERE { " + " UNION ".join(
f"{{ ?s <http://example.org/p{i}> ?o }}" for i in range(100)
) + " }"
# POST avoids URL length issues
result = client.query(long_query, method="POST")