Skip to main content

Lightweight RDF Stream Parser

Project description

Lightweight RDF Stream Parser for Python

A lightweight RDF parser which streams triples directly from disk or standard input without loading the entire graph into memory.

Work in progress. Only supports ntriple format as of now.

Usage

Read and write to disk.

from rdf.io import NTriple
from rdf.terms import Literal

with NTriple(path = "./pizzacats.nt", mode = 'r') as g:
    with NTriple(path = "./out.nt", mode = 'w') as h:
        for subject, predicate, object in g.parse():
            if type(object) = Literal and object.language == "en":
                # do stuff
            h.write((subject, predicate, object))

Read / write from standard input / output.

from os import stdin
from rdf.io import NTriple
from rdf.terms import IRIRef

g = NTriple(data=stdin.read(), mode = 'r')
h = NTriple(mode = 'w')

target = IRIRef("https://example.org/Pizzacat")
for triple in g.parse():
    if triple[0] == target:
        # do stuff
        h.write(triple)
        
g.close()
h.close()

Project details


Download files

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

Source Distribution

pyRDF-1.0.0.tar.gz (16.2 kB view details)

Uploaded Source

File details

Details for the file pyRDF-1.0.0.tar.gz.

File metadata

  • Download URL: pyRDF-1.0.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.3 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.4

File hashes

Hashes for pyRDF-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9aeb70b6e590f60814f47eb4b20c60178fe42b29f0331014c724cfefde20f3d5
MD5 7ed67552b57ad6b16799f5143fe0e0f0
BLAKE2b-256 e0d41d73cd277ace16c6d60606408361e75f4112bedcf8dc4d150dcd82783346

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page