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.
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.
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.
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))
Metadata
Release files for pyRDF 2.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyrdf-2.3.2.tar.gz | 20.2 kB | Without provenance | Details for pyrdf-2.3.2.tar.gz |
Release files / pyrdf-2.3.2.tar.gz
| Download URL | pyrdf-2.3.2.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0c5942c3bada3313301b5d63aabba64482525adc266b2ed831bc0dcecbc72a16
|
|
BLAKE2b-256 checksum How to use checksums |
14578b73e2b8666508172d25298cab7e1a7beaf2b5983bad0717ae39989c46af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for pyRDF 2.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.