ohawf
================
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
## Install
``` sh
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
<a href="https://console.cloud.google.com/">developer</a> and the
mangled [Google
examples](https://developers.google.com/webmaster-tools/search-console-api-original/v3/quickstart/quickstart-python)
have you frustrated? Well then, ***ohawf*** is for you.
## How to use
``` python
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, <a href="https://mikelev.in/ux">Drink Me</a>.
### A Tale of 2 Installed App Flows
What makes ohawf work is this line:
``` python
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 <a href="https://mikelev.in/ux/">this
way</a>. And if you need to force ohawf to use run_console() for a
server installation, you can do this:
``` python
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](https://console.cloud.google.com/) 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:
``` python
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:
``` python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/miklevin/ohawf",
"name": "ohawf",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "nbdev jupyter notebook python",
"author": "Mike Levin",
"author_email": "miklevin@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f0/c7/36df5283257ba259e52d285ab4b66b6199227b49af56ca2b3583cb690455/ohawf-23.0.10.tar.gz",
"platform": null,
"description": "ohawf\n================\n\n<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->\n\n## Install\n\n``` sh\npip install -U ohawf\n```\n\nAre you trying to log into Google Analytics, Search Console, or even\nGoogle Photos from a Jupyter Notebook? Does all the advice telling you\nto register as a\n<a href=\"https://console.cloud.google.com/\">developer</a> and the\nmangled [Google\nexamples](https://developers.google.com/webmaster-tools/search-console-api-original/v3/quickstart/quickstart-python)\nhave you frustrated? Well then, ***ohawf*** is for you.\n\n## How to use\n\n``` python\nimport ohawf\n\ncreds = ohawf.get()\n```\n\n### Why So Easy?\n\nGoogle OAuth2 woes go away once you can use the authentication scheme\nthat pops up the same **\u201clogin as Google\u201d** web-prompt that all Mobile\nand Web apps seem to be using these days. It doesn\u2019t seem possible, but\nthis authentication scheme actually works from a Jupyter Notebook in\nJupyterLab.\n\nOhawf makes JupyterLab behave like an installed app, so that when you\nfirst run **creds= ohawf.get()**, you\u2019ll be presented with the \u201cLogin\nwith Google\u201d prompt. Just just wait a moment, it will pop up a window\nseparate from JupyterLab\u2019s own, and let you log in then prompt you to\nclose the window. If not, <a href=\"https://mikelev.in/ux\">Drink Me</a>.\n\n### A Tale of 2 Installed App Flows\n\nWhat makes ohawf work is this line:\n\n``` python\nfrom google_auth_oauthlib.flow import InstalledAppFlow\n```\n\n#### The Old Way: Copy/Paste Token\n\nInstalledAppFlow\u2019s ***run_console()*** prompts you to copy/paste a token\nfrom a browser tab to Jupyter and used to work well, but that approach\nhas been deprecated. It can still be forced to work, but it\u2019s not so\neasy.\n\n#### The New Way: Gotta Have a Webserver\n\nThe new way which is now the ohawf default is ***run_local_server()***.\nThis is what you encounter all the time with mobile apps when you see\n\u201cLogin with Google\u201d. An embedded browser pops up, goes through login,\nthen returns you to the mobile app. This works in Jupyter too. If you\nhave problems, run Jupyter <a href=\"https://mikelev.in/ux/\">this\nway</a>. And if you need to force ohawf to use run_console() for a\nserver installation, you can do this:\n\n``` python\nimport ohawf\ncreds = ohawf.get(cli=True)\n```\n\nBut then you\u2019ll have to whitelist your email address, and you can only\ndo that through the [Google Cloud\nConsole](https://console.cloud.google.com/) so chicken-and-egg. If you\nhave to go that route, consider just registering as a Google developer\nand downloading a OAuth Client secret json file like this:\n\n- Go to <https://console.cloud.google.com>\n- Make sure you\u2019re in the correct Google account.\n- Create a new Project.\n- Go to API & Services.\n- Enable the APIs & Services you want to use.\n- Go to Credentials.\n- Create a new OAuth 2.0 Client IDs of the Desktop App type.\n- Go to OAuth consent screen and set it up.\n- Go to +Add users, under test users (gets around tight security)\n- Add the users for the test (your gmail, necessary even though already\n the app owner)\n- Go back to Credentials and download OAuth Client.\n - Typically,\n ***client_secret\\_\\[secret\\].apps.googleusercontent.com.json***\n- Use that file with ohawf\n\nOnce you have the Client Secret JSON file, you can call ohawf like this:\n\n``` python\nimport ohawf\n\ncreds = ohawf.get(file=\"client_secret.json\")\n```\n\n### Adding Scopes\n\nThe ohawf package uses the following default scopes if you don\u2019t set\nany:\n\n https://www.googleapis.com/auth/spreadsheets\n https://www.googleapis.com/auth/gmail.modify\n https://www.googleapis.com/auth/userinfo.email\n https://www.googleapis.com/auth/youtube.readonly\n https://www.googleapis.com/auth/analytics.readonly\n https://www.googleapis.com/auth/webmasters.readonly\n https://www.googleapis.com/auth/yt-analytics.readonly\n https://www.googleapis.com/auth/photoslibrary.readonly\n\nIf you want to set your own scopes, create a Python list of scopes and\nfeed it to ohawf:\n\n``` python\nscopes = [\"https://www.googleapis.com/auth/spreadsheets\"]\ncreds = ohawf(scopes=scopes)\n```\n\n## Google Services\n\n from apiclient.discovery import build\n\nConnect to Google services by giving ***build*** any (activated) API\nname, version and credentials such listing your GSC sites:\n\n gsc_service = build('searchconsole', 'v1', credentials=cred)\n gsc_sites = gsc_service.sites().list().execute()\n [print(x['siteUrl']) for x in gsc_sites['siteEntry']];\n\n\u2026or this go list your GA accounts:\n\n ga_service = build('analytics', 'v3', credentials=cred)\n ga_accounts = ga_service.management().accounts().list().execute()\n [print((x['id'], x['name'])) for x in ga_accounts['items']];\n\n## Copyright (c) 2023 Mike Levin\n\nPermission is hereby granted, free of charge, to any person obtaining a\ncopy of this software and associated documentation files (the\n\u201cSoftware\u201d), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS\nOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n# Privacy Policy\n\n## Last updated: December 31, 2022\n\nThis app does not collect nor use any of Your Personal data.\n",
"bugtrack_url": null,
"license": "Apache Software License 2.0",
"summary": "Easy Google login from Jupyter Notebooks",
"version": "23.0.10",
"split_keywords": [
"nbdev",
"jupyter",
"notebook",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "aa6ba84dfa962d5c39369930e197e5af3615a0d81c23794fde89d47f71afb8da",
"md5": "8f2a4eb3a150d9d7632b5a833eb60c94",
"sha256": "78d7113c51c2391205309e40b3445835d90cece0e118f10d6c083b8771c877eb"
},
"downloads": -1,
"filename": "ohawf-23.0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8f2a4eb3a150d9d7632b5a833eb60c94",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 10821,
"upload_time": "2023-01-31T14:41:50",
"upload_time_iso_8601": "2023-01-31T14:41:50.839670Z",
"url": "https://files.pythonhosted.org/packages/aa/6b/a84dfa962d5c39369930e197e5af3615a0d81c23794fde89d47f71afb8da/ohawf-23.0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f0c736df5283257ba259e52d285ab4b66b6199227b49af56ca2b3583cb690455",
"md5": "25b7ef7c8faff0a4c4f7001dd1b27ae3",
"sha256": "0657f721246f8963efe780d903008c8a2d849b2e1c0841d1ba305193e770f2b6"
},
"downloads": -1,
"filename": "ohawf-23.0.10.tar.gz",
"has_sig": false,
"md5_digest": "25b7ef7c8faff0a4c4f7001dd1b27ae3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11232,
"upload_time": "2023-01-31T14:41:52",
"upload_time_iso_8601": "2023-01-31T14:41:52.818815Z",
"url": "https://files.pythonhosted.org/packages/f0/c7/36df5283257ba259e52d285ab4b66b6199227b49af56ca2b3583cb690455/ohawf-23.0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-31 14:41:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "miklevin",
"github_project": "ohawf",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ohawf"
}