rdflib

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

https://github.com/rdflib/rdflib

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    18 of 201 committers (9.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.7%) to scientific vocabulary

Keywords

graph json-ld linked-data n3 namespace nquads ntriples parser pypi python python-library rdf rdf-xml rdflib semantic-web serializer sparql turtle turtle-rdf uri

Keywords from Contributors

owl shacl closember neuroimaging constraints bioinformatics data-mining json-schema distributed data-profilers
Last synced: 4 months ago · JSON representation ·

Repository

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

Basic Info
Statistics
  • Stars: 2,323
  • Watchers: 80
  • Forks: 577
  • Open Issues: 345
  • Releases: 17
Topics
graph json-ld linked-data n3 namespace nquads ntriples parser pypi python python-library rdf rdf-xml rdflib semantic-web serializer sparql turtle turtle-rdf uri
Created almost 14 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Codeowners Security

README.md

RDFLib

Build Status Documentation Status Coveralls branch

GitHub stars Downloads PyPI PyPI DOI

Contribute with Gitpod Gitter Matrix

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.
  • pyrdfa3 - RDFa 1.1 distiller/parser library: can extract RDFa 1.1/1.0 from (X)HTML, SVG, or XML in general.
  • pymicrodata - A module to extract RDF from an HTML5 page annotated with microdata.
  • pySHACL - A pure Python module which allows for the validation of RDF graphs against SHACL graphs.
  • OWL-RL - A simple implementation of the OWL2 RL Profile which expands the graph with all possible triples that OWL RL defines.

Please see the list for all packages/repositories here:

Help with maintenance of all of the RDFLib family of packages is always welcome and appreciated.

Versions & Releases

See https://github.com/RDFLib/rdflib/releases/ for the release details.

Documentation

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:

$ pip install rdflib[berkeleydb,networkx,html,lxml,orjson]

Alternatively manually download the package from the Python Package Index (PyPI) at https://pypi.python.org/pypi/rdflib

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

Installation of the current main 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@main

or

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

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

$ poetry install  # installs into a poetry-managed venv

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:

```python 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:

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

You can use them like this:

```python 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) `` WhereRDFSis the RDFS namespace,XSDthe XML Schema Datatypes namespace andg.value` returns an object of the triple-pattern given (or an arbitrary one if multiple exist).

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

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

python g.bind("foaf", FOAF) g.bind("xsd", XSD)

This will allow the n-triples triple above to be serialised like this:

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

With these results: ```turtle 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:

