Skip to content


Subversion checkout URL

You can clone with
Download ZIP
A Python library for working with APIs
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A Python library for working with APIs.


This is a library for working with APIs provided by Kasabi

Homepage: Pypi:


Install with easy_install:

>sudo easy_install pytassium

If you already have it installed then simply upgrade with:

>sudo easy_install --upgrade pytassium

pytassium requires the following (should be handled automatically with easy_install):

Getting Started

The basic pattern of usage is as follows:

import pytassium
import time
dataset = pytassium.Dataset('nasa','put-your-api-key-here')

# --------------------------
# Use the lookup API
# --------------------------
response, data = dataset.lookup('')
if response.status in range(200,300):
  # data now contains an rdflib.Graph
  print data.serialize(format="turtle") 
  print "Oh no! %d %s - %s" % (response.status, response.reason, body)

# --------------------------
# Use the sparql API
# --------------------------
response, data ='select ?s where {?s a <>} limit 10')
if response.status in range(200,300):
  # data now contains a dictionary of results
  print data
  print "Oh no! %d %s - %s" % (response.status, response.reason, body)

# --------------------------
# Use the attribution API
# --------------------------
response, data = dataset.attribution()
# assuming success, data now contains dictionary
print data['homepage']

# --------------------------
# Use the search API
# --------------------------
# search for 5 results matching apollo
response, data ="apollo", 5)
for result in data['results']:
  print "%s (score: %s)" % (result['title'], result['score'])

# facet on a search for alan, with the name and type fields
fields = ['name', 'type']
query = "alan"
response, data = dataset.facet(query, fields)
for facet in data['fields']:
  print "Top %ss matching %s" % (facet['name'],query)
  for term in facet['terms']:
    print "%s (%s results)" % (term['value'], term['number'])

# --------------------------
# Use the reconciliation API
# --------------------------
# Reconcile one label
response, data = dataset.reconcile('Alan Shepard')
print "Best match is: %s" % data['result'][0]['id']

# Reconcile a list of labels
labels = ['Neil Armstrong','alan shepard']
response, data = dataset.reconcile(labels)
for i in range(0, len(labels)):
  print "Best match for %s is: %s" % (labels[i], data['q%s'%i]['result'][0]['id'])

# Reconcile a label with specific parameters
response, data = dataset.reconcile('Apollo 11', limit=3, type='', type_strict ='any')
print "Best match is: %s" % data['result'][0]['id']

# Reconcile with a specific query
query = {
    "query" : "Apollo 11",
    "limit" : 3,
    "type" : "",
    "type_strict" : "any",
response, data = dataset.reconcile(query)
print "Best match is: %s" % data['result'][0]['id']

# --------------------------
# Use the update API
# --------------------------
dataset = pytassium.Dataset('my-writable-dataset','put-your-api-key-here')

# Store the contents of a turtle file
dataset.store_file('/tmp/mydata.ttl', media_type='text/turtle') 

# Store data from a string
mytriples = "<> a <> ."
dataset.store_data(mytriples, media_type='text/turtle') 

# --------------------------
# Use the jobs API
# --------------------------
response, job_uri = dataset.schedule_reset()
print "Reset scheduled, URI is: %s" % job_uri
print "Waiting for reset to complete"
done = False
while not done:
  response, data = dataset.job_status(job_uri)
  if response.status in range(200,300):
    if data['status'] == 'scheduled':
      print "Reset has not started yet"
    elif data['status'] == 'running':
      print "Reset is in progress"
    elif data['status'] == 'failed':
      print "Reset has failed :("
      done = True
    elif data['status'] == 'succeeded':
      print "Reset has completed :)"
      done = True

  if not done:

Using pytassium command line

The pytassium package comes with a command line utility. Use it from the command line like this:


You'll be presented with a command prompt:


First you need to tell it which dataset you want to work with. The "use" command does this. You can supply the short name of the store or the full URI, it doesn't matter:

>>> use nasa
Using nasa

You also need to supply your API key:

>>> apikey yourapikey

You can also specify the dataset and apikey using the -d and -a command line options:

./pytassium -d nasa -a yourapikey

Alternatively you can specify the default apikey to use by setting the KASABI_API_KEY environment variable. In Linux:

export KASABI_API_KEY=yourapikey
pytassium -d nasa

The -a parameter will override the environment variable.

To stop using pytassium use the "exit" command:

>>> exit

Exploring a dataset

pytassium has a number of commands that help with exploring a dataset. First up is "sample" which returns a sample of the subjects from the data:

>>> sample

You'll see that each URI is numbered. You can quickly describe that URI by typing the describe command followed by its number:

>>> describe 1
@prefix rdfs: <> .
@prefix space: <> .

    a <>;
    rdfs:label "Apollo 10 Lunar Module Pilot";
    space:actor <>;
    space:mission <>;
    space:role <> .

The numbers are remembered between each listing of URIs, so describe 2 will still work.

You can also describe by URI:

>>> describe <>
@prefix dc: <> .
@prefix foaf: <> .
@prefix po: <> .

<> a <>;
    dc:title "One Small Step";
    po:short_synopsis "The story of Neil Armstrong and Buzz Aldrin's trip to the moon.";
    foaf:primaryTopic <>,
    foaf:topic <> .

You can get a count of the triples in a store:

>>> count
99448 triples

Or counts of various other types:

>>> count subjects
12357 subjects

>>> count classes
10 classes

>>> count properties
39 properties

You can also count occurrences of a class:

>>> count <>
58 <>

Or you can use the prefixed version (see below for more on prefixes)

>>> count foaf:Person
58 foaf:Person

The "show" command enables you to explore characteristics of the data:

>>> show classes

>>> show properties

>>> show schemas

>>> show topclasses
                    class                     | count
==============================================+======  | 6692      | 5090               | 303 | 142              | 58   

The "show void" command lists all void descriptions in the dataset, or describes it if there is only one:

>>> show void
@prefix dcterm: <> .
@prefix void: <> .

<> a <>;
    dcterm:description """
  Conversion of various NASA datasets into RDF, starting with the spacecraft data from the NSSDC master catalog
    dcterm:source <>,
    dcterm:title "NASA Space Flight & Astronaut data";
    void:exampleResource <>,
    void:sparqlEndpoint <>;
    void:uriRegexPattern "" .

The status and attribution commands provide more information about a dataset:

>>> status
Status: published

>>> attribution
Name: NASA

Loading data

You can load data from a local file with the "store" command:

>>> store yourdata.nt
Uploading 'yourdata.nt'

The store command will automatically chunk ntriples files and load the pieces into the store. Note: this does not take account of blank nodes so don't use store on files over 2MB if they contain blank nodes

A future version will add support for the ingest service.

Querying data

pytassium provides a "sparql" command to run a sparql query. It will attempt to format the results nicely.

>>> sparql select * where {?s a <>} limit 5

The sparql command expands well known prefixes automatically:

>>> sparql select ?title where {?s a space:Mission; dc:title ?title } limit 5
Apollo 10
Apollo 11
Apollo 12
Apollo 17
Apollo 15

You can use "show prefixes" to list the recognised prefixes:

>>> show prefixes
foaf: <>
owl: <>
xsd: <>
bibo: <>

You can add your own prefixes with the "prefix" command:

>>> prefix ex <>

By default, when pytassium starts up it attempts to fetch a list of common prefixes from This file is cached in the system temp directory for future use.


pytassium provides the "search" command for accessing a dataset's search API. All following parameters are assumed to be the search query:

>>> search apollo
0. Apollo 6 (score: 1.0)
1. ASTP-Apollo (score: 0.9938665)
2. Apollo 7 (score: 0.9717672)
3. Apollo 10 (score: 0.9620834)
4. Apollo 8 (score: 0.9620834)

>>> search apollo 13
0. Apollo 13 (score: 1.0)
1. Apollo 13 Lunar Module/ALSEP (score: 0.97858286)
2. Apollo 13 Command and Service Module (CSM) (score: 0.83995086)
3. Apollo 13 SIVB (score: 0.7720434)
4. Soyuz 13 (score: 0.71551764)

>>> search "apollo 13"
0. Apollo 13 (score: 1.0)
1. Apollo 13 Lunar Module/ALSEP (score: 0.9803725)
2. Apollo 13 Command and Service Module (CSM) (score: 0.84758013)
3. Apollo 13 SIVB (score: 0.49793136)
4. Apollo 13 Capsule Communicator (score: 0.41402295)

Reconciling data

pytassium provides a reconcile command which invokes the dataset's reconciliation service.

>>> reconcile apollo
0. (score: 1.0)
1. (score: 0.9938665)
2. (score: 0.9717672)
3. (score: 0.9620834)
4. (score: 0.9620834)

Enclose multi word labels in quotes:

>>> reconcile "apollo 13"
0. (score: 1.0)
1. (score: 0.97858286)
2. (score: 0.83995086)
3. (score: 0.7720434)
4. (score: 0.71551764)

Specify a type:

>>> reconcile apollo space:Mission
0. (score: 1.0)
1. (score: 1.0)
2. (score: 1.0)
3. (score: 1.0)
4. (score: 1.0)

Resetting a dataset

You can schedule a reset job on your dataset:

>>> reset
Scheduling reset job for immediate execution
Reset scheduled, URI is:
Reset has not started yet
Reset is in progress
Reset has completed

Batch scripts

pytassium provides a -f command line options which specifies a filename containing commands to run. When pytassium is invoked with the -f option it reads the commands from the file, runs them and then terminates

./pytassium -f /tmp/myscript

You can save the history from an interactive session with the "save" command:

>>> save history /tmp/newscript

And execute the commands in any script with the "run" command:

>>> run /tmp/newscript

Command line operation

Any parameters supplied on the command line are assumed to a command for pytassium. It runs the command and then terminates:

pytassium -a yourapikey -d nasa show classes

Sparql queries will typically need to be enclosed in quotes:

pytassium -a yourapikey -d nasa sparql "select * where {?s a <>}"

Multi-word reconciliations will need quotes to be doubled or escaped othewise the second word will be treated as the type:

pytassium -a yourapikey -d nasa reconcile "'apollo 13'" space:Mission
0. (score: 1.0)

A common pattern is to reset a dataset and load some fresh data into it:

pytassium -a yourapikey -d yourdataset reset
pytassium -a yourapikey -d yourdataset store yourdata.nt


The following APIs are not yet implemented:

  • Augmentation

Related Projects

If Python's not your thing, you may also be interested in:


Ian Davis,


This work is hereby released into the Public Domain.

To view a copy of the public domain dedication, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Something went wrong with that request. Please try again.