Skip to content
tggoPublic

About

Go RDF library with full SPARQL 1.1 query/update engine and SHACL validator. 100% W3C conformance (1221/1221 tests). Port of Python RDFLib.

Topics

Resources

Contributing

Stars

38 stars

Watchers

1 watching

Forks

Latest commit

 

History

386 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goRDFlib

CI Go Reference Go Report Card Coverage W3C Tests W3C SPARQL Query W3C SPARQL 1.0 W3C SPARQL Update W3C SPARQL 1.2 W3C Turtle W3C Turtle 1.2 W3C N-Triples W3C N-Triples 1.2 W3C N-Quads W3C N-Quads 1.2 W3C RDF/XML W3C RDF/XML 1.2 W3C TriG W3C TriG 1.2 W3C SHACL W3C JSON-LD toRdf SPARQL Protocol Badger Store SQLite Store MongoDB Store

A Go port of the Python RDFLib library for working with RDF (Resource Description Framework) data.

Note: This project is in active development. The core API is stabilizing but may still change. All 4093 W3C conformance tests that run pass (make test-w3c; suites pinned as git submodules at rdf-tests 202a74e and data-shapes 40231dfb). Skipped: 56 JSON-LD toRdf tests (JSON-LD 1.0 only, or limitations of json-gold). Fuzz-tested for robustness.

About

goRDFlib is a Go implementation of the core RDFLib functionality, ported from the Python RDFLib library (BSD 3-Clause License). The architecture, algorithms, and test cases are derived from the Python original, adapted to idiomatic Go patterns.

Features

RDF Data Model

  • URIRef -- IRI references with RFC 3987 validation, base URI resolution, fragment extraction
  • BNode -- Blank nodes with auto-generated UUIDs or explicit IDs
  • Literal -- Typed literals with language tags, XSD datatype support, and type-aware comparison
    • Native Go type mapping: string, int, int64, float32, float64, bool
    • XSD datatypes: string, integer, int, long, float, double, decimal, boolean, dateTime, date, time, anyURI
    • Directional language tags (@en--ltr) per RDF 1.2
  • TripleTerm -- RDF 1.2 triple terms (triple-as-term) for reification
  • Variable -- SPARQL query variables
  • Triple / Quad -- Triple and quad representations with pattern matching

Graph

  • Graph -- Single RDF graph with full CRUD operations
  • ConjunctiveGraph -- Multiple named graphs over a shared store
  • Dataset -- Named graph management with concurrent access control
  • Resource -- Node-centric API for convenient traversal (resource.Objects(), resource.Value())
  • Collection -- RDF List (rdf:List) support with cycle detection
  • Set operations -- Union, intersection, difference between graphs
  • Pattern matching -- Triples(), Subjects(), Predicates(), Objects(), and pair iterators

Storage Backends

Everything below implements the same store.Store interface and is interchangeable: Graph, SPARQL, SHACL, reasoning and the parsers work on any of them. Each one is verified against the shared store/storetest conformance suite.

Store Package Backend Plugin name Persistence
MemoryStore store/ in-memory maps (default) no
BadgerStore store/badgerstore/ Badger v4 LSM-tree KV "badger" yes
SQLiteStore store/sqlitestore/ modernc.org/sqlite (pure Go) "sqlite" yes
SPARQLStore store/sparqlstore/ HTTP SPARQL 1.1 Protocol "sparql" remote
MongoStore rdflibgo-mongostore (external module) MongoDB "mongo" yes

Writing your own is supported and does not require a fork — see Custom Storage Backends.

In-Memory Store

  • Thread-safe triple store with RWMutex
  • Three-way indexing (SPO, POS, OSP) for efficient pattern matching
  • Namespace binding storage

Persistent Badger Store

  • BadgerStore -- store.Store implementation backed by Badger LSM-tree KV engine (from the creators of Dgraph)
  • Three KV indexes (SPO, POS, OSP) for efficient triple pattern matching via prefix scans
  • Named graph support with graph key embedded in every index entry
  • ACID transactions, MVCC concurrency (safe for parallel reads/writes)
  • Pure Go -- zero CGo dependencies, cross-compile friendly
  • Options: WithDir(), WithInMemory(), WithReadOnly(), WithLogger()
  • Registered as "badger" store type via the plugin system
import "github.com/tggo/goRDFlib/store/badgerstore"

// Persistent store
s, _ := badgerstore.New(badgerstore.WithDir("/path/to/data"))
defer s.Close()

// Use with Graph
g := graph.NewGraph(graph.WithStore(s))
g.Add(alice, name, rdf.NewLiteral("Alice"))
// Data survives process restart

Persistent SQLite Store

  • SQLiteStore -- store.Store implementation backed by modernc.org/sqlite (pure Go, zero CGo)
  • Standard relational schema with three indexes (SPO, POS, OSP)
  • WAL mode with busy_timeout for concurrent access
  • ACID transactions, human-readable database (inspectable with sqlite3 CLI)
  • Options: WithFile(), WithInMemory()
  • Registered as "sqlite" store type via the plugin system

Remote SPARQL Store

  • SPARQLStore -- store.Store implementation backed by a remote SPARQL endpoint
  • Full W3C SPARQL 1.1 Protocol support (query via GET/POST, update via POST)
  • Content negotiation: application/sparql-results+xml, application/sparql-results+json
  • Named graph support via GRAPH clause wrapping
  • Options: WithUpdate(), WithHTTPClient(), WithTimeout()
  • Implements store.ContextBinder: under sparql.QueryContext and the other *Context entry points, its HTTP requests carry the caller's context (deadline, cancellation, tracing span) — see Contexts
  • Built-in test server (sparqlstore.Server) for integration testing
  • Registered as "sparql" store type via the plugin system

MongoDB Store (external module)

  • MongoStore -- store.Store implementation backed by MongoDB, maintained as its own module: rdflibgo-mongostore
  • Also implements store.QueryableStore and store.ReachabilityStore
  • SPARQL property paths answered by $graphLookup in a single round trip
  • One document per (subject, predicate, graph) with a multikey object array; Set is a single-document update and so atomic on a standalone mongod
  • Options: WithURI(), WithDatabase(), WithClient(), WithContext(), WithTimeout(), WithErrorHandler()
  • Registered as "mongo" store type via the plugin system
  • Passes store/storetest with no declared exemptions

It lives outside this repository so that the MongoDB driver is not a dependency of everyone who uses goRDFlib. Requires goRDFlib v0.2.0 or later.

