Get Version


→ ‘rubyrdf’


An RDF data access layer for Ruby with a pluggable graph implementation. I have three goals:

  1. Provide an in-memory, pure Ruby implementation of the RDF graph model for situations where a high performance triple store is not needed.
  2. Provide plug-in graph implementations that delegate to high performance triple stores for situations where high performance is needed.
  3. Smooth out differences between triple stores to provide a consistent interface to RDF data. An example of this would be to deletgate reasoning to a triple store when available, but to provide a pure Ruby RDF reasoning engine that can be used with the in-memory model, or with triple stores that do not support reasoning. Same goes for SPARQL queries, import/export formats, etc.


sudo gem install rubyrdf

The basics

RubyRDF implements the basic RDF data model (UriNode, TypedLiteralNode, PlainLiteralNode, BlankNode, Graph, etc.). There is also a very, very simple querying mechanism that would hopefully be replaced by SPARQL or a SPARQL-based DSL. There is also a fully compliant NTriples import/export function.

There is a in-memory graph implementation, and a Sesame 1.2.7 graph implementation that uses Sesame’s HTTP protocol.

There is a class (Namespace) that is used to generate new UriNodes easily.

For more details about the API see the rdocs.

There are also some subprojects (at this point just one) that provide graph implementations for specific triple stores:

Demonstration of usage

Adding data to a graph

g =
g.add(''), RDF::type, RDF::Resource)

Registering a new namespace

RDF::Namespace.register(:dc, '')
# you can also create instances of Triple and add them to the graph
t =''), 

Querying a graph

q =, :y).where(:x, DC::author, :y)
result = g.execute(q)
result.bindings.each do |b|
  puts "x = #{b[:x]}"
  puts "y = #{b[:y]}"


How to get involved

I am using Bazaar for source control, and Launchpad for development management. This provides (in my opinion) a superior development process. Since bazaar is a distributed version control system, you do not need my permission to start hacking on the code, you only need to branch it

bzr branch rubyrdf

Write your tests. Write your code. Test. Then commit

bzr commit -m"Some useful message about what you have done"

If you want to let me know about your changes to have them included in the main development branch, then you’ll need to publish your branch somewhere. Launchpad provides bazaar hosting. To host your code there you’ll need a Launchpad account.

bzr push s[your launchpad login]/rubyrdf/[your branch name]

Let me know what you have done, and if your changes work, then I’ll pull them into the main branch, or I’ll provide feedback. You can also do stuff like associate a commit with a bug report, and Launchpad will automagically notice. For a more detailed tutorial see Bazaar in five minutes and Using Bazaar with Launchpad.


This code is free to use under the terms of the BSD license (revised).


Comments are welcome. Send an email to Paul Stadig via the forum

FIXME full name, 9th April 2008
Theme extended from Paul Battley