Awesome Open Source
Awesome Open Source


Build Status Coveralls branch GitHub stars PyPI PyPI

RDFLib is a pure Python package for working with RDF. RDFLib contains most things you need to work with RDF, including:

  • parsers and serializers for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, Trig and JSON-LD (via a plugin).
  • a Graph interface which can be backed by any one of a number of Store implementations
  • store implementations for in-memory storage and persistent storage on top of the Berkeley DB
  • a SPARQL 1.1 implementation - supporting SPARQL 1.1 Queries and Update statements

RDFlib Family of packages

The RDFlib community maintains many RDF-related Python code repositories with different purposes. For example:

  • rdflib - the RDFLib core
  • sparqlwrapper - a simple Python wrapper around a SPARQL service to remotely execute your queries
  • pyLODE - An OWL ontology documentation tool using Python and templating, based on LODE.
  • rdflib-jsonld - an RDFLib plugin that is an implementation of JSON-LD

Please see the list for all packages/repositories here:


  • 5.x.y supports Python 2.7 and 3.4+ and is mostly backwards compatible with 4.2.2. Only bug fixes will be applied.
  • 6.x.y is the next major release which will support Python 3.6+. (Current master branch)


RDFLib may be installed with Python's package management tool pip:

$ pip install rdflib

Alternatively manually download the package from the Python Package Index (PyPI) at

The current version of RDFLib is 5.0.0, see the file for what's new in this release.

Installation of the current master branch (for developers)

With pip you can also install rdflib from the git repository with one of the following options:

$ pip install git+[email protected]
# or
$ pip install -e git+[email protected]#egg=rdflib

or from your locally cloned repository you can install it with one of the following options:

$ python install
# or
$ pip install -e .

Getting Started

RDFLib aims to be a pythonic RDF API. RDFLib's main data object is a Graph which is a Python collection of RDF Subject, Predicate, Object Triples:

To create graph and load it with RDF data from DBPedia then print the results:

import rdflib
g = rdflib.Graph()

for s, p, o in g:
    print(s, p, o)

The components of the triples are URIs (resources) or Literals (values).

URIs are grouped together by namespace, common namespaces are included in RDFLib:

from rdflib.namespace import DC, DCTERMS, DOAP, FOAF, SKOS, OWL, RDF, RDFS, VOID, XMLNS, XSD

You can use them like this:

semweb = rdflib.URIRef('')
type = g.value(semweb, rdflib.RDFS.label)

Where rdflib.RDFS is the RDFS Namespace, graph.value returns an object of the triple-pattern given (or an arbitrary one if more exist).

Or like this, adding a triple to a graph g:

    rdflib.Literal("Nick", datatype=XSD.string)

The triple (in n-triples notation) <> <> "Nick"^^<> . is created where the property FOAF.giveName is the URI <> and XSD.string is the URI <>.

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:


With these results:

PREFIX foaf: <>
PREFIX xsd: <>

<> foaf:givenName "Nick"^^xsd:string .

New Namespaces can also be defined:

dbpedia = rdflib.Namespace('')

abstracts = list(x for x in g.objects(semweb, dbpedia['abstract']) if x.language=='en')

See also ./examples


The library contains parsers and serializers for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, RDFa and Microdata. JSON-LD parsing/serializing can be achieved using the JSON-LD plugin.

The library presents a Graph interface which can be backed by any one of a number of Store implementations.

This core RDFLib package includes store implementations for in-memory storage and persistent storage on top of the Berkeley DB.

A SPARQL 1.1 implementation is included - supporting SPARQL 1.1 Queries and Update statements.

RDFLib is open source and is maintained on GitHub. RDFLib releases, current and previous are listed on PyPI

Multiple other projects are contained within the RDFlib "family", see


See for our documentation built from the code.


For general "how do I..." queries, please use and tag your question with rdflib. Existing questions:


See for the release schedule.


RDFLib survives and grows via user contributions! Please read our contributing guide to get started. Please consider lodging Pull Requests here:

You can also raise issues here:


If you want to contact the rdflib maintainers, please do so via the rdflib-dev mailing list:

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (51,910
parser (499
graph (391
python-library (145
pypi (142
rdf (82
serializer (67
json-ld (47
semantic-web (40
linked-data (39
uri (28
namespace (23

Find Open Source By Browsing 7,000 Topics Across 59 Categories