Installation

YesGraph’s Python SDK is available through the pip package manager.

$ pip install --upgrade yesgraph

It’s also open source! Check out the source code on [Github](https://github.com/yesgraph/python-yesgraph, or the YesGraph package on PyPI.

Setup

Here’s how to setup the Python SDK using your API key:

from yesgraph import YesGraphAPI
api = YesGraphAPI('YOUR_SECRET_KEY')
print(api.test())
###
{'message': 'You have successfully made an authorized request to the '
            'YesGraph API!',
 'meta': {'app_name': 'test',
          'docs': 'https://www.yesgraph.com/docs/#get-test',
          'env': 'live',
          'help': 'Please contact support@yesgraph.com for any issues.',
          'user_id': None}}

POST /address-book

Assuming that your secret key is still set from the example above, here’s how you would make a POST call to rank some contacts:

# Build the list of address book entries
entries = [
  {"name": "Ivan Kirigin", "email": "ivan@yesgraph.com"},
  {"name": "Vincent Driessen", "email": "vincent@yesgraph.com"},
  {"name": "George Hickman", "email": "george@yesgraph.com"}
]

# Hit the API!
response = api.post_address_book(user_id=1234,
                                 entries=entries,
                                 source_name='Jonathan Chu',
                                 source_email='jonathan@yesgraph.com',
                                 source_type='gmail')
print(response)
{'batch_id': '3d958e33-9734-4095-8bfc-e95f13db86a5',
 'message': 'Address book for 1234 added.'}

POST /invites-sent

Here’s how you would make a POST call to track invites sent. Let’s say you sent an invite to “john@smith.com” and would like to track that data with YesGraph:

# Build the list of invite entries
entries = [
    {
        "user_id": 1234, # The inviter's user ID
        "email": "john@smith.com", # The recipient's email
        "sent_at": "1970-01-01T00:00:00+00:00"  # When the invite was sent
    }
]
response = api.post_invites_sent(entries)
print(response)
{'meta': {'time': 0.10435795783996582},
 'message': 'Invite sent added.'}

POST /invites-accepted

And finally, when John Smith (from the above example) accepts your invite, here’s how you can track that data:

# Build the list of invite entries
entries = [
    {
        "user_id": "43eb4524", # John's new user ID!
        "email": "john@smith.com",
        "accepted_at": "1970-02-01T00:00:00+00:00"
    },
]
response = api.post_invites_accepted(entries)
print(response)
{'meta': {'time': 0.02321600914001465},
 'message': 'Invite accepted added.'}