go get github.com/tggo/rdflibgo-mongostore
import (
    "github.com/tggo/goRDFlib/graph"
    mongostore "github.com/tggo/rdflibgo-mongostore"
)

s, err := mongostore.New(
    mongostore.WithURI("mongodb://localhost:27017"),
    mongostore.WithDatabase("rdf"),
)
if err != nil {
    log.Fatal(err)
}
defer s.Close()

g := graph.NewGraph(graph.WithStore(s))
g.Add(alice, knows, bob)

One document per (subject, predicate, graph), holding every object those three point at, with each value written through term.TermKey:

// collection: triples
{ s: "U:http://example.org/Alice",
  p: "U:http://example.org/knows",
  o: ["U:http://example.org/Bob", "U:http://example.org/Carol"],
  g: "" }                                  // "" is the default graph

db.triples.createIndex({s: 1, p: 1, g: 1}, {unique: true})
db.triples.createIndex({p: 1, o: 1, g: 1})   // multikey over o
db.triples.createIndex({o: 1, g: 1})         // multikey over o

Grouping rather than one document per triple is what makes Set atomic there. Set must replace (s, p, *) without a reader seeing the gap between the removal and the insert; across two documents that needs a transaction, and a standalone mongod cannot run one. Grouped this way it is a single updateOne, which MongoDB makes atomic on every deployment. It is a good illustration of what an external backend has to think about that the interface cannot state for it.

What makes MongoDB worth a dedicated backend rather than a generic document store is $graphLookup, which implements store.ReachabilityStore directly — <p>+ becomes one aggregation instead of a traversal that ships every edge of the predicate to the client:

db.triples.aggregate([
  { $match: { s: startKey, p: predKey, g: "" } },
  { $unwind: "$o" },
  { $group: { _id: null, seeds: { $addToSet: "$o" } } },
  { $graphLookup: {
      from: "triples",
      startWith: "$seeds",
      connectFromField: "o",
      connectToField: "s",
      restrictSearchWithMatch: { p: predKey, g: "" },
      as: "reached" } },
  { $project: { nodes: { $setUnion: ["$seeds",
      { $reduce: { input: "$reached.o", initialValue: [],
                   in: { $setUnion: ["$$value", "$$this"] } } }] } } },
  { $unwind: "$nodes" },
  { $group: { _id: "$nodes" } }
])

$graphLookup never revisits a document, so cycles terminate on their own, and maxDepth covers bounded paths. It is capped at 100 MiB per stage and ignores allowDiskUse, which is exactly why Reachable is allowed to return an error: the backend declines, and property path evaluation falls back to the client-side traversal rather than returning a truncated answer.

Custom Storage Backends

store.Store is a 13-method interface, and a backend implementing it works everywhere a store works: Graph, SPARQL, SHACL, reasoning, the parsers. A backend does not have to live in this repository — nothing in store.Store, term, or plugin is internal — so a store for MongoDB, Postgres, a cloud KV, or a proprietary engine can be its own module and its own release cycle.

Three things support that:

A shared conformance suite. store/storetest is the executable half of the store.Store contract — the rules that the interface documents but cannot enforce, such as "a nil context is the default graph", "a BNode context is the default graph too", "Contexts never reports the default graph", and that every term shape, RDF 1.2 triple terms included, survives a round trip. Every store shipped here runs it, so an external backend is measured against exactly the same bar:

func TestConformance(t *testing.T) {
    storetest.Run(t, storetest.Config{
        New: func(t *testing.T) store.Store {
            s, err := mongostore.New(mongostore.WithURI(uri))
            if err != nil {
                t.Fatalf("New: %v", err)
            }
            t.Cleanup(func() { s.Close() })
            return s
        },
        // Optional: reopening the same storage enables the persistence section.
        Reopen: func(t *testing.T, s store.Store) store.Store { ... },
        // Optional: behaviour the backend genuinely cannot provide, with the
        // reason. Listed subtests are skipped and the reason is printed; every
        // other subtest has to pass.
        Known: map[string]string{
            "Persistence": "requires a replica set for transactions",
        },
    })
}

Sections for the optional interfaces are enabled by detecting them, not by declaring them: implement store.QueryableStore or store.ReachabilityStore and the suite starts testing it.

Two optional pushdown interfaces. Both are opt-in, and the engine works without them:

  • store.QueryableStore — Count, Exists, TriplesWithLimit, so LIMIT, COUNT and EXISTS are answered by the backend instead of by materializing every candidate triple.
  • store.ReachabilityStore — a single transitive-closure query. This is what lets a backend with a native graph traversal answer SPARQL property paths of the form <p>*, <p>+, ^<p>+, (<p1>|<p2>)* and !(<p1>|<p2>)+ in one round trip. paths.MulPath reduces the path, asks the store, and falls back to a client-side traversal whenever the interface is absent or the backend returns an error — so declining is always safe, and a backend may decline per query when a limit would be exceeded.

A context on every call. store.Store methods take no context.Context. A backend that wants one (for tracing, deadlines or credentials) implements store.ContextBinder, whose BindContext(ctx) returns a view of the same data with ctx attached. The *Context entry points bind their context this way; see Contexts.

Registration. plugin.RegisterStore("mongo", factory) in the backend's init() makes it available by name; the consumer blank-imports the package.

An external backend is built against the same store.Store this repository uses, so the CI here clones the known satellite repositories on every commit, points them at it with a replace, and runs their test suites — an interface or conformance change goes red here rather than downstream.

rdflibgo-mongostore is the worked example of all of the above; see MongoDB Store.

Serialization Formats

All formats include both parser and serializer:

Format Parser Serializer W3C Tests
Turtle 1.2 yes yes 313/313 + 109/109 RDF 1.2 (100%)
TriG 1.2 yes yes 357/357 + 64/64 RDF 1.2 (100%)
N-Triples 1.2 yes yes 70/70 + 75/75 RDF 1.2 (100%)
N-Quads 1.2 yes yes 87/87 + 72/72 RDF 1.2 (100%)
RDF/XML 1.2 yes yes 166/166 + 31/31 RDF 1.2 (100%)
JSON-LD 1.1 yes yes toRdf 411/448 via piprate/json-gold; the 37 others are json-gold limitations, listed with reasons in jsonld/w3c_test.go

All parsers support RDF 1.2 features: triple terms (<<( s p o )>>), reified triples, annotations ({| p o |}), directional language tags, and rdf:parseType="Triple" (RDF/XML).

Skolemizing blank nodes

