Command-Line Client (CLI)

The Dydra command-line client is a Ruby gem installable via RubyGems. This client has command-line functions for most of the REST and RPC APIs. You may never need to use it, but you can use it to easily write scripts to automate certain repository actions, and to use query results inside other, simple scripts.

Installing the Client

The client is installed via RubyGems. The client is tested on Ruby 1.8.7, 1.9.1, 1.9.2, and JRuby.


RubyGems is installed by default on OS X. Simply open a terminal ( Applications –> Utilities –> Terminal) and type:

$ sudo gem install dydra

You’ll be asked to enter your system password.


Windows users can install a working RubyGems environment with the Ruby installer at If you have any trouble, there’s a wealth if tutorials for getting Ruby started on windows at

After installing Ruby via the Ruby Installer, run a shell (Win+R and type cmd) and type:

C:\Users\Administrator>gem update --system
Updating RubyGems
Nothing to update
C:\Users\Administrator>gem install dydra

Most Linux systems have Ruby and RubyGems easily available. For Ubuntu 10.x, we recommend the rubygems1.9.1 package. If you have another version of Ruby installed, that’s fine too.

After Ruby and RubyGems are installed, whatever package your distribution uses, type:

$ gem install dydra

The dydra command should now be available. If not, your distributions may require adjustments to your PATH environment variable to properly use RubyGems. Check your distribution’s RubyGems documentation.

Using the Client

The first time you run the Dydra command, you’ll be asked to authenticate. When you type your username and password, your API token will be saved to ~/.dydra/credentials and used for future commands.

$ dydra create foaf
Username or email: alice

The client currently performs several basic operations at the command line.

Specifiying Repositories

After you log in with the client, your account name will be cached, and any command which specifies a repository will default to your own.

$ dydra count foaf
10 foaf
10 total

But you can always specify any repository to which you have access for any command by specifying the username:

$ dydra count bhuga/foaf
20 foaf
20 total
Repository Creation

Create a new repository with the create command:

$ dydra create foaf

This creates a repository for your account named foaf.


Imports a URL or local file into a repository.

$ dydra import foaf
completed: Completed at 2011-03-19 21:29:37 +0000

Runs a SPARQL query on a repository.

$ dydra query foaf 'select distinct ?s where { ?s ?p ?o }'

Command-line sparql queries are output in a tab-delimited format for easy processing by further command-line tools. The first line will be a list of variables.

You can also get raw SPARQL results to feed in to an existing tool, if you choose. Add -x to get SPARQL-XML results.

$ dydra query foaf 'select distinct ?s where { ?s ?p ?o }' -x
<?xml version='1.0'?>
<sparql xmlns=''>
   <binding name='s'><uri></uri></binding>
   <binding name='s'><uri></uri></binding>

Add -j for SPARQL-JSON results.

$ dydra query foaf 'select distinct ?s where { ?s ?p ?o }' -j
{ "head": { "vars": [ "s" ] },
   "results": {
   "bindings": [
   { "s": {"type":"uri", "value":""} },
   { "s": {"type":"uri", "value":""} } ] } }
Clearing a Repository

Clear a repository’s contents with the clear command:

$ dydra clear foaf
Counting Triples

Get a count of the triples in a repository with the count command:

$ dydra count foaf empty-repo
10 foaf
0 empty-repo
10 total
Listing Repositories

List your repositories, or those of another user, with the list command:

$ dydra list
$ dydra list bhuga
Deleting a Repository

Delete a repository permanently with the drop command:

$ dydra drop foaf

Client API

The Dydra gem can also be used as an API for writing Ruby programs.