Hi Jamie.
I think what you're looking for is to export a named graph contained in a database which is what that "download" button is doing in Studio.
REST API: API Reference | ReDoc -
Note: I think what may be missing from this documentation is the
graph_uri
query parameter which will allow you to export just a named graph from the database instead of the entire database.
pystardog docs: Modules — pystardog documentation
Below is example using pystardog that shows how to export a graph/model 2 different ways.
- with streaming the contents of the model/graph back (avoids reading the graph into memory all at once - useful for large graphs)
- just getting the contents of the graph back all at once:
import stardog
connection_details = {
"endpoint": "https://sd-######.stardog.cloud:5820",
"username": "someuser",
"password": "somepassword",
"database": "my_database",
}
model_uri = "urn:example:starwars:model"
# streams an export of the graph/model serialized as Turtle
# a generator that yields bytes making up the graph/model is returned
# avoids reading the graph/model at once into memory for large graph/models
# `chunk_size` parameter available to control the amount of bytes to read per chunk when streaming
model = ""
with stardog.Connection(**connection_details) as conn:
with conn.export(
graph_uri=model_uri, stream=True, content_type=stardog.content_types.TURTLE
) as stream:
for chunk in stream:
model += chunk.decode("utf-8")
print(f"---MODEL (STREAMED)---\n{model}\n\n")
# exports the graph/model serialized as turtle
# send whole response (graph/model) back as as bytes
with stardog.Connection(**connection_details) as conn:
model = conn.export(graph_uri=model_uri, content_type=stardog.content_types.TURTLE)
print(f"---MODEL---\n{model.decode('utf-8')}")
Hope that helps!
Cheers,
Noah