g.Skolemize(authority) returns a copy of the graph with every blank node replaced by an IRI under authority/.well-known/genid/ (RDF 1.1 §3.5), and DeSkolemize reverses it. By default the IRI is built from the blank node's label, and labels are fresh on every parse. For output that must be identical each time the same document is processed (checksums, diffs, idempotent loads), derive the IRIs from the graph's structure instead:

sk := g.Skolemize("https://example.org", rdflibgo.WithStableSkolemIDs())

The same graph gives the same IRIs whatever its labels or statement order. Interchangeable blank nodes (two identical [ ex:v "x" ]) get numbered suffixes rather than being merged.

Streaming parse

Every parser except JSON-LD's input side can hand statements to a callback instead of building a graph: ParseStream(r, handler, opts...) and ParseStreamContext(ctx, r, handler, opts...) in nt, nq, turtle, trig, rdfxml and jsonld. Parser options apply as they do to Parse; a handler error stops the parse and is returned, and a done context stops it with an error matching ctx.Err().

err := rdfxml.ParseStreamContext(ctx, f, func(s rdflibgo.Subject, p rdflibgo.URIRef, o rdflibgo.Term) error {
    return w.Write(s, p, o) // or count, filter, index ...
})

Memory: N-Triples, N-Quads and RDF/XML are bounded by parser state (100k RDF/XML triples: 144 MB live through a graph, under 1 MB streamed). Turtle and TriG still read the whole input before parsing. JSON-LD expands the whole document and delivers its triples only once that succeeded.

Streaming JSON-LD nodes

For newline-delimited JSON, one node object per line with one shared @context, jsonld.ParseNodes processes the context once and converts the nodes in batches of 256, so memory is bounded by a batch rather than by the input (50k nodes: 16 MB peak heap, against 373 MB for one @graph document and 35 MB for hand-made batches of 1000 Parse calls, at the same speed). Blank node identifiers are scoped to the stream, as to one document.

err := jsonld.ParseNodes(ctx, g, f, json.RawMessage(`{"@vocab": "https://schema.org/"}`),
    jsonld.WithNodeErrorHandler(func(line int, node []byte, err error) error {
        log.Printf("skipping line %d: %v", line, err)
        return nil
    }))

ParseNodesStream delivers to a handler instead; NewNodeParser with ParseNode/Flush takes nodes from any source.

Streaming N-Quads output

nq.Serialize buffers and sorts a whole graph. To write statements as they are produced, or several graphs into one file, use nq.Writer:

w := nq.NewWriter(out)
for _, doc := range docs {
    g := rdflibgo.NewGraph(rdflibgo.WithIdentifier(doc.GraphIRI))
    // ... parse into g ...
    if err := w.WriteGraph(g); err != nil { return err }
}
err := w.Flush()

A parser writes into whatever graph it is given, so parsing into a graph built with WithIdentifier is how a document lands in its own named graph; WriteGraph labels every statement with it. ExampleWriter_namedGraphs shows the full path: JSON-LD → named graph → stable Skolem IRIs → N-Quads.

Write(s, p, o, graph) and WriteQuad write single statements. A term the N-Quads parser would reject is refused with its error and nothing of it is written.

Blank-node identity when parsing

Blank-node labels identify nodes within a document, not across documents. All six parsers use a fresh blank-node scope for each parse by default. This prevents unrelated documents that both use _:b1 from joining through that label.

  • Repeated labels in one document refer to the same blank node. In TriG and N-Quads, this includes labels shared across graphs in that document.
  • A scope belongs to the parse call, not to a source URL or named graph. Parsing the same source again produces new blank-node IDs, even with the same base IRI, loader instance, or destination graph.

Each parser package (turtle, trig, nt, nq, rdfxml, and jsonld) provides WithPreserveBlankNodeIDs() for compatibility with code that needs parser IDs. The preserve option can make separate documents share blank-node identities; use it only when the caller manages those identities. JSON-LD exception: json-gold renames source labels before the N-Quads stage. Its preserve option retains those expansion IDs for compatibility, not the original source labels.

JSON-LD: remote contexts

Without a document loader, every jsonld.Parse fetches each remote @context (e.g. "https://schema.org/") over HTTP again, with no timeout. A process that parses many documents should share one caching loader:

loader := jsonld.NewCachingDocumentLoader(nil) // once
err := jsonld.Parse(g, r, jsonld.WithDocumentLoader(loader))

It is safe for concurrent use, fetches each context once (concurrent first requests wait for one fetch), does not cache failures, and its HTTP requests time out after DefaultLoaderTimeout. AddDocument bundles a context with the program so it is never fetched; Preload(doc, urls...) registers it under every spelling of its address:

loader.Preload(schemaOrgContext,
    "https://schema.org/", "https://schema.org", "http://schema.org/", "http://schema.org")

Cached documents do not expire.

JSON-LD: supplying a context the document does not declare

jsonld.WithExpandContext passes a context to the processor that is applied before the document's own @context — the expandContext option of the JSON-LD API. Use it to pre-declare terms and prefixes a document relies on but never declares, or to give a stock of defaults to documents that carry no context at all. The value may be a context definition, an IRI the document loader resolves, an array of those, or a whole document with a @context key.

ctx := map[string]any{
    "ex":   "http://example.org/",
    "name": "http://example.org/name",
}
err := jsonld.Parse(g, r, jsonld.WithExpandContext(ctx))

Precedence is the one the API specifies: the document's @context is processed on top, so a term the document defines wins over the same term in the expand context. Provenance (WithProvenance) expands identifiers through the same combined context, so an @id that only resolves thanks to the expand context still gets its source line.

Namespace System

Built-in vocabularies with pre-defined terms:

Vocabulary Prefix Description
RDF rdf: RDF core vocabulary
RDFS rdfs: RDF Schema
OWL owl: Web Ontology Language (50+ terms)
XSD xsd: XML Schema Datatypes
SHACL sh: Shapes Constraint Language
FOAF foaf: Friend of a Friend
DC dc: Dublin Core Elements 1.1
DCTERMS dcterms: Dublin Core Terms
SKOS skos: Simple Knowledge Organization System
PROV prov: Provenance Ontology
SOSA/SSN sosa:/ssn: Sensor Network Ontologies
DCAT dcat: Data Catalog Vocabulary
VOID void: Vocabulary of Interlinked Datasets

Custom namespaces with open and closed (restricted) modes.

SPARQL 1.1 Query Engine

Query forms: SELECT, ASK, CONSTRUCT (including CONSTRUCT WHERE shorthand)

