https://github.com/cthoyt/rdflib
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
Science Score: 23.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: zenodo.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.2%) to scientific vocabulary
Repository
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
Basic Info
- Host: GitHub
- Owner: cthoyt
- License: bsd-3-clause
- Default Branch: main
- Homepage: https://rdflib.readthedocs.org
- Size: 19.9 MB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
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
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
6.3.0a0currentmainbranch6.x.ycurrent release and support Python 3.7+ only. Many improvements over 5.0.0- see Releases
5.x.ysupports Python 2.7 and 3.4+ and is mostly backwards compatible with 4.2.2.
See https://rdflib.dev for the release overview.
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.2.0, 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.
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:
- the rdflib-dev mailing list: https://groups.google.com/group/rdflib-dev
- the chat, which is available at gitter or via matrix #RDFLib_rdflib:gitter.im
Owner
- Name: Charles Tapley Hoyt
- Login: cthoyt
- Kind: user
- Location: Bonn, Germany
- Company: RWTH Aachen University
- Website: https://cthoyt.com
- Repositories: 489
- Profile: https://github.com/cthoyt
GitHub Events
Total
Last Year
Dependencies
- alabaster 0.7.13 develop
- attrs 22.2.0 develop
- babel 2.11.0 develop
- black 22.12.0 develop
- certifi 2022.12.7 develop
- charset-normalizer 3.0.1 develop
- click 8.1.3 develop
- colorama 0.4.6 develop
- coverage 7.1.0 develop
- docutils 0.17.1 develop
- entrypoints 0.4 develop
- exceptiongroup 1.1.0 develop
- flake8 4.0.1 develop
- flakeheaven 3.2.1 develop
- idna 3.4 develop
- imagesize 1.4.1 develop
- iniconfig 2.0.0 develop
- isort 5.11.5 develop
- jinja2 3.1.2 develop
- lxml-stubs 0.4.0 develop
- markdown-it-py 2.1.0 develop
- markupsafe 2.1.2 develop
- mccabe 0.6.1 develop
- mdit-py-plugins 0.3.3 develop
- mdurl 0.1.2 develop
- mypy 0.991 develop
- mypy-extensions 1.0.0 develop
- myst-parser 0.18.1 develop
- packaging 23.0 develop
- pathspec 0.11.0 develop
- pbr 5.11.1 develop
- pep8-naming 0.13.2 develop
- platformdirs 3.0.0 develop
- pluggy 1.0.0 develop
- pycodestyle 2.8.0 develop
- pyflakes 2.4.0 develop
- pygments 2.14.0 develop
- pytest 7.2.1 develop
- pytest-cov 4.0.0 develop
- pytz 2022.7.1 develop
- pyyaml 6.0 develop
- requests 2.28.2 develop
- setuptools 65.7.0 develop
- snowballstemmer 2.2.0 develop
- sphinx 4.3.2 develop
- sphinx-autodoc-typehints 1.17.1 develop
- sphinxcontrib-apidoc 0.3.0 develop
- sphinxcontrib-applehelp 1.0.2 develop
- sphinxcontrib-devhelp 1.0.2 develop
- sphinxcontrib-htmlhelp 2.0.0 develop
- sphinxcontrib-jsmath 1.0.1 develop
- sphinxcontrib-kroki 1.3.0 develop
- sphinxcontrib-qthelp 1.0.3 develop
- sphinxcontrib-serializinghtml 1.1.5 develop
- toml 0.10.2 develop
- tomli 2.0.1 develop
- typed-ast 1.5.4 develop
- types-docutils 0.19.1.3 develop
- types-setuptools 65.7.0.4 develop
- urllib3 1.26.14 develop
- berkeleydb 18.1.5
- html5lib 1.1
- importlib-metadata 4.2.0
- isodate 0.6.1
- lxml 4.9.2
- networkx 2.6.3
- pyparsing 3.0.9
- six 1.16.0
- typing-extensions 4.4.0
- webencodings 0.5.1
- zipp 3.13.0
- abatilo/actions-poetry v2.2.0 composite
- actions/checkout v3 composite
- arduino/setup-task v1 composite
- docker/login-action v2 composite
- dorny/test-reporter v1 composite
- abatilo/actions-poetry v2.2.0 composite
- 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.io/library/python 3.11.2-slim@sha256 build
- docker.io/library/python 3.11.2-slim@sha256 build
- poetry ==1.3.2 development
- Sphinx ==5.3.0 development
- html5lib * test
- rdflib ==6.2.0 test
- 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
- berkeleydb ^18.1.0
- html5lib ^1.0
- importlib-metadata ^4.0.0
- isodate ^0.6.0
- lxml ^4.3.0
- networkx ^2.0.0
- pyparsing >=2.1.0,<4
- python ^3.7