Skip to content

How to get started ?

The data format returned by the API can be controlled using the Accept header.

Valid values are application/rdf+xml, application/n-triples, application/ld+json, application/n-quads, application/trix, application/trig and text/turtle - the default format.

While it's possible to use the command line with curl, Python is used in the remaining part of this guide using the module RDFLib.

It's also possible to use the module Owlready2

curl -X 'GET' \
'https://w3id.clouddataengine.io/admin-loc/v1.0/countries' \
-H 'accept: text/turtle'
pip install rdflib

Info

The full CDE API is available at https://www.w3id.org/cde/docs.

How to load RDF data from the CDE API

from rdflib import Graph
g = Graph()
g.parse("https://w3id.clouddataengine.io/admin-loc/v1.0/countries")
print(f"fetched {len(g)} tuples")
for s, o, p in g:
  print(s, o, p)

How to query data from a loaded graph

q = """
PREFIX adloc:  <https://w3id.org/cde/admin-loc/v1.0/#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT ?name
WHERE {
    ?p rdf:type adloc:AdministrativeLocation .
    ?p rdfs:label ?name .
}
"""

# Apply the query to the graph and iterate through results
for r in g.query(q):
    print(r["name"])