Skip to main content

ohawf

Install

pip install -U ohawf

Are you trying to log into Google Analytics, Search Console, or even Google Photos from a Jupyter Notebook? Does all the advice telling you to register as a developer and the mangled Google examples have you frustrated? Well then, ohawf is for you.

How to use

import ohawf

creds = ohawf.get()

Why So Easy?

Google OAuth2 woes go away once you can use the authentication scheme that pops up the same “login as Google” web-prompt that all Mobile and Web apps seem to be using these days. It doesn’t seem possible, but this authentication scheme actually works from a Jupyter Notebook in JupyterLab.

Ohawf makes JupyterLab behave like an installed app, so that when you first run creds= ohawf.get(), you’ll be presented with the “Login with Google” prompt. Just just wait a moment, it will pop up a window separate from JupyterLab’s own, and let you log in then prompt you to close the window. If not, Drink Me.

A Tale of 2 Installed App Flows

What makes ohawf work is this line:

from google_auth_oauthlib.flow import InstalledAppFlow

The Old Way: Copy/Paste Token

InstalledAppFlow’s run_console() prompts you to copy/paste a token from a browser tab to Jupyter and used to work well, but that approach has been deprecated. It can still be forced to work, but it’s not so easy.

The New Way: Gotta Have a Webserver

The new way which is now the ohawf default is run_local_server(). This is what you encounter all the time with mobile apps when you see “Login with Google”. An embedded browser pops up, goes through login, then returns you to the mobile app. This works in Jupyter too. If you have problems, run Jupyter this way. And if you need to force ohawf to use run_console() for a server installation, you can do this:

import ohawf
creds = ohawf.get(cli=True)

But then you’ll have to whitelist your email address, and you can only do that through the Google Cloud Console so chicken-and-egg. If you have to go that route, consider just registering as a Google developer and downloading a OAuth Client secret json file like this:

  • Go to https://console.cloud.google.com
  • Make sure you’re in the correct Google account.
  • Create a new Project.
  • Go to API & Services.
  • Enable the APIs & Services you want to use.
  • Go to Credentials.
  • Create a new OAuth 2.0 Client IDs of the Desktop App type.
  • Go to OAuth consent screen and set it up.
  • Go to +Add users, under test users (gets around tight security)
  • Add the users for the test (your gmail, necessary even though already the app owner)
  • Go back to Credentials and download OAuth Client.
    • Typically, client_secret_[secret].apps.googleusercontent.com.json
  • Use that file with ohawf

Once you have the Client Secret JSON file, you can call ohawf like this:

import ohawf

creds = ohawf.get(file="client_secret.json")

Adding Scopes

The ohawf package uses the following default scopes if you don’t set any:

https://www.googleapis.com/auth/spreadsheets
https://www.googleapis.com/auth/gmail.modify
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/youtube.readonly
https://www.googleapis.com/auth/analytics.readonly
https://www.googleapis.com/auth/webmasters.readonly
https://www.googleapis.com/auth/yt-analytics.readonly
https://www.googleapis.com/auth/photoslibrary.readonly

If you want to set your own scopes, create a Python list of scopes and feed it to ohawf:

scopes = ["https://www.googleapis.com/auth/spreadsheets"]
creds = ohawf(scopes=scopes)

Google Services

from apiclient.discovery import build

Connect to Google services by giving build any (activated) API name, version and credentials such listing your GSC sites:

gsc_service = build('searchconsole', 'v1', credentials=cred)
gsc_sites = gsc_service.sites().list().execute()
[print(x['siteUrl']) for x in gsc_sites['siteEntry']];

…or this go list your GA accounts:

ga_service = build('analytics', 'v3', credentials=cred)
ga_accounts = ga_service.management().accounts().list().execute()
[print((x['id'], x['name'])) for x in ga_accounts['items']];

Copyright (c) 2023 Mike Levin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Privacy Policy

Last updated: December 31, 2022

This app does not collect nor use any of Your Personal data.

Metadata

Release files for ohawf 23.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ohawf 23.0.10
File Size Uploaded Provenance Actions
ohawf-23.0.10.tar.gz 11.2 kB Without provenance Details for ohawf-23.0.10.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ohawf 23.0.10
File Interpreter ABI Platform Actions
ohawf-23.0.10-py3-none-any.whl Python 3 none any Details for ohawf-23.0.10-py3-none-any.whl

Total release size: 22.1 kB

Release files / ohawf-23.0.10.tar.gz

Download URL ohawf-23.0.10.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0657f721246f8963efe780d903008c8a2d849b2e1c0841d1ba305193e770f2b6
BLAKE2b-256 checksum
How to use checksums
f0c736df5283257ba259e52d285ab4b66b6199227b49af56ca2b3583cb690455
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / ohawf-23.0.10-py3-none-any.whl

Download URL ohawf-23.0.10-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
78d7113c51c2391205309e40b3445835d90cece0e118f10d6c083b8771c877eb
BLAKE2b-256 checksum
How to use checksums
aa6ba84dfa962d5c39369930e197e5af3615a0d81c23794fde89d47f71afb8da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Security for ohawf 23.0.10

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

23.0.10 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page