Skip to main content

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))

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrdf-2.3.2.tar.gz (20.2 kB view details)

Uploaded Source

File details

Details for the file pyrdf-2.3.2.tar.gz.

File metadata

  • Download URL: pyrdf-2.3.2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pyrdf-2.3.2.tar.gz
Algorithm Hash digest
SHA256 0c5942c3bada3313301b5d63aabba64482525adc266b2ed831bc0dcecbc72a16
MD5 158ae4edd8d0b6b20120d1bee273ecf8
BLAKE2b-256 14578b73e2b8666508172d25298cab7e1a7beaf2b5983bad0717ae39989c46af

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.3.2 This release

1 file

2.3.1

1 file

2.3.0

1 file

2.2.1

1 file

2.2.0

1 file

2.1.1

1 file

2.1.0

1 file

2.0.1

1 file

2.0.0

1 file

1.0.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page