Skip to content
Open
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
6 changes: 5 additions & 1 deletion docs/tutorial/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ Start here to begin working with `graphspace-python`.
Connecting to GraphSpace
------------------------

You can connect to GraphSpace using your username and password.
You can connect to GraphSpace using your username and password,

>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')

or using your username and authentication key.
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', auth_token='Basic dXNlcjFAZXhhbXBsZS5jb206dXNlcjE=')

You can also set the api host using the :meth:`~graphspace_python.api.client.GraphSpace.set_api_host`
method if you are using a different server.

Expand Down
14 changes: 13 additions & 1 deletion graphspace_python/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@ class GraphSpace(object):
Groups
]

def __init__(self, username, password):
def __init__(self, username=None, password=None, auth_token=None):
"""Construct a new 'GraphSpace' client object.

Args:
username (str): Email of the user.
password (str): Password of the user.
auth_token (str): Basic authorization value

User can connect to GraphSpace using username and password or username and auth_token.
Example:
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', 'user1')
OR
>>> from graphspace_python.api.client import GraphSpace
>>> graphspace = GraphSpace('user1@example.com', auth_token='Basic dXNlcjFAZXhhbXBsZS5jb206dXNlcjE=')
"""
# self.auth_token = 'Basic %s' % base64.b64encode('{0}:{1}'.format(username, password))
if auth_token is not None:
userpass = base64.b64decode(auth_token[len('Basic')+1:]) #'username:password'
password = userpass[len(username)+1:]
self.auth_token = requests.auth.HTTPBasicAuth(username, password)
self.username = username
self.api_host = API_HOST
Expand Down