#rdf #graph #serialization #triple #statement #representation #reading


This crate provides traits for reading and writing Statements and Graphs as well as implementations of these for common representations

11 releases

0.2.1 Jun 14, 2021
0.2.0 Jun 8, 2021
0.1.9 May 27, 2021
0.1.6 Apr 24, 2021
0.1.0 Jul 28, 2020

#11 in #triple

38 downloads per month
Used in 3 crates (2 directly)

MIT license


Rust 8K SLoC // 0.2% comments Pest 1.5K SLoC // 0.2% comments Shell 5 SLoC


io This crate provides traits for reading and writing Statements and Graphs as well as implementations of these for common representations.

crates.io docs.rs

The following are some well-known formats (see Wikipedia for a description of different serializations), support is indicated in the final column with an R for read support and W for write support. One additional module, dot allows for the creation of GraphViz dot files for a visualization of a graph's structure.

Module Name MIME Type R/W
nt RDF 1.1 N-Triples; A line-based syntax for an RDF graph application/n-triples R+W
nq RDF 1.1 N-Quads; A line-based syntax for RDF datasets application/n-quads W
turtle RDF 1.1 Turtle; Terse RDF Triple Language text/turtle W
trig RDF 1.1 TriG; RDF Dataset Language application/trig
xml RDF 1.1 XML Syntax application/rdf+xml W
json RDF 1.1 JSON Alternate Serialization application/rdf+json R+W
n3 Notation3 (N3): A readable RDF syntax text/rdf+n3 W
TBD Binary RDF Representation for Publication and Exchange (HDT) N/A
TBD RDF Binary using Apache Thrift application/x-binary-rdf
TBD JSON-LD 1.1; A JSON-based Serialization for Linked Data application/ld+json
TBD RDFa Core 1.1 - Third Edition text/html

Each module will also provide public constants NAME, FILE_EXTENSION, and MIME_TYPE.


An example, reading an existing NTriple file.

use rdftk_io::nt::reader::NTriplesReader;
use rdftk_io::GraphReader;
use rdftk_memgraph::simple::graph_factory;
use std::fs::File;
use std::path::PathBuf;

let file_path = PathBuf::from("tests/w3c/nt/literal.nt");
let mut file = File::open(file_path).unwrap();
let reader = NTriplesReader::default();
let graph = reader.read(&mut file, graph_factory()).unwrap();


Version 0.2.1

  • Added JSON reader.

Version 0.2.0

  • Updated rdftk_core dependency to 0.3.0, this is a significant API change.
  • All read operations require a graph factory now.

Version 0.1.9

  • Added unicode escape handling into the IRI parsing.
  • All W3C test cases for NTriples now passing.
  • Removed local error module, using core error types now.

Version 0.1.8

  • Using new style interfaces, a consistent use of traits and trait reference types.
  • Have a working NTriple parser.

Version 0.1.7

  • Using rdftk_core 0.2, this has changes in the signature of both Graph and DataSet traits.
    • This results in changes to both GraphWriter and DataSetWriter traits.
  • Applied a lot more warnings in lib.rs
  • Fixed resulting Clippy suggestions.

Version 0.1.6

  • Made all modules have separate reader/writer sub-modules.
  • Put all modules behind features.
  • Added JSON writer.
  • Re-write NQuad writer to write datasets.
  • Re-wrote NTripe writer to use NQuad writer.
  • Fixed formatting in Turtle writer.
  • Added XML writer.

Version 0.1.5

  • Internal change to use StatementRef.

Version 0.1.4

  • API changes in core crate:
    • Altered PrefixMappings::compress and PrefixMappings::expand to take references.

Version 0.1.2

  • Made all IRI into IRIRef.

Version 0.1.1

  • Made all local dependencies only major/minor valued.

Version 0.1.0

  • First release.
  • Provides write support only for N-Triples, N-Quads, and GraphViz.


  1. The core; N-Triples, N-Quads, N3, and Turtle need read and write support.
  2. The extended core; RDF/XML, JSON-LD, and RDFa need read and write support.
  3. The rest; RDF/JSON, TriG, HDT, and BinaryRDF will be implemended as needed.



~194K SLoC