See https://rdflib.readthedocs.io for our documentation built from the code. Note that there are latest, stable and versioned builds, such as 5.0.0, matching releases.
Installation
The stable release of RDFLib may be installed with Python's package management tool pip:
$ pip install rdflib
Some features of RDFLib require optional dependencies which may be installed using pip extras:
from rdflib import Graph, URIRef, Literal
from rdflib.namespace import RDFS, XSD
g = Graph()
semweb = URIRef('http://dbpedia.org/resource/Semantic_Web')
type = g.value(semweb, RDFS.label)
Where RDFS is the RDFS namespace, XSD the XML Schema Datatypes namespace and g.value returns an object of the triple-pattern given (or an arbitrary one if multiple exist).
The triple (in n-triples notation) <http://example.com/person/nick> <http://xmlns.com/foaf/0.1/givenName> "Nick"^^<http://www.w3.org/2001/XMLSchema#string> .
is created where the property FOAF.givenName is the URI <http://xmlns.com/foaf/0.1/givenName> and XSD.string is the
URI <http://www.w3.org/2001/XMLSchema#string>.
You can bind namespaces to prefixes to shorten the URIs for RDF/XML, Turtle, N3, TriG, TriX & JSON-LD serializations:
g.bind("foaf", FOAF)
g.bind("xsd", XSD)
This will allow the n-triples triple above to be serialised like this:
Running test coverage on the host with coverage report
Run the test suite and generate a HTML coverage report with pytest and pytest-cov.
poetry run pytest --cov
Viewing test coverage
Once tests have produced HTML output of the coverage report, view it by running:
poetry run pytest --cov --cov-report term --cov-report html
python -m http.server --directory=htmlcov
Contributing
RDFLib survives and grows via user contributions!
Please read our contributing guide and developers guide to get started.
Please consider lodging Pull Requests here:
rdflib-jsonldPythie’s Index: 20rdflib extension adding JSON-LD parser and serializer1.2M downloads/mo
owlrlPythie’s Index: 67A simple implementation of the OWL2 RL Profile, as well as a basic RDFS inference, on top of RDFLib. Based mechanical forward chaining.2.4M downloads/mo