{"id":1693,"library":"rdflib","title":"RDFLib","description":"RDFLib is a Python library for working with RDF (Resource Description Framework), a simple yet powerful language for representing information. It provides a Graph data structure, parsers and serializers for various RDF formats (e.g., Turtle, N-Triples, RDF/XML, JSON-LD), and SPARQL query capabilities. RDFLib is actively maintained with frequent minor releases and major versions typically every 1-2 years.","status":"active","version":"7.6.0","language":"en","source_language":"en","source_url":"https://github.com/RDFLib/rdflib","tags":["rdf","semantic-web","graph-database","sparql","knowledge-graph"],"install":[{"cmd":"pip install rdflib","lang":"bash","label":"Basic installation"},{"cmd":"pip install \"rdflib[json-ld,sparql,rdf4j,graphdb]\"","lang":"bash","label":"Installation with common extras"}],"dependencies":[{"reason":"Required for parsing and serializing XSD date/time literals.","package":"isodate","optional":true},{"reason":"Required for faster RDF/XML parsing and validation, and for some XML-based serialization formats.","package":"lxml","optional":true},{"reason":"Required for parsing RDF embedded in HTML using RDFa or Microdata.","package":"html5rdf","optional":true},{"reason":"Used for SPARQL parsing. Often installed as a transitive dependency.","package":"pyparsing","optional":true},{"reason":"Provides JSON-LD parsing and serialization support.","package":"rdflib-jsonld","optional":true},{"reason":"Enables connection to remote SPARQL endpoints as an RDFLib Store.","package":"rdflib-sparqlstore","optional":true},{"reason":"Enables integration with RDF4J servers and stores (introduced in 7.5.0).","package":"rdf4j-client","optional":true},{"reason":"Enables integration with GraphDB instances (introduced in 7.6.0).","package":"graphdb-client","optional":true}],"imports":[{"symbol":"Graph","correct":"from rdflib import Graph"},{"symbol":"Namespace","correct":"from rdflib import Namespace"},{"symbol":"URIRef","correct":"from rdflib import URIRef"},{"symbol":"BNode","correct":"from rdflib import BNode"},{"symbol":"Literal","correct":"from rdflib import Literal"},{"note":"Commonly used namespaces like FOAF, RDFS, RDF, XSD are found in `rdflib.namespace`.","wrong":"from rdflib import FOAF","symbol":"FOAF","correct":"from rdflib.namespace import FOAF"}],"quickstart":{"code":"from rdflib import Graph, Literal, Namespace, URIRef\nfrom rdflib.namespace import FOAF, XSD\n\n# Create a Graph\ng = Graph()\n\n# Define a custom namespace\nEX = Namespace(\"http://example.org/people/\")\n\n# Create URIs for resources\njohn = EX.johnDoe\njane = EX.janeDoe\n\n# Add triples to the graph\ng.add((john, FOAF.name, Literal(\"John Doe\")))\ng.add((john, FOAF.mbox, URIRef(\"mailto:john.doe@example.org\")))\ng.add((john, FOAF.age, Literal(30, datatype=XSD.integer)))\n\ng.add((jane, FOAF.name, Literal(\"Jane Doe\")))\ng.add((jane, FOAF.age, Literal(25, datatype=XSD.integer)))\n\n# Serialize the graph to Turtle format and print it\nprint(g.serialize(format=\"turtle\"))\n\n# You can also parse from a file or string\n# g.parse(\"path/to/my_data.ttl\", format=\"turtle\")","lang":"python","description":"This quickstart demonstrates how to create an RDF Graph, define namespaces, add triples using URIRef, BNode, and Literal, and serialize the graph to the Turtle format. It's a fundamental example of how to represent and manage RDF data programmatically."},"warnings":[{"fix":"Review calls to `Graph.parse` or `Dataset.parse` that use `publicID`. If your data contains relative URIs, ensure the `publicID` is correctly set to define the base URI, or use `base` parameter explicitly if appropriate.","message":"The handling of the `publicID` parameter in `Graph.parse` and `Dataset.parse` methods changed in version 7.0.0. It now explicitly sets the base URI for parsing, potentially altering how relative URIs are resolved in some cases.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Consult the RDFLib documentation for `Dataset` to identify deprecated methods and their recommended alternatives. Update your code to use the newer, more consistent API to avoid breakage in future major versions.","message":"Several methods and attributes of the `Dataset` class have been deprecated in version 7.3.0 and are scheduled for removal in the next major release (likely 8.0.0). This aims to improve consistency and align `Dataset` more closely with RDF specifications.","severity":"deprecated","affected_versions":">=7.3.0"},{"fix":"Install RDFLib with the necessary extras, e.g., `pip install \"rdflib[json-ld,sparql,isodate,lxml,rdf4j,graphdb]\"`, or install individual missing packages as needed (e.g., `pip install isodate`). Refer to the documentation for specific feature requirements.","message":"Many parsers, serializers, and advanced features (e.g., SPARQL, JSON-LD, HTML5 parsing, specific datatype handling) rely on optional dependencies that are not installed by default. Without them, you might encounter `ImportError` or incomplete functionality.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using RDFLib >= 7.1.3 if you target Python 3.8. It's generally recommended to use the latest patch release for your major version.","message":"Python 3.8 support was temporarily removed in version 7.1.2 and then re-added in 7.1.3 due to a typing-related regression. Users on specific patch versions of 7.1.x might experience unexpected behavior or installation issues on Python 3.8.","severity":"gotcha","affected_versions":"7.1.2"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}