Clauses and patterns:

  • Basic Graph Patterns (BGP)
  • FILTER, OPTIONAL, UNION, MINUS
  • BIND, VALUES (inline data)
  • Sub-SELECT (subqueries)
  • ORDER BY (ASC/DESC), DISTINCT, LIMIT/OFFSET
  • GROUP BY with HAVING

Aggregates (7): COUNT (with DISTINCT), SUM, AVG, MIN, MAX, GROUP_CONCAT (with SEPARATOR), SAMPLE

Built-in functions (40+):

Category Functions
Term tests BOUND, ISIRI, ISBLANK, ISLITERAL, ISNUMERIC
String STR, STRLEN, SUBSTR, UCASE, LCASE, STRSTARTS, STRENDS, CONTAINS, CONCAT, REGEX, REPLACE, STRBEFORE, STRAFTER, ENCODE_FOR_URI
Constructors STRLANG, STRDT, IRI/URI, BNODE
Accessors LANG, DATATYPE
Numeric ABS, ROUND, CEIL, FLOOR
Hash MD5, SHA1, SHA256, SHA384, SHA512
Date/Time NOW, YEAR, MONTH, DAY, HOURS, MINUTES, SECONDS, TIMEZONE, TZ
Conditional IF, COALESCE
Comparison LANGMATCHES, SAMETERM
Random/UUID RAND, UUID, STRUUID
XSD casts xsd:boolean, xsd:integer, xsd:float, xsd:double, xsd:decimal, xsd:string

Extension functions: register your own IRI-named functions (SPARQL 1.1 §17.6), the counterpart of rdflib's register_custom_function:

sparql.MustRegisterFunction("http://example.org/geo#distance",
    func(args []rdf.Term) (rdf.Term, error) {
        if len(args) != 2 {
            return nil, fmt.Errorf("geo:distance: want 2 arguments, got %d", len(args))
        }
        // ... compute ...
        return rdf.NewLiteral(d), nil
    })

Once registered, a function is callable from any query — by full IRI, <http://example.org/geo#distance>(?a, ?b), or through a prefixed name that resolves to it, geo:distance(?a, ?b) — anywhere an expression is allowed (FILTER, BIND, SELECT, HAVING, ORDER BY) including inside SHACL sh:sparql constraints. Returning an error produces a SPARQL expression error (the value is unbound), not a query failure. See examples/custom_function_example.

The registry is global and safe for concurrent use: RegisterFunction (error on duplicate), MustRegisterFunction (panic on duplicate), ReplaceFunction, UnregisterFunction, LookupFunction, RegisteredFunctions. A function that calls out and should carry the query's context is a sparql.ContextFunction, registered with RegisterContextFunction (or bound per query with ParsedQuery.BindContextFunctions); it receives the ctx passed to QueryContext.

Bounding untrusted queries

A context deadline bounds time, not memory: a cross product over a few hundred triples can take gigabytes before the deadline arrives. LIMIT (without ORDER BY, DISTINCT or grouping) and ASK stop evaluation as soon as they have enough solutions. For everything else, put a budget on the context:

ctx = sparql.WithMaxSolutions(ctx, 1_000_000)
res, err := sparql.QueryContext(ctx, g, untrusted)
if errors.Is(err, sparql.ErrTooManySolutions) { /* refuse */ }

endpoint.WithMaxSolutions(n) does the same per request and answers 422.

Contexts: tracing, deadlines, cancellation

Every long-running entry point has a *Context variant:

Package Functions
sparql QueryContext, EvalQueryContext, UpdateContext, EvalUpdateContext
paths EvalContext
shacl ValidateContext, PrepareContext, Prepared.ValidateContext, CompiledShapes.ValidateContext, ApplyRulesContext
reasoning ExpandContext, ExpandCheckContext

The context does two things. It stops the work once it is done: the call returns an error matching both the package's sentinel (sparql.ErrQueryCancelled, shacl.ErrCancelled, reasoning.ErrCancelled) and ctx.Err(), never a partial result that looks complete. And it reaches the stores: a backend that implements store.ContextBinder gets every read and write made on the caller's behalf through a view bound to ctx. That includes the queries inside SHACL constraints, targets, rules and SHACL functions, and extension functions registered as ContextFunction. So an OpenTelemetry-instrumented store sees the caller's span:

ctx, span := tracer.Start(ctx, "validate order")
defer span.End()
report, err := shacl.ValidateContext(ctx, data, shapes)

sparqlstore implements ContextBinder, so its HTTP requests carry the context. The Graph Store Protocol handlers in endpoint do not bind the request context yet; its SPARQL query and update handlers do.

SPARQL 1.2 Extensions

Full SPARQL 1.2 support -- 271/271 W3C tests pass (100%):

  • Triple term patterns -- <<( ?s ?p ?o )>> in graph patterns
  • Reified triples -- << ?s ?p ?o >> with rdf:reifies desugaring
  • Annotation syntax -- ?s ?p ?o {| :source :web |}
  • VERSION directive -- VERSION "1.2"
  • Codepoint escapes -- \uHHHH / \UHHHHHHHH in prefixed names
  • Directional language tags -- "text"@en--ltr
  • New functions -- TRIPLE(), SUBJECT(), PREDICATE(), OBJECT(), isTriple(), LANGDIR(), hasLANG(), hasLANGDIR(), STRLANGDIR()

SPARQL 1.1 Update Engine

Data operations:

  • INSERT DATA, DELETE DATA
  • DELETE/INSERT WHERE (with template instantiation)
  • DELETE WHERE (shorthand)

Modify operations:

  • WITH clause (scoped graph target)
  • USING / USING NAMED (query dataset override)
  • Multiple operations separated by ;

Graph management:

  • CLEAR, DROP (DEFAULT / NAMED / ALL / specific graph)
  • CREATE GRAPH
  • ADD, MOVE, COPY (between graphs)
  • LOAD (with rdfloader.DefaultLoader for http(s):// and file:// URIs, auto-format detection)

Dataset: sparql.Dataset holds default graph + named graphs map for multi-graph update operations.

Property Paths

Full SPARQL 1.1 property path support:

  • Inverse -- ^p
  • Sequence -- p1/p2
  • Alternative -- p1|p2
  • Repetition -- p* (zero or more), p+ (one or more), p? (zero or one)
  • Negated -- !p (negated property set)
  • Cycle detection for transitive closure operations
  • Backend pushdown: p*, p+, ^p+, (p1|p2)* and !(p1|p2)+ are answered by the store in one call when it implements store.ReachabilityStore, with an automatic fall back to client-side traversal otherwise

SHACL Validator

Full W3C SHACL Core validation engine -- 98/98 W3C SHACL Core tests pass (100%); with SHACL-SPARQL and the SHACL 1.2 suites (Core, SPARQL, node expressions, rules), 905/905.

Targets:

  • sh:targetNode, sh:targetClass (with rdfs:subClassOf inference)
  • sh:targetSubjectsOf, sh:targetObjectsOf
  • Implicit class targets (NodeShape that is also rdfs:Class)

Constraint components (28):

Category Constraints
Cardinality sh:minCount, sh:maxCount
Value type sh:class, sh:datatype, sh:nodeKind
Value range sh:minExclusive, sh:minInclusive, sh:maxExclusive, sh:maxInclusive
String sh:minLength, sh:maxLength, sh:pattern (with flags), sh:languageIn, sh:uniqueLang
Property pair sh:equals, sh:disjoint, sh:lessThan, sh:lessThanOrEquals
Logical sh:and, sh:or, sh:not, sh:xone
Shape-based sh:node, sh:property, sh:qualifiedValueShape (with min/max count)
Other sh:hasValue, sh:in, sh:closed

Additional features:

  • Property shapes with sh:path (including property paths)
  • Node shapes
  • Severity levels: sh:Violation, sh:Warning, sh:Info
  • Custom messages via sh:message
  • Shape deactivation via sh:deactivated
  • Recursive shape validation
  • Prepared.Conforms(ctx, node, shape): does one node conform to one shape, ignoring its targets — what sh:node asks, safe for concurrent calls
  • Ill-formed shapes (a property shape without exactly one sh:path) are reported as ErrIllFormedShape through WithErrorHandler, or returned under WithStrictShapes
  • WithDefaultMessages(): a generated sh:resultMessage per constraint component ("Less than 1 values on ex:p1->ex:title") for results the shapes give none

Source Lines in Validation Results

A SHACL report is about a graph, and a graph has no text, so a plain report can only name a node — which is why no SHACL implementation has historically been able to say which line of the file is wrong (pySHACL#321 was closed as not possible on RDFLib, whose parsers hand the validator nothing about the source).

The parsers here already report a source line per triple through WithProvenance. provenance.Index collects that, and shacl.WithSourceLines puts it back on each result:

data := graph.NewGraph()
lines := provenance.NewIndex()
turtle.Parse(data, r, turtle.WithProvenance(lines.Triple))

report := shacl.Validate(
    shacl.NewGraphFromRDF(data, ""),
    shacl.NewGraphFromRDF(shapes, ""),
    shacl.WithSourceLines(lines),
)

for _, res := range report.Results {
    fmt.Printf("%s:%d: %s\n", file, res.SourceLine, res.ResultMessages[0].Value())
}
people.ttl:11: not an email address
     |     ex:email "bob-at-example-org" ;
people.ttl:12: age must be an integer
     |     ex:age   "middle aged" .
people.ttl:14: a person needs a name
     | ex:carol a ex:Person ;

ValidationResult.SourceLineKind distinguishes the two answers, because they are not equally precise:

  • SourceLineTriple — the offending triple's own line. The value the constraint rejected is written there.
  • SourceLineFocusNode — where the focus node was first mentioned. This is what a constraint about an absence reports: a failed sh:minCount has no offending triple, because the triple is the thing that is missing.
  • SourceLineNone — no line. The triple was inferred by a SHACL-AF rule or the reasoner, or added programmatically, so it was never in any file.

Entirely opt-in: without WithSourceLines the report is byte-for-byte what it always was, and SourceLine stays 0. The line is a Go-level field and is not part of the RDF form of the report, which SHACL defines and does not extend.

Every parser reports provenance, at the precision its format allows:

Format Precision How
N-Triples, N-Quads triple one triple per line
Turtle, TriG triple the line the triple was completed on
RDF/XML triple xml.Decoder input position at the end of the property element
JSON-LD node object the line the subject's @id block opens on

JSON-LD is the one that cannot be per triple. Its triples come out of an expansion performed by json-gold, which resolves contexts and term definitions and returns a dataset with no memory of where any of it came from (json-gold#96 asks for that and is still open). What is recoverable is where each @id was written, so a triple is reported against the line its subject's node object opens on.

It never guesses. Identifiers are expanded through the document's own @context (on top of any WithExpandContext) using the same processor that produced the triples, so a match is a match rather than a resemblance; anything that fails to expand contributes nothing. A node object with no @id — a blank node whose label the expander invents — gets no line at all, because a wrong line is worse than none. @id aliased through a context ({"id": "@id"}) is honoured.

Runnable version: examples/shacl_source_lines_example/.

SHACL Advanced Features (SHACL-AF)

Added in response to a user feature request, #24. Consider it experimental until it has been run against real SHACL-AF workloads — bug reports and real-world test cases are very welcome.

SHACL-AF is a W3C Note rather than a Recommendation, but it is what pySHACL and TopQuadrant's Java API implement, so shapes written against it are common. It is supported as an opt-in mode, kept separate from the SHACL 1.2 constructs that respecify the same ground:

report := shacl.Validate(data, shapes, shacl.WithAdvancedFeatures())
Feature Vocabulary
Rules sh:rule with sh:TripleRule / sh:SPARQLRule, sh:condition, sh:order, sh:deactivated
Node expressions sh:this, sh:path (with sh:nodes), sh:union, sh:intersection, sh:filterShape, function calls
Functions sh:SPARQLFunction with sh:select / sh:ask, sh:parameter, sh:optional, sh:returnType
Custom targets sh:target with sh:SPARQLTarget and sh:SPARQLTargetType
Expression constraints sh:expression
Entailment sh:entailment sh:Rules

Under Validate the rules run first and validation sees what they infer; the caller's data graph is never modified. To keep the inferred triples, apply the rules explicitly:

n, err := shacl.ApplyRules(data, shapes)          // mutates data, returns triples added
n, err := shacl.ApplyRules(data, shapes, shacl.WithRuleIteration())

Rules execute in sh:order and once per focus node, as the spec describes. WithRuleIteration repeats to a fixed point for chains that ordering cannot express. Problems that Validate cannot return — a malformed rule, a rule set that never settles — reach the caller through shacl.WithErrorHandler.

SHACL functions are bound to the query being run rather than registered globally, so two shapes graphs may define the same function IRI differently and still be used concurrently. The same mechanism is available directly: sparql.ParsedQuery.BindFunctions.

Conformance: 13/13 DASH advanced-features test cases (testdata/dash-af/), the suite both reference implementations are tested against.

Many documents, one shapes graph

Validate parses the shapes graph on every call. A service that checks many documents against the same shapes should parse them once:

compiled, err := shacl.CompileShapes(shapes) // once, at startup
// ...
report := compiled.Validate(doc)              // per document, from any goroutine

CompiledShapes is safe for concurrent use and gives the same report as Validate. Options passed to CompileShapes apply to every call; per-document options (WithSourceLines, WithErrorHandler) go to Validate itself. On the shapes and documents from issue #39, validation per document went from 620 µs (v0.6.0, Validate) to 286 µs (v0.7.1, CompiledShapes); with small documents and more shapes the gap is larger (~20x in BenchmarkCompiledShapes). See Performance for the whole parse-and-validate pipeline.

Many documents over one shared graph

When every document is validated together with the same large graph (a vocabulary, reference data), wrapping the store again per document re-indexes all of it. Index the shared graph once and overlay each document on it:

base, err := shacl.NewGraphFromRDF(ctx, shared, "") // once
// per document:
overlay, err := base.Overlay(ctx, doc) // doc is a []term.Triple
report := compiled.Validate(overlay)

The overlay indexes only doc and reads base's indexes, which any number of overlays share, from any goroutine. Nothing is written to shared: SPARQL-based constraints and SHACL-AF query a read-only store.UnionStore of shared and a small in-memory store holding doc, so documents over one base validate concurrently, SPARQL shapes included. An overlay is read-only (Add and Merge return shacl.ErrReadOnly), and base must not be changed while overlays over it are in use. Runnable version: ExampleGraph_Overlay.

Parse once, validate, then serialize

A document does not have to be parsed twice to be both validated and written out. Parse it into an rdflibgo.Graph and wrap that graph for SHACL:

compiled, _ := shacl.CompileShapes(shapes)       // once
loader := jsonld.NewCachingDocumentLoader(nil)   // once, shared

g := rdflibgo.NewGraph()
err := jsonld.Parse(g, r, jsonld.WithDocumentLoader(loader))
report := compiled.Validate(shacl.NewGraphFromRDF(g, ""))
if report.Conforms {
    err = nq.Serialize(g, w)
}

NewGraphFromRDF wraps the graph without copying it, so the report and the N-Quads describe exactly the same triples. Don't modify g while a validation of it is running. Runnable version: ExampleCompiledShapes_parseOnce.

Triples already in memory

A program that builds its triples itself (rather than parsing a file) hands them over without filling a store first:

report := compiled.Validate(shacl.NewGraphFromTriples(triples, "")) // triples []term.Triple

Validation reads indexes built from the slice, as for LoadJsonLD; the rdflib graph is built only if a SPARQL-based constraint, Add, Merge or a SHACL-AF rule needs it. Don't modify the slice while the graph is in use. Runnable version: ExampleNewGraphFromTriples.

Prepared validation and inspection

A validation report contains findings, not every shape application. To inspect how shapes apply to the data, even where every constraint passes, prepare the run first:

prepared := shacl.Prepare(data, shapes, shacl.WithAdvancedFeatures())
report := prepared.Validate()

for info := range prepared.Shapes() {
    for _, focus := range prepared.Targets(info.ID) {
        for via, child := range prepared.ShapeLinks(info.ID) {
            // via is sh:property, sh:node, sh:and, sh:or, sh:xone or sh:not
            _ = prepared.ValueNodes(child, focus)
        }
    }
}

Prepare runs the configured rule derivation once and keeps the parsed shapes and the derived data. Inspection can come before or after Validate, and neither reruns rules. shacl.Validate(data, shapes, opts...) is Prepare(...).Validate().

  • Shapes and Shape return ShapeInfo descriptions, including the RDF node that defines a property path.
  • Targets returns a shape's focus nodes. They are selected once and shared with Validate, so a target that mints blank nodes selects the same ones for both.
  • ShapeLinks lists sh:property, sh:node, sh:and, sh:or, sh:xone and sh:not references. Qualified shapes, rule conditions and target definitions are not followed.
  • ValueNodes selects a shape's values the way validation does (including sh:values); PathValues evaluates a path defined in the shapes graph.
  • ShapeObjects reads shape parameters and path-definition triples.

Returned slices are copies. Keep the data and shapes graphs unchanged while a Prepared is in use; it is not safe for concurrent use, but independent prepared runs may share the same source graphs. WithErrorHandler reporting is unchanged.

Plugin System

  • Format auto-detection by filename extension (.ttl, .trig, .nt, .nq, .rdf, .owl, .jsonld)
  • MIME type detection (text/turtle, application/rdf+xml, etc.)
  • Content sniffing (XML headers, JSON, @prefix, etc.)
  • Extensible parser, serializer, and store registries

Installation

go get github.com/tggo/goRDFlib

Upgrading from an earlier version? MIGRATION.md lists, version by version, what changes and how to find the affected code.

Quick Start

package main

import (
    "fmt"
    "os"
    "strings"

    rdf "github.com/tggo/goRDFlib"
    "github.com/tggo/goRDFlib/sparql"
    "github.com/tggo/goRDFlib/turtle"
)

func main() {
    g := rdf.NewGraph()
    g.Bind("ex", rdf.NewURIRefUnsafe("http://example.org/"))

    alice, _ := rdf.NewURIRef("http://example.org/Alice")
    name, _ := rdf.NewURIRef("http://example.org/name")
    age, _ := rdf.NewURIRef("http://example.org/age")

    g.Add(alice, rdf.RDF.Type, rdf.NewURIRefUnsafe("http://example.org/Person"))
    g.Add(alice, name, rdf.NewLiteral("Alice"))
    g.Add(alice, age, rdf.NewLiteral(30))

    // Serialize to Turtle (compact by default; turtle.WithPretty() indents)
    turtle.Serialize(g, os.Stdout)
    turtle.Serialize(g, os.Stdout, turtle.WithPretty())

    // Parse Turtle
    g2 := rdf.NewGraph()
    turtle.Parse(g2, strings.NewReader(`
        @prefix ex: <http://example.org/> .
        ex:Bob a ex:Person ; ex:name "Bob" .
    `))

    // SPARQL query
    result, _ := sparql.Query(g, `
        PREFIX ex: <http://example.org/>
        SELECT ?name WHERE { ?s ex:name ?name }
    `)
    for _, row := range result.Bindings {
        fmt.Println(row["name"])
    }
}

SPARQL Update Example

ds := &sparql.Dataset{Default: g}

// DELETE/INSERT WHERE: bulk status change with pattern matching
err := sparql.Update(ds, `
    PREFIX ex: <http://example.org/>
    DELETE { ?s ex:status "draft" }
    INSERT { ?s ex:status "published" }
    WHERE  { ?s ex:status "draft" }
`)

// Graph management: copy default graph to a named graph
err = sparql.Update(ds, `COPY DEFAULT TO <http://example.org/archive>`)

SHACL Validation Example

package main

import (
    "fmt"
    "log"

    "github.com/tggo/goRDFlib/shacl"
)

func main() {
    data, err := shacl.LoadTurtleString(`
        @prefix ex: <http://example.org/> .
        @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
        ex:Alice a ex:Person ; ex:name "Alice" ; ex:age 30 .
        ex:Bob   a ex:Person ; ex:age "not a number" .
    `, "")
    if err != nil {
        log.Fatal(err)
    }

    shapes, err := shacl.LoadTurtleString(`
        @prefix sh: <http://www.w3.org/ns/shacl#> .
        @prefix ex: <http://example.org/> .
        @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

        ex:PersonShape a sh:NodeShape ;
            sh:targetClass ex:Person ;
            sh:property [
                sh:path ex:name ;
                sh:minCount 1 ;
                sh:datatype xsd:string ;
            ] ;
            sh:property [
                sh:path ex:age ;
                sh:datatype xsd:integer ;
            ] .
    `, "")
    if err != nil {
        log.Fatal(err)
    }

    report := shacl.Validate(data, shapes)
    fmt.Printf("Conforms: %v\n", report.Conforms)
    for _, r := range report.Results {
        fmt.Printf("  Focus: %s, Path: %s, Constraint: %s\n",
            r.FocusNode, r.ResultPath, r.SourceConstraintComponent)
    }
}

W3C Conformance

All parsers, SPARQL engine, and SHACL validator are validated against official W3C test suites:

Component Tests Pass Status
SPARQL 1.1 Query 353 353 100%
SPARQL 1.0 Dataset (FROM / FROM NAMED) 12 12 100%
SPARQL 1.0 (DAWG syntax and evaluation) 475 475 100%
SPARQL 1.1 Update 157 157 100%
SPARQL 1.2 271 271 100%
SPARQL 1.1 Federated (syntax-fed, service) 10 10 100%
SPARQL 1.1 Protocol 34 34 100%
SPARQL 1.1 Graph Store Protocol 14 14 100%
SPARQL 1.1 GSP (deprecated manifest) 18 18 100%
SPARQL 1.1 Results JSON 4 4 100%
SPARQL 1.1 Results CSV/TSV 8 8 100%
Turtle 1.1 313 313 100%
Turtle 1.2 109 109 100%
TriG 1.1 357 357 100%
TriG 1.2 64 64 100%
N-Triples 1.1 70 70 100%
N-Triples 1.2 75 75 100%
N-Quads 1.1 87 87 100%
N-Quads 1.2 72 72 100%
RDF/XML 1.1 166 166 100%
RDF/XML 1.2 31 31 100%
JSON-LD 1.1 toRdf 467 411 19 skipped: JSON-LD 1.0 only; 37 skipped: json-gold limitations, each with its reason in jsonld/w3c_test.go
SHACL Core 98 98 100%
SHACL-SPARQL 22 22 100%
SHACL 1.2 Core 162 162 100%
SHACL 1.2 SPARQL 98 98 100%
SHACL 1.2 Node Expressions 284 284 100%
SHACL 1.2 Rules (SRL) 241 241 100%
RDF 1.1 Semantics (entailment) 48 48 100%
RDF 1.2 Semantics (entailment) 29 29 100%
Total 4149 4093 0 failed, 56 skipped

Counts are leaf test cases from go test -json, produced by make test-w3c.

make test          # all tests
make test-sparql   # W3C SPARQL 1.1 conformance
make test-w3c      # every W3C suite, one row each

Fuzz Testing

make test-fuzz                # 30s per target
make test-fuzz FUZZTIME=5m    # when hunting something specific
Target Property checked
sparql/FuzzParse, FuzzParseUpdate no panic, no infinite loop; seeded from every W3C SPARQL 1.1 and 1.2 test file
rdfxml/FuzzParseProvenance no panic on arbitrary XML; every reported line exists; every triple in the graph has one
jsonld/FuzzScanIDPositions every reported line exists; only identifiers actually written are reported
jsonld/FuzzLineIndex offset-to-line agrees with the naive implementation
jsonld/FuzzParseProvenance a failed parse reports nothing; a line is only given to a subject the graph holds
provenance/FuzzIndexKeyCollisions two distinct triples never share a key, whatever a literal contains
provenance/FuzzTripleKeySplit, FuzzSubjectLineIsTheMinimum key layout and earliest-line selection
shacl/FuzzSourceLines, FuzzSourceLinesNeverInvent no result names a line outside the file; a SourceLineTriple always has the triple to back it

Seed corpora run as ordinary tests on every go test, so a fixed crash stays fixed.

Fuzzing the provenance work turned up a crash that predated it: jsonld.Parse panicked instead of erroring on some malformed input, because json-gold resolves a reference against a URL that failed to parse. A parser is routinely aimed at untrusted bytes, so the processor is now guarded and a panic comes back as an error wrapping jsonld.ErrProcessorPanic, stack included.

Performance

Benchmarked against Python rdflib 7.6.0 + pyshacl 0.31.0 on Apple M4 Max. Go figures are the median of 6 runs (v0.7.2), Python figures the median of 3.

Benchmark Go Python Speedup
NewURIRef 36 ns 337 ns 9x
NewBNode 220 ns 2,545 ns 12x
NewLiteral (string) 14 ns 1,318 ns 92x
NewLiteral (int) 15 ns 1,922 ns 132x
URIRef.N3() 15 ns 297 ns 20x
Literal.N3() 27 ns 403 ns 15x
Literal.Eq() 22 ns 335 ns 15x
Store Add 10k 7.3 ms 83.0 ms 11x
Store Lookup 1k 5.6 us 878 us 157x
Parse Turtle 4.0 us 262 us 65x
Serialize Turtle 4.7 us 96 us 20x
SPARQL SELECT 46 us 1,825 us 39x
SHACL Validate (10 nodes) 13 us 1,097 us 82x
SHACL Validate (100 nodes) 74 us 8,202 us 110x
SHACL Validate (complex) 43 us 7,849 us 184x
go test ./benchmarks/ -bench=. -benchmem -count 6
python3 benchmarks/bench_python.py

JSON-LD + SHACL pipeline (issue #39)

The pipeline is harvested schema.org documents (4 KB, 124 KB and 5 KB) parsed and validated against one fixed shapes graph (geoconnex.ttl), as in internetofwater/nabu. The benchmarks are the ones from #39. Versions ran alternately, 8 runs each, and benchstat compared them. v0.6.0 calls shacl.Validate per document; v0.7.1 and v0.8.0 use CompileShapes and a shared CachingDocumentLoader. v0.8.0 was measured against v0.7.2 in a separate run (1.61 / 2.20 / 0.52 ms there); its gain is shacl.LoadJsonLD indexing the triples directly instead of through a MemoryStore (#48).

Per document v0.6.0 v0.7.1 v0.8.0 v0.6.0 → v0.8.0
Parse JSON-LD 8.96 ms 1.65 ms 1.15 ms 7.8x
Validate 620 us 286 us 273 us 2.3x
Parse + validate 9.97 ms 2.33 ms 1.77 ms 5.6x
Parse + validate, 14 goroutines 1.60 ms 0.54 ms 0.42 ms 3.8x
Memory, parse + validate 5.35 MiB 2.89 MiB 2.24 MiB -58%
Allocations, validate 14.1k 393 392 -97%

Store Stress Test (3M triples, Apple M4 Max)

Metric Memory Badger Badger Disk SQLite SQLite Disk
Ingest time 3.7s 7.3s 8.7s 20.0s 30.6s
Ingest rate 804K/s 408K/s 346K/s 150K/s 98K/s
Go heap delta 4.3 GB 1.6 GB — outside Go heap —
Len() 4.0 ns 443ms 446ms 104ms 106ms
Full scan 629ms 956ms 985ms 1.47s 1.57s
Subject lookup 86 ns 2.2 us 2.2 us 1.8 us 2.6 us
Predicate scan (15K triples) 0.92ms 3.8ms 3.9ms 370ms 412ms

Measured on v0.7.2. Ingest and heap delta are single runs of TestStress3M. Reads are the median of 6 runs of BenchmarkStress3M, which loads each backend once and repeats every read. MemoryStore's heap halved (8.4 GB → 4.3 GB) when its three indexes started sharing one copy of each triple. SQLite (modernc.org/sqlite) allocates its pages outside the Go heap, so the heap delta cannot see them.

go test ./store/ -run TestStress3M -v -count=1
go test ./store/ -run '^$' -bench BenchmarkStress3M -count 6

Examples

The examples/ directory contains runnable programs:

Example Description
simple_example Basic graph operations and triple manipulation
format_examples Parsing and serializing all supported formats
sparql_query_example SPARQL SELECT, ASK, and CONSTRUCT queries
custom_function_example Registering and calling SPARQL extension functions
property_paths_example Property path traversal
resource_example Node-centric Resource API
shacl_example Basic SHACL validation
shacl_constraints_example SHACL constraint types
transitive_example Transitive closure with property paths

Package Structure

goRDFlib/
  term/         Core RDF terms (URIRef, BNode, Literal, Variable)
  store/        Store interface + thread-safe in-memory triple store
  graph/        Graph, ConjunctiveGraph, Dataset, Resource, Collection
  namespace/    Built-in vocabularies and namespace management
  turtle/       Turtle parser and serializer
  nt/           N-Triples parser and serializer
  nq/           N-Quads parser and serializer
  rdfxml/       RDF/XML parser and serializer
  jsonld/       JSON-LD parser and serializer
  trig/         TriG parser and serializer
  sparql/       SPARQL 1.1/1.2 query and update engine
  store/badgerstore/  Persistent Badger KV store (SPO/POS/OSP indexes)
  store/sqlitestore/  Persistent SQLite store (pure Go)
  store/sparqlstore/  Remote SPARQL Protocol store + test server
  store/storetest/    Shared conformance suite for store.Store backends
  paths/        Property path evaluation
  provenance/   Source-line index linking triples back to the text they came from
  shacl/        SHACL Core validator
  rdfloader/    HTTP/file URI loader for SPARQL LOAD
  plugin/       Format registry and auto-detection
  examples/     Runnable example programs
  benchmarks/   Performance benchmarks

Acknowledgements

Much of what this library does well, it does because someone took the time to open an issue explaining what was broken or missing — often with a minimal reproduction attached. Several features exist only because they were asked for.

  • @utrack (Nikita Koptelov) — the SHACL-AF layer is a direct response to #24, which asked whether the library was committing to SHACL 1.2 or SHACL-AF; the answer became "both, kept apart". Also reported two precise SHACL-SPARQL bugs (#20, #21) and contributed the reasoning fix in #23 — blank nodes as classes, and closing RDFS/OWL RL to a joint fixed point.
  • @C-Loftus (Colton Loftus) — sustained real-world pressure on the parsers: streaming and buffer limits (#10, #11, #12), provenance tracking (#18), base IRI handling (#19), SHACL error locations (#15), plus the unbounded JSON-LD parsing option in #14.
  • @situx — asked how to register SPARQL extension functions (#22), which produced sparql.RegisterFunction and, later, the query-scoped binding that SHACL functions are built on.
  • @asdfsx — JSON-LD support for SHACL (#5, #6).
  • @justin2004 — nested blank nodes in CONSTRUCT templates (#9).

Issues and pull requests are welcome — especially ones carrying a real workload this library has not seen yet.

Based On

This project is a Go port of RDFLib (v7.x), a Python library for working with RDF. The original RDFLib is maintained by the RDFLib Team and licensed under the BSD 3-Clause License.

Test suites are vendored from the W3C (data-shapes, rdf-tests) and, for SHACL Advanced Features, from TopQuadrant/shacl and RDFLib/pySHACL — see testdata/dash-af/README.md for provenance.

Known Limitations

  • JSON-LD processing delegates to piprate/json-gold which may attempt remote context fetches
  • SPARQL UPDATE LOAD requires the SILENT flag when no loader is configured (default: rdfloader.DefaultLoader handles http://, https://, and file:// URIs with auto-format detection)

License

BSD 3-Clause License. See LICENSE.

The original Python RDFLib is Copyright (c) 2002-2025, RDFLib Team.

About

Go RDF library with full SPARQL 1.1 query/update engine and SHACL validator. 100% W3C conformance (1221/1221 tests). Port of Python RDFLib.

Topics

Resources

Contributing

Stars

38 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages