Google Authentication Library for OAuth 2.0

1.3.0 · active · verified Sat Mar 28

A Python library that provides OAuth 2.0 support for the google-auth library, enabling secure authentication for Google APIs. Current version: 1.3.0, released on February 27, 2026. Maintained with regular updates.

Warnings

Install

Imports

Quickstart

A complete example demonstrating OAuth 2.0 authentication and accessing Google Drive API to list files.

import os
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# Set up the OAuth 2.0 flow
flow = InstalledAppFlow.from_client_secrets_file(
    'client_secrets.json',
    scopes=['https://www.googleapis.com/auth/drive.readonly']
)

# Run the flow to get credentials
credentials = flow.run_local_server(port=0)

# Build the service
service = build('drive', 'v3', credentials=credentials)

# Call the Drive API
results = service.files().list(pageSize=10, fields='files(id, name)').execute()
items = results.get('files', [])

if not items:
    print('No files found.')
else:
    print('Files:')
    for item in items:
        print(f'{item['name']} ({item['id']})')

view raw JSON →