This post describes the exact steps I took to get started with FluidDB. It describes how to
- Get a login and password
- Get the libraries to allow you to use it from python 2.5
- Get the FluidDB object ID corresponding to a FluidDB username
- Create a new object in FluidDB
- Retrieve that object
What I had to do¶
Get a username and password. I got my username as a consequence of following @fluiddb on twitter, and the password was sent to me this morning. If you haven’t already reserved a username this way, you can reserve one instead by signing up at http://fluidinfo.com/accounts/new.
I started using the very simple but useful python library fluiddb put together by Sanghyeon Seo and augmented by Nicholas Tollervey, who gives some nice examples of its use on his blog. (I found bitbucket a bit confusing, but you can get the actual source from, gzipped, from http://bitbucket.org/sanxiyn/fluidfs/get/054092b8d3ff.gz or as a zip or bz2 by changing the extension.)
I found that I needed install a couple of libraries to use with Python 2.5. These were httplib2, available from http://code.google.com/p/httplib2/ and simplejson, available from http://pypi.python.org/pypi/simplejson/ I then tried tollervey’s examples, which all worked fine, without any credentials for FluidDB. So far so good.
Then I used the following trivial code to get the ID for the object corresponding to me (njr).
import fluiddb njrID = fluiddb.call('GET', '/objects', query='fluiddb/users/username = "njr"') print njrID
which produced
$ python getnjr.py (200, {'ids': ['cde01b2c-68bb-4d41-b25c-3ca49dcec434']})
I then wanted to try creating an object, which does require credentials. For this, I created the following trivial credentials class (credentials.py):
class Credentials: def __init__ (self, username, password, id=None): self.username = username self.password = password self.id = id njr = Credentials ('njr', 'my-secret-password', 'cde01b2c-68bb-4d41-b25c-3ca49dcec434')
(Obviously, that isn’t the real password...)
That having worked, it seemed like it was time to create an object and test that I could retrieve it, which I did with the following code (createDADGAD.py):
import fluiddb, credentials import simplejson as json njr=credentials.njr fluiddb.login (njr.username, njr.password) about_DADGAD = json.dumps ({'about' : 'DADGAD'}) (status, o) = fluiddb.call ('POST', '/objects', about_DADGAD) print status, o print fluiddb.call ('GET', '/objects/' + o['id'], '{"showAbout": true}')
which produced
$ python createDADGAD.py 201 {'id': 'a984efb2-67d8-4b5c-86d0-267b87832fa4', 'URI': 'http://fluidDB.fluidinfo.com/objects/a984efb2-67d8-4b5c-86d0-267b87832fa4'} (200, {'about': 'DADGAD', 'tagPaths': ['fluiddb/about']})
No comments:
Post a Comment