All Projects → RDFLib → Rdflib

RDFLib / Rdflib

Licence: other
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.

Programming Languages

python
139335 projects - #7 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Rdflib

Pyld
JSON-LD processor written in Python
Stars: ✭ 413 (-73.93%)
Mutual labels:  linked-data, rdf, json-ld, semantic-web
Jsonld.js
A JSON-LD Processor and API implementation in JavaScript
Stars: ✭ 1,212 (-23.48%)
Mutual labels:  linked-data, rdf, json-ld, semantic-web
Hypergraphql
GraphQL interface for querying and serving linked data on the Web.
Stars: ✭ 120 (-92.42%)
Mutual labels:  linked-data, rdf, json-ld, semantic-web
Php Json Ld
PHP implementation of a JSON-LD Processor and API
Stars: ✭ 246 (-84.47%)
Mutual labels:  linked-data, rdf, json-ld, semantic-web
ont-api
ONT-API (OWL-API over Apache Jena)
Stars: ✭ 20 (-98.74%)
Mutual labels:  rdf, semantic-web, turtle, triples
Hypergraphql
GraphQL interface for querying and serving linked data on the Web.
Stars: ✭ 112 (-92.93%)
Mutual labels:  linked-data, rdf, json-ld, semantic-web
Rdf
RDF.rb is a pure-Ruby library for working with Resource Description Framework (RDF) data.
Stars: ✭ 353 (-77.71%)
Mutual labels:  graph, linked-data, rdf, semantic-web
Rdflib Jsonld
JSON-LD parser and serializer plugins for RDFLib (Python 2.6+)
Stars: ✭ 250 (-84.22%)
Mutual labels:  rdf, serializer, json-ld, parser
titanium-json-ld
A JSON-LD 1.1 Processor & API
Stars: ✭ 79 (-95.01%)
Mutual labels:  linked-data, rdf, semantic-web, json-ld
twinql
A graph query language for the semantic web
Stars: ✭ 17 (-98.93%)
Mutual labels:  linked-data, rdf, semantic-web, json-ld
jsonld-context-parser.js
Parses JSON-LD contexts
Stars: ✭ 20 (-98.74%)
Mutual labels:  linked-data, rdf, semantic-web, json-ld
jsonld-streaming-serializer.js
A fast and lightweight streaming JSON-LD serializer for JavaScript
Stars: ✭ 20 (-98.74%)
Mutual labels:  linked-data, rdf, serializer, json-ld
YALC
🕸 YALC: Yet Another LOD Cloud (registry of Linked Open Datasets).
Stars: ✭ 14 (-99.12%)
Mutual labels:  linked-data, rdf, semantic-web, json-ld
Serd
A lightweight C library for RDF syntax
Stars: ✭ 43 (-97.29%)
Mutual labels:  rdf, serializer, semantic-web, parser
semantic-web
Storing ontologies/vocabularies from the web. Wish anybody can translate some of them.
Stars: ✭ 114 (-92.8%)
Mutual labels:  rdf, semantic-web, turtle
LinkedDataHub
The Knowledge Graph notebook. Apache license.
Stars: ✭ 150 (-90.53%)
Mutual labels:  linked-data, rdf, semantic-web
hexadb
A schemaless graph database based on RocksDb
Stars: ✭ 33 (-97.92%)
Mutual labels:  graph, linked-data, triples
joseki
Pure Go library for working with RDF, a powerful framework for representing informations as graphs.
Stars: ✭ 27 (-98.3%)
Mutual labels:  rdf, rdflib, turtle
Sparql.js
A parser for the SPARQL query language in JavaScript
Stars: ✭ 271 (-82.89%)
Mutual labels:  rdf, serializer, parser
Jsonld
JSON-LD processor for PHP
Stars: ✭ 280 (-82.32%)
Mutual labels:  linked-data, json-ld, semantic-web

RDFLib

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
  • a Graph interface which can be backed by any one of a number of Store implementations
  • store implementations for in-memory, persistent on disk (Berkeley DB) and remote SPARQL endpoints
  • a SPARQL 1.1 implementation - supporting SPARQL 1.1 Queries and Update statements
  • SPARQL function extension mechanisms

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.

Please see the list for all packages/repositories here:

Versions & Releases

  • 6.0.1-alpha current master branch
  • 6.x.y current release and support Python 3.7+ only. Many improvements over 5.0.0
  • 5.x.y supports Python 2.7 and 3.4+ and is mostly backwards compatible with 4.2.2.

See https://rdflib.dev for the release schedule.

Documentation

See https://rdflib.readthedocs.io for our documentation built from the code. Note that there are latest, stable 5.0.0 and 4.2.2 documentation versions, matching releases.

Installation

The stable release of 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 https://pypi.python.org/pypi/rdflib

The current version of RDFLib is 6.0.0, see the CHANGELOG.md 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+https://github.com/rdflib/rdflib@master

or

$ pip install -e git+https://github.com/rdflib/rdflib@master#egg=rdflib

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

$ python setup.py 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:

from rdflib import Graph
g = Graph()
g.parse('http://dbpedia.org/resource/Semantic_Web')

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:

from rdflib import Graph, URIRef, Literal
from rdflib.namespace import RDFS

g = Graph()
semweb = URIRef('http://dbpedia.org/resource/Semantic_Web')
type = g.value(semweb, RDFS.label)

Where RDFS is the RDFS Namespace, g.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:

g.add((
    URIRef("http://example.com/person/nick"),
    FOAF.givenName,
    Literal("Nick", datatype=XSD.string)
))

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.giveName 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:

print(g.serialize(format="turtle"))

With these results:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

<http://example.com/person/nick> foaf:givenName "Nick"^^xsd:string .

New Namespaces can also be defined:

dbpedia = Namespace('http://dbpedia.org/ontology/')

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

See also ./examples

Features

The library contains parsers and serializers for RDF/XML, N3, NTriples, N-Quads, Turtle, TriX, JSON-LD, RDFa and Microdata.

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 https://github.com/RDFLib/.

Running tests

Running the tests on the host

Run the test suite with pytest.

pytest

Running test coverage on the host with coverage report

Run the test suite and generate a HTML coverage report with pytest and pytest-cov.

pytest --cov

Running the tests in a Docker container

Run the test suite inside a Docker container for cross-platform support. This resolves issues such as installing BerkeleyDB on Windows and avoids the host and port issues on macOS.

make tests

Tip: If the underlying Dockerfile for the test runner changes, use make build.

Running the tests in a Docker container with coverage report

Run the test suite inside a Docker container with HTML coverage report.

make coverage

Viewing test coverage

Once tests have produced HTML output of the coverage report, view it by running:

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 to get started. Please consider lodging Pull Requests here:

You can also raise issues here:

Support & Contacts

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

If you want to contact the rdflib maintainers, please do so via:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].