Welcome to rdflib-web’s documentation!¶
rdflib_web
Package¶
rdflib-web contains two Flask Blueprints for exposing a
SPARQL Endpoint
and a Linked Open Data application for machine- and
human-readable views of resources.
endpoint
Module¶
This is a Flask Blueprint for a SPARQL Endpoint
confirming to the
SPARQL 1.0 Protocol.
You can add the blueprint endpoint object to your own application:
from rdflib_web.endpoint import endpoint
app = Flask(__name__)
...
app.config['graph'] = my_rdflib_graph
app.register_blueprint(endpoint)
Or the application can be started from commandline:
python -m rdflib_web.endpoint <RDF-file>
or if you installed with pip, commands rdflodapp
has been added to your path:
rdflodapp <RDF-file>
Either way, the endpoint will be available at http://localhost:5000
You can also start the server from your application by calling the serve()
method
or get the application object yourself by called get()
function
-
rdflib_web.endpoint.
get
(ds)¶ Get the LOD Flask App setup to serve the given dataset
-
rdflib_web.endpoint.
serve
(ds, debug=False)¶ Serve the given dataset on localhost with the LOD App
lod
Module¶
This is a Flask web-app for a simple Linked Open Data Web-app
it also includes a SPARQL 1.0 Endpoint
.
You can add the blueprint lod object to your own application:
from rdflib_web.lod import lod
app = Flask(__name__)
...
app.config['graph'] = my_rdflib_graph
app.register_blueprint(lod)
Or the application can be started from commandline:
python -m rdflib_web.lod <RDF-file>
or if you installed with pip, commands rdflodapp
has been added to your path:
rdflodapp <RDF-file>
Either way, the file will be served from http://localhost:5000
You can also start the server from your application by calling the serve()
method
or get the application object yourself by called get()
function
The application creates local URIs based on the type of resources and servers content-negotiated HTML or serialised RDF from these.
-
rdflib_web.lod.
get
(graph, types='auto', image_patterns=['\\.[png|jpg|gif]$'], label_properties=[rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.URIRef(u'http://purl.org/dc/elements/1.1/title'), rdflib.term.URIRef(u'http://xmlns.com/foaf/0.1/name'), rdflib.term.URIRef(u'http://www.w3.org/2006/vcard/ns#fn'), rdflib.term.URIRef(u'http://www.w3.org/2006/vcard/ns#org')], hierarchy_properties=[rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#subClassOf'), rdflib.term.URIRef(u'http://www.w3.org/2000/01/rdf-schema#subPropertyOf')], add_types_labels=True, dbname='RDFLib LOD App')¶ Get the LOD Flask App setup to serve the given graph
-
rdflib_web.lod.
serve
(graph_, debug=False)¶ Serve the given graph on localhost with the LOD App
Utilities¶
bookdb
Module¶
A tiny test graph with Book meta-data
caches
Module¶
LRU and LFU Caching decorators taken from py3.2
-
rdflib_web.caches.
lfu_cache
(maxsize=100)¶ Least-frequenty-used cache decorator.
Arguments to the cached function must be hashable. Cache performance statistics stored in f.hits and f.misses. Clear the cache with f.clear(). http://en.wikipedia.org/wiki/Least_Frequently_Used
-
rdflib_web.caches.
lru_cache
(maxsize=100)¶ Least-recently-used cache decorator.
Arguments to the cached function must be hashable. Cache performance statistics stored in f.hits and f.misses. http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used
htmlresults
Module¶
SPARQL Result Serializer and RDF Serializer for nice human readable HTML tables
>>> from rdflib import RDF, RDFS, XSD, Graph, Literal
>>> g=Graph()
>>> g.add((RDF.Property, RDF.type, RDFS.Class))
>>> g.add((RDF.Property, RDFS.label, Literal('Property')))
>>> g.add((RDF.Property, RDFS.label, Literal('Property', datatype=XSD.string)))
>>> g.add((RDF.Property, RDFS.label, Literal('Eigenschaft', lang='de')))
>>> s=g.query('select * where { ?s ?p ?o . }').serialize(format='html')
>>> 'rdf:type' in s
True
>>> '@de' in s
True
>>> '^^<xsd:string>' in s
True
-
class
rdflib_web.htmlresults.
HTMLResultSerializer
(result)¶ Bases:
rdflib.query.ResultSerializer
-
serialize
(stream, encoding='utf-8')¶
-
-
class
rdflib_web.htmlresults.
HTMLSerializer
(store)¶ Bases:
rdflib.serializer.Serializer
Serializes RDF graphs as HTML tables
-
serialize
(stream, base=None, encoding=None, **args)¶
-
-
rdflib_web.htmlresults.
qname
(ctx, t)¶
-
rdflib_web.htmlresults.
term_to_string
(ctx, t)¶