Simperium Python


Auth

init

Initializes a client creating and authenticating users:

>>> from simperium.core import Auth
>>> auth = Auth('appid', 'apikey')

create

Creates a new user and returns an auth token.

>>> token = auth.create('email@address.com', 'password')
>>> token
'25c11ad089dd4c18b84f24bc18c58fe2'

authorize

Authorizes an existing user and returns an auth token.

>>> token = auth.authorize('email@address.com', 'password')
>>> token
'25c11ad089dd4c18b84f24bc18c58fe2'

Api

init

Initializes a client for interacting with the Simperium syncing api:

>>> from simperium.core import Api
>>> api = Api('appid', 'access_token')

getattr/getitem

Returns an instance of a Simperium bucket:

>>> api.todo
>>> api['todo']

Bucket

new

Create a new item in the bucket. Returns the id of the new item.

>>> api.todo.new({'title': 'Create a startup to kill email', 'done': False})
'e87881c38a9544eb83d942af928002a5'

set

Set values in an existing item. This merges the keys you are setting with keys that have been currently set:

>>> api.todo.set(_id, {'done': True})

get

Get the value of an existing item:

>>> api.todo.get(_id)
{'title': 'Create a startup to kill email', 'done': True}

delete

Remove an existing item:

>>> api.todo.delete(_id)

index

Retreives a page of the items in this bucket, which have been most recently modified.

data — if true, the current data for each item is returned in the result

mark — set the start of the page of items to be returned to this mark

limit — number of items to return. default is 100. max is 1000.

since — limit the page of items to be returned to those modified since the given mark

>>> api.todo.index(data=False, mark=None, limit=None, since=None)

Returns:

{
    'current':  # head cv of the most recently modified document,
    'mark':     # cv to use to pull the next page of documents. only
                # included in the repsonse if there are remaining pages
                # to fetch.

    'index': [{
        'id':  # id of the document,
        'v':   # current version of the document,
        'd':   # optionally current data of the document, if
               # data is requested
        }, {....}],
    }

changes

Polls Simperium for changes being made for the currently authed user on this bucket.

cv — listen for changes after this cv.

timeout — how long to wait for a new change to be available before returning. By default the changes call will wait forever.

>>> api.todo.changes(cv=None, timeout=None)

all

Polls Simperium for changes all being made on this bucket, regardless of the user who made the change. This call requires an API key with admin privileges when initializing the Api

cv — listen for changes after this cv.

data — if True, also include the latest version of the data for the changed document

username — if True, the username for the user who created the change will also be included

most_recent — if True, then if a document has been modified several times since the last all call, only the most recent change for that document will be returned.

timeout — how long to wait for a new change to be available before returning. By default the all call will wait forever.

>>> api.todo.all(cv=None, data=False, username=False, most_recent=False, timeout=None)