# Lightweight RDF Stream Parser for Python
A lightweight RDF and RDF-Star parser which streams triples directly from disk
or standard input without loading the entire graph into memory.
Supports the N-Triples and N-Quads serialization format.
## Usage
Read and write to disk.
```python
from rdf import NTriples
from rdf import Literal
with NTriples(path = "./pizzacats.nt", mode = 'r') as g:
with NTriples(path = "./out.nt", mode = 'w') as h:
for subject, predicate, object in g.parse():
if type(object) is Literal and object.language == "en":
# do stuff
h.write((subject, predicate, object))
```
Read / write from standard input / output.
```python
from os import stdin
from rdf import NQuads
from rdf import IRIRef
g = NQuads(data=stdin.read(), mode = 'r')
h = NQuads(mode = 'w')
target = IRIRef("https://example.org/Pizzacat")
for triple in g.parse():
if triple[0] == target: # subject
# do stuff
h.write(triple)
g.close()
h.close()
```
Adding new triples.
```python
from rdf import IRIRef, Literal, Statement
from rdf import RDF, XSD
EX = IRIRef("https://example.org/") # define prefix
g = set()
subject = EX + "Pizzacat"
g.add(Statement(subject, RDF+"type", EX+"Cat"))
literal = Literal("Samurai Pizza Cats!!!", datatype=XSD+"string")
g.add(Statement(subject, EX+"tag_phrase", literal))
```
Raw data
{
"_id": null,
"home_page": "https://wxwilcke.gitlab.io/pyRDF",
"name": "pyRDF",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "rdf, ntriples, nquads, rdf-star, parser, streamer",
"author": "Xander Wilcke",
"author_email": "Xander Wilcke <w.x.wilcke@vu.nl>",
"download_url": "https://files.pythonhosted.org/packages/ad/0c/7c8b8e9cc1b78c3051220f181dfe15e0c52928a93aba9dcc57e4830df80a/pyrdf-2.3.1.tar.gz",
"platform": null,
"description": "# Lightweight RDF Stream Parser for Python\n\nA lightweight RDF and RDF-Star parser which streams triples directly from disk\nor standard input without loading the entire graph into memory.\n\nSupports the N-Triples and N-Quads serialization format.\n\n## Usage\n\nRead and write to disk.\n\n```python\nfrom rdf import NTriples\nfrom rdf import Literal\n\nwith NTriples(path = \"./pizzacats.nt\", mode = 'r') as g:\n with NTriples(path = \"./out.nt\", mode = 'w') as h:\n for subject, predicate, object in g.parse():\n if type(object) is Literal and object.language == \"en\":\n # do stuff\n h.write((subject, predicate, object))\n```\n\nRead / write from standard input / output.\n\n```python\nfrom os import stdin\nfrom rdf import NQuads\nfrom rdf import IRIRef\n\ng = NQuads(data=stdin.read(), mode = 'r')\nh = NQuads(mode = 'w')\n\ntarget = IRIRef(\"https://example.org/Pizzacat\")\nfor triple in g.parse():\n if triple[0] == target: # subject\n # do stuff\n h.write(triple)\n \ng.close()\nh.close()\n```\n\nAdding new triples.\n\n```python\nfrom rdf import IRIRef, Literal, Statement\nfrom rdf import RDF, XSD\n\nEX = IRIRef(\"https://example.org/\") # define prefix\ng = set()\n\nsubject = EX + \"Pizzacat\"\ng.add(Statement(subject, RDF+\"type\", EX+\"Cat\"))\n\nliteral = Literal(\"Samurai Pizza Cats!!!\", datatype=XSD+\"string\")\ng.add(Statement(subject, EX+\"tag_phrase\", literal))\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Lightweight RDF Stream Parser",
"version": "2.3.1",
"project_urls": {
"Bug Tracker": "https://gitlab.com/wxwilcke/pyRDF/-/issues",
"Download": "https://gitlab.com/wxwilcke/pyRDF/-/archive/2.3.1/pyRDF-2.3.1.tar.gz",
"Homepage": "https://wxwilcke.gitlab.io/pyRDF"
},
"split_keywords": [
"rdf",
" ntriples",
" nquads",
" rdf-star",
" parser",
" streamer"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ad0c7c8b8e9cc1b78c3051220f181dfe15e0c52928a93aba9dcc57e4830df80a",
"md5": "9e7ce1e01499e21bac9e7b5f12d78cfa",
"sha256": "2c750e41d811ae80c3783d29be85fbf750e9b3a2a07293fa66bb2004ffcc8501"
},
"downloads": -1,
"filename": "pyrdf-2.3.1.tar.gz",
"has_sig": false,
"md5_digest": "9e7ce1e01499e21bac9e7b5f12d78cfa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 20193,
"upload_time": "2025-08-08T16:14:09",
"upload_time_iso_8601": "2025-08-08T16:14:09.820596Z",
"url": "https://files.pythonhosted.org/packages/ad/0c/7c8b8e9cc1b78c3051220f181dfe15e0c52928a93aba9dcc57e4830df80a/pyrdf-2.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-08 16:14:09",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "wxwilcke",
"gitlab_project": "pyRDF",
"lcname": "pyrdf"
}