```python 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. shell poetry install poetry run 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. shell poetry run pytest --cov

Viewing test coverage

Once tests have produced HTML output of the coverage report, view it by running: shell 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:

To get a development environment consider using Gitpod or Google Cloud Shell.

Open in Gitpod Open in Cloud Shell

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:

Owner

  • Name: RDFlib
  • Login: RDFLib
  • Kind: organization

RDFlib, the GitHub organization, is a volunteer-maintained collection of Python tools for working with RDF data.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Krech"
  given-names: "Daniel"
- family-names: "Grimnes"
  given-names: "Gunnar Aastrand"
- family-names: "Higgins"
  given-names: "Graham"
- family-names: "Car"
  given-names: "Nicholas"
  orcid: "https://orcid.org/0000-0002-8742-7730"
- family-names: "Hees"
  given-names: "Jörn"
  orcid: "https://orcid.org/0000-0002-0084-8998"
- family-names: "Aucamp"
  given-names: "Iwan"
  orcid: "https://orcid.org/0000-0002-7325-3231"
- family-names: "Lindström"
  given-names: "Niklas"
- family-names: "Arndt"
  given-names: "Natanael"
  orcid: "https://orcid.org/0000-0002-8130-8677"
- family-names: "Sommer"
  given-names: "Ashley"
  orcid: "https://orcid.org/0000-0003-0590-0131"
- family-names: "Chuc"
  given-names: "Edmond"
  orcid: "https://orcid.org/0000-0002-6047-9864"
- family-names: "Herman"
  given-names: "Ivan"
  orcid: "https://orcid.org/0000-0003-0782-2704"
- family-names: "Nelson"
  given-names: "Alex"
- family-names: "McCusker"
  given-names: "Jamie"
  orcid: "https://orcid.org/0000-0003-1085-6059"
- family-names: "Gillespie"
  given-names: "Tom"
- family-names: "Kluyver"
  given-names: "Thomas"
  orcid: "https://orcid.org/0000-0003-4020-6364"
- family-names: "Ludwig"
  given-names: "Florian"
- family-names: "Champin"
  given-names: "Pierre-Antoine"
  orcid: "https://orcid.org/0000-0001-7046-4474"
- family-names: "Watts"
  given-names: "Mark"
- family-names: "Holzer"
  given-names: "Urs"
- family-names: "Summers"
  given-names: "Ed"
- family-names: "Morriss"
  given-names: "Whit"
- family-names: "Winston"
  given-names: "Donny"
- family-names: "Perttula"
  given-names: "Drew"
- family-names: "Kovacevic"
  given-names: "Filip"
  orcid: "https://orcid.org/0000-0002-2854-0434"
- family-names: "Chateauneu"
  given-names: "Remi"
  orcid: "https://orcid.org/0000-0002-7505-8149"
- family-names: "Solbrig"
  given-names: "Harold"
  orcid: "https://orcid.org/0000-0002-5928-3071"
- family-names: "Cogrel"
  given-names: "Benjamin"
  orcid: "https://orcid.org/0000-0002-7566-4077"
- family-names: "Stuart"
  given-names: "Veyndan"
title: "RDFLib"
version: 7.1.2
date-released: 2025-01-10
url: "https://github.com/RDFLib/rdflib"
doi: 10.5281/zenodo.6845245

GitHub Events

Total
  • Create event: 167
  • Commit comment event: 2
  • Issues event: 67
  • Release event: 5
  • Watch event: 137
  • Delete event: 143
  • Issue comment event: 375
  • Push event: 293
  • Pull request event: 335
  • Pull request review event: 57
  • Pull request review comment event: 32
  • Fork event: 34
Last Year
  • Create event: 167
  • Commit comment event: 2
  • Issues event: 67
  • Release event: 5
  • Watch event: 137
  • Delete event: 143
  • Issue comment event: 375
  • Push event: 293
  • Pull request event: 335
  • Pull request review event: 57
  • Pull request review comment event: 32
  • Fork event: 34

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 4,357
  • Total Committers: 201
  • Avg Commits per committer: 21.677
  • Development Distribution Score (DDS): 0.807
Past Year
  • Commits: 164
  • Committers: 25
  • Avg Commits per committer: 6.56
  • Development Distribution Score (DDS): 0.512
Top Committers
Name Email Commits
Daniel Krech e****n@e****m 842
Gunnar Aastrand Grimnes g****l@g****m 493
Chimezie Ogbuji d****l@l****t 364
Iwan Aucamp a****a@g****m 354
Graham Higgins g****h@b****m 337
dependabot[bot] 4****] 286
Nicholas Car n****r@s****m 265
Jörn Hees d****v@j****e 234
Niklas Lindström l****m@g****m 90
Ashley Sommer a****r@g****m 76
Natanael Arndt a****n@g****m 60
Edmond Chuc e****c@g****m 59
Alex Nelson a****n@n****v 43
Michel Pelletier m****l@g****m 41
Ivan Herman i****n@i****t 41
Jamie McCusker m****r@g****m 33
Tom Gillespie t****s@g****m 30
Thomas Kluyver t****l@g****m 25
pre-commit-ci[bot] 6****] 23
Florian Ludwig f****g@g****m 23
Mark Watts w****5@g****m 20
Pierre-Antoine Champin p****n@l****r 20
Ed Summers e****s@p****m 17
Whit Morriss d****s@g****m 17
Drew Perttula d****p@b****m 16
Urs Holzer u****s@a****m 16
dependabot-preview[bot] 2****] 15
Filip Kovacevic g****7@g****m 14
Donny Winston d****n@a****u 14
Harold Solbrig s****g@e****t 13
and 171 more...

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 252
  • Total pull requests: 976
  • Average time to close issues: 9 months
  • Average time to close pull requests: 16 days
  • Total issue authors: 139
  • Total pull request authors: 74
  • Average comments per issue: 2.5
  • Average comments per pull request: 1.45
  • Merged pull requests: 590
  • Bot issues: 5
  • Bot pull requests: 566
Past Year
  • Issues: 63
  • Pull requests: 356
  • Average time to close issues: 8 days
  • Average time to close pull requests: 8 days
  • Issue authors: 43
  • Pull request authors: 32
  • Average comments per issue: 0.22
  • Average comments per pull request: 0.96
  • Merged pull requests: 171
  • Bot issues: 4
  • Bot pull requests: 209
Top Authors
Issue Authors
  • aucampia (37)
  • ashleysommer (9)
  • edmondchuc (8)
  • ajnelson-nist (8)
  • lu-pl (6)
  • WhiteGobo (6)
  • dependabot[bot] (5)
  • floresbakker (5)
  • multimeric (5)
  • sdasda7777 (5)
  • gjhiggins (3)
  • william-vw (3)
  • jclerman (3)
  • jaw111 (3)
  • kloczek (3)
Pull Request Authors
  • dependabot[bot] (544)
  • aucampia (95)
  • ashleysommer (53)
  • nicholascar (48)
  • edmondchuc (30)
  • pre-commit-ci[bot] (22)
  • WhiteGobo (14)
  • wallberg (12)
  • white-gecko (10)
  • ajnelson-nist (7)
  • avillar (7)
  • ageorgou (7)
  • mgberg (6)
  • raboof (6)
  • recalcitrantsupplant (5)
Top Labels
Issue Labels
bug (51) breaking change (29) enhancement (26) core (22) good first issue (19) SPARQL (16) concept: RDF dataset (16) serialization (13) id-as-cntxt (10) parsing (9) confirmation needed (8) documentation (8) store (6) concept: RDF Literal (6) interface bug (5) marked for closing (5) format: JSON-LD (5) cleanup (5) dependencies (5) duplicate (4) concept: skolemization (4) help wanted (4) accepting PR (4) concept: namespace (4) feedback wanted (4) critical (4) low priority (3) format: N-Quads (3) concept: datatype (3) reconfirm (3)
Pull Request Labels
dependencies (544) python (421) docker (106) review wanted (61) ready to merge (40) github_actions (17) testing (9) fix (8) enhancement (8) RDFLib8 (6) documentation (5) awaiting feedback (5) refactor (4) good first issue (4) needs more work (4) cleanup (3) store (3) backwards incompatible (3) core (3) 7.0 (3) SPARQL (2) bug (2) help wanted (2) needs discussion (2) feedback wanted (2) 7.1 (2) breaking change (2) meta (2) type hints (2) marked for closing (2)

Packages

  • Total packages: 8
  • Total downloads:
    • pypi 5,830,856 last-month
  • Total docker downloads: 77,978,175
  • Total dependent packages: 501
    (may contain duplicates)
  • Total dependent repositories: 4,378
    (may contain duplicates)
  • Total versions: 59
  • Total maintainers: 5
pypi.org: rdflib

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

  • Versions: 42
  • Dependent Packages: 471
  • Dependent Repositories: 4,363
  • Downloads: 5,830,856 Last month
  • Docker Downloads: 77,978,175
Rankings
Dependent packages count: 0.1%
Dependent repos count: 0.2%
Downloads: 0.2%
Docker downloads count: 0.4%
Average: 0.8%
Stargazers count: 1.6%
Forks count: 2.3%
Last synced: 9 months ago
spack.io: py-rdflib

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

  • Versions: 5
  • Dependent Packages: 10
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Average: 3.7%
Forks count: 4.0%
Stargazers count: 5.4%
Dependent packages count: 5.5%
Maintainers (1)
Last synced: 4 months ago
conda-forge.org: rdflib
  • Versions: 7
  • Dependent Packages: 20
  • Dependent Repositories: 15
Rankings
Dependent packages count: 3.2%
Average: 7.2%
Forks count: 7.3%
Dependent repos count: 9.2%
Stargazers count: 9.2%
Last synced: 4 months ago
anaconda.org: rdflib-with-all

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

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 42.3%
Average: 44.4%
Dependent repos count: 46.5%
Last synced: 4 months ago
anaconda.org: rdflib-with-orjson

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

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 42.3%
Average: 44.4%
Dependent repos count: 46.5%
Last synced: 4 months ago
anaconda.org: rdflib

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

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 42.3%
Average: 44.4%
Dependent repos count: 46.5%
Last synced: 4 months ago
anaconda.org: rdflib-with-lxml

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

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 42.3%
Average: 44.4%
Dependent repos count: 46.5%
Last synced: 4 months ago
anaconda.org: rdflib-with-networkx

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

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 42.3%
Average: 44.4%
Dependent repos count: 46.5%
Last synced: 4 months ago

Dependencies

docs/sphinx-requirements.txt pypi
  • myst-parser *
  • sphinx <6
  • sphinx-autodoc-typehints *
  • sphinxcontrib-apidoc *
  • sphinxcontrib-kroki *
requirements.dev-extra.txt pypi
  • berkeleydb *
  • networkx *
requirements.dev.txt pypi
  • black ==22.6.0
  • coverage *
  • doctest-ignore-unicode ==0.1.2
  • html5lib *
  • isort *
  • mypy *
  • pytest *
  • pytest-cov *
  • types-setuptools *
requirements.flake8.txt pypi
  • flake8 *
  • flakeheaven *
  • pep8-naming *
requirements.txt pypi
  • html5lib *
  • isodate *
  • pyparsing *
.github/workflows/docker-images.yaml actions
  • actions/checkout v3 composite
  • arduino/setup-task v1 composite
  • docker/login-action v2 composite
.github/workflows/test-report.yml actions
  • dorny/test-reporter v1 composite
.github/workflows/validate.yaml actions
  • actions/cache v3 composite
  • actions/checkout v3 composite
  • actions/setup-java v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • arduino/setup-task v1 composite
  • coverallsapp/github-action master composite
docker/latest/Dockerfile docker
  • docker.io/library/python 3.11.1-slim@sha256 build
docker/unstable/Dockerfile docker
  • docker.io/library/python 3.11.1-slim@sha256 build
docker/latest/requirements.in pypi
  • html5lib * test
  • rdflib ==6.2.0 test
docker/latest/requirements.txt pypi
  • html5lib ==1.1 test
  • isodate ==0.6.1 test
  • pyparsing ==3.0.9 test
  • rdflib ==6.2.0 test
  • six ==1.16.0 test
  • webencodings ==0.5.1 test
docker/unstable/requirements.txt pypi
  • html5lib ==1.1
  • isodate ==0.6.1
  • pyparsing ==3.0.9
  • six ==1.16.0
  • webencodings ==0.5.1