Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
riak/*.pyc
riak/tests/*.pyc
riak/transports/*.pyc
*.pyc

docs/_build

Expand Down
86 changes: 43 additions & 43 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Python Client for Riak
Documentation
==============

`Documentation for the Riak Python Client Library <http://basho.github.com/riak-python-client/index.html>`_ is available here.
The documentation source is found in `docs/ subdirectory
<https://github.com/basho/riak-python-client/tree/master/docs>`_ and can be
`Documentation for the Riak Python Client Library <http://basho.github.com/riak-python-client/index.html>`_ is available here.
The documentation source is found in `docs/ subdirectory
<https://github.com/basho/riak-python-client/tree/master/docs>`_ and can be
built with `Sphinx <http://sphinx.pocoo.org/>`_.

Documentation for Riak is available at http://wiki.basho.com/display/RIAK/Riak
Documentation for Riak is available at http://wiki.basho.com/How-Things-Work.html

Install
=======
Expand All @@ -35,7 +35,7 @@ This tutorial assumes basic working knowledge of how Riak works & what it can
do. If you need a more comprehensive overview how to use Riak, please check out
the `Riak Fast Track`_.

.. _`Riak Fast Track`: http://wiki.basho.com/display/RIAK/The+Riak+Fast+Track
.. _`Riak Fast Track`: http://wiki.basho.com/The-Riak-Fast-Track.html


Quick Start
Expand All @@ -45,14 +45,14 @@ For the impatient, simple usage of the official Python binding for Riak looks
like::

import riak

# Connect to Riak.
client = riak.RiakClient()

# Choose the bucket to store data in.
bucket = client.bucket('test')


# Supply a key to store data under.
# The ``data`` can be any data Python's ``json`` encoder can handle.
person = bucket.new('riak_developer_1', data={
Expand Down Expand Up @@ -85,7 +85,7 @@ To use the HTTP interface and connecting to a local Riak on the default port,
no arguments are needed::

import riak

client = riak.RiakClient()

The constructor also configuration options such as ``host``, ``port`` &
Expand All @@ -94,7 +94,7 @@ The constructor also configuration options such as ``host``, ``port`` &
To use the Protocol Buffers interface::

import riak

client = riak.RiakClient(port=8087, transport_class=riak.RiakPbcTransport)

.. warning:
Expand Down Expand Up @@ -231,44 +231,44 @@ in either the JSON-decoded form or a binary blob. Getting the JSON-decoded
data out looks like::

import riak

client = riak.RiakClient()
user_bucket = client.bucket('user')

johndoe = user_bucket.get('johndoe')

# You've now got a ``RiakObject``. To get at the values in a dictionary
# form, call:
johndoe_dict = johndoe.get_data()

Getting binary data out looks like::

import riak

client = riak.RiakClient()
user_photo_bucket = client.bucket('user_photo')

johndoe = user_photo_bucket.get_binary('johndoe')

# You've now got a ``RiakObject``. To get at the binary data, call:
johndoe_headshot = johndoe.get_data()

Manually fetching data is also possible::

import riak

client = riak.RiakClient()
status_bucket = client.bucket('status')

# We're using the UUID generated from the above section.
first_post_status = riak.RiakObject(client, status_bucket, post_uuid)
first_post_status._encode_data = True
r = status_bucket.get_r()

# Calling ``reload`` will cause the ``RiakObject`` instance to load fresh
# data/metadata from Riak.
first_post_status.reload(r)

# Finally, pull out the data.
message = first_post_status.get_data()['message']

Expand All @@ -281,23 +281,23 @@ disposal is MapReduce_. This technique iterates over all of the data, returning
data from the map phase & combining all the different maps in the reduce
phase(s).

.. _MapReduce: http://wiki.basho.com/display/RIAK/MapReduce
.. _MapReduce: http://wiki.basho.com/MapReduce.html

To perform a map operation, such as returning all active users, you can do
something like::

import riak

client = riak.RiakClient()
# First, you need to ``add`` the bucket you want to MapReduce on.
query = client.add('user')
# Then, you supply a Javascript map function as the code to be executed.
query.map("function(v) { var data = JSON.parse(v.values[0].data); if(data.is_active == true) { return [[v.key, data]]; } return []; }")

for result in query.run():
# Print the key (``v.key``) and the value for that key (``data``).
print "%s - %s" % (result[0], result[1])

# Results in something like:
#
# mr_smith - {'first_name': 'Mister', 'last_name': 'Smith', 'is_active': True}
Expand All @@ -307,27 +307,27 @@ something like::
You can also do this manually::

import riak

client = riak.RiakClient()
query = riak.RiakMapReduce(client).add('user')
query.map("function(v) { var data = JSON.parse(v.values[0].data); if(data.is_active == true) { return [[v.key, data]]; } return []; }")

for result in query.run():
print "%s - %s" % (result[0], result[1])

Adding a reduce phase, say to sort by username (key), looks almost identical::

import riak

client = riak.RiakClient()
query = client.add('user')
query.map("function(v) { var data = JSON.parse(v.values[0].data); if(data.is_active == true) { return [[v.key, data]]; } return []; }")
query.reduce("function(values) { return values.sort(); }")

for result in query.run():
# Print the key (``v.key``) and the value for that key (``data``).
print "%s - %s" % (result[0], result[1])

# Results in something like:
#
# annabody - {'first_name': 'Anna', 'last_name': 'Body', 'is_active': True}
Expand All @@ -341,20 +341,20 @@ Working With Related Data Via Links
Links_ are powerful concept in Riak that allow, within the key/value pair's
metadata, relations between objects.

.. _Links: http://wiki.basho.com/display/RIAK/Links
.. _Links: http://wiki.basho.com/Links.html

Adding them to your data is relatively trivial. For instance, we'll link a
user's statuses to their user data::

import riak
import uuid

client = riak.RiakClient()
user_bucket = client.bucket('user')
status_bucket = client.bucket('status')

johndoe = user_bucket.get('johndoe')

new_status = status_bucket.new(uuid.uuid1().hex, data={
'message': 'First post!',
'created': time.time(),
Expand All @@ -363,20 +363,20 @@ user's statuses to their user data::
# Add one direction (from status to user)...
new_status.add_link(johndoe)
new_status.store()

# ... Then add the other direction.
johndoe.add_link(new_status)
johndoe.store()

Fetching the data is equally simple::

import riak

client = riak.RiakClient()
user_bucket = client.bucket('user')

johndoe = user_bucket.get('johndoe')

for status_link in johndoe.get_links():
# Since what we get back are lightweight ``RiakLink`` objects, we need to
# get the associated ``RiakObject`` to access its data.
Expand All @@ -394,23 +394,23 @@ a Solr-like interface into Riak. The setup of this is outside the realm of this
tutorial, but usage of this feature looks like::

import riak

client = riak.RiakClient()

# First parameter is the bucket we want to search within, the second
# is the query we want to perform.
search_query = client.search('user', 'first_name:[Anna TO John]')

for result in search_query.run():
# You get ``RiakLink`` objects back.
user = result.get()
user_data = user.get_data()
print "%s %s" % (user_data['first_name'], user_data['last_name'])

# Results in something like:
#
# John Doe
# Anna Body

.. _`Riak Search`: http://wiki.basho.com/display/RIAK/Riak+Search
.. _`Riak Search`: http://wiki.basho.com/Riak-Search.html
.. _Lucene: http://lucene.apache.org/
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Contents:

.. toctree::
:maxdepth: 2

tutorial

client
bucket
riak_object
Expand Down
Loading