Using Two Factor Authentication with github3.pyΒΆ

GitHub recently added support for Two Factor Authentication to and shortly thereafter added support for it on In version 0.8, also added support for it and you can use it right now.

To use Two Factor Authentication, you must define your own function that will return your one time authentication code. You then provide that function when logging in with

For example:

import github3

    # Python 2
    prompt = raw_input
except NameError:
    # Python 3
    prompt = input

def my_two_factor_function():
    code = ''
    while not code:
        # The user could accidentally press Enter before being ready,
        # let's protect them from doing that.
        code = prompt('Enter 2FA code: ')
    return code

g = github3.login('sigmavirus24', 'my_password',

Then each time the API tells it requires a Two Factor Authentication code, will call my_two_factor_function which prompt you for it.