{"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":"python","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,"search_vec":"'-2':62 '1':61 'activ':50 'capabl':47 'data':26 'databas':70 'descript':12 'e.g':35 'everi':60 'format':34 'framework':13 'frequent':53 'graph':25,69,74 'graph-databas':68 'inform':21 'json':42 'json-ld':41 'knowledg':73 'knowledge-graph':72 'languag':18 'ld':43 'librari':6 'maintain':51 'major':57 'minor':54 'n':38 'n-tripl':37 'parser':28 'power':17 'provid':23 'python':5 'queri':46 'rdf':10,33,64 'rdf/xml':40 'rdflib':1,2,48 'releas':55 'repres':20 'resourc':11 'semant':66 'semantic-web':65 'serial':30 'simpl':15 'sparql':45,71 'structur':27 'tripl':39 'turtl':36 'typic':59 'various':32 'version':58 'web':67 'work':8 'year':63 'yet':16","created_at":"2026-04-09T03:59:04.767075+00:00","updated_at":"2026-04-16T20:47:40.651079+00:00","problems":[{"fix":"Ensure your RDF input string or file strictly adheres to the specified RDF format (e.g., Turtle, N-Triples, RDF/XML, JSON-LD) and is well-formed. Double-check the `format` argument passed to `g.parse()`.","cause":"The input data (string or file) provided to the `Graph.parse()` method is not valid RDF in the specified format, or the format was incorrectly identified.","error":"rdflib.exceptions.ParserError: Error parsing RDF"},{"fix":"Review and correct the syntax of your SPARQL query to ensure it conforms to the SPARQL 1.1 grammar. Common mistakes include missing keywords (like `SELECT` or `WHERE`), incorrect curly brace placement, or malformed prefixes.","cause":"The SPARQL query string provided to `Graph.query()` has a syntax error and cannot be parsed by RDFLib's SPARQL engine.","error":"rdflib.plugins.sparql.parser.ParseError: Expected {SelectQuery, ConstructQuery, DescribeQuery, AskQuery}"},{"fix":"Convert the `URIRef` or `Literal` object to a string using `str()` before concatenating it with other strings, or use f-strings which handle conversion automatically.","cause":"You are attempting to concatenate an `rdflib.URIRef` (or `Literal`, `BNode`) object directly with a Python string without explicitly converting the RDFLib object to a string first.","error":"TypeError: can only concatenate str (not URIRef) to str"},{"fix":"Install the `pyld` package using pip: `pip install pyld`. If you also need other optional parsers/serializers, check their respective documentation for required dependencies.","cause":"RDFLib uses the external `pyld` library for JSON-LD parsing and serialization, but this dependency is not installed in your Python environment.","error":"ImportError: 'pyld' must be installed to use JSON-LD serialiser/parser"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"7.6.0","cli_name":"rdfpipe","cli_version":"rdfpipe (using rdflib 7.6.0)","type":"library","homepage":"https://rdflib.dev","github":"https://github.com/RDFLib/rdflib","docs":"https://rdflib.readthedocs.org/","changelog":null,"pypi":"https://pypi.org/project/rdflib/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":null}}