Skip to main content

Reusable bridge between Python apps and Google Workspace APIs (Drive, Contacts, and more)

Project description

selander_bridge

PyPI version GitHub Repo

A small, reusable Python library that bridges your apps to Google accounts and Google Workspace services (Drive, Contacts, more to come) - built once, imported everywhere, with no server you have to host for auth.

Why this exists

The standard "web app" OAuth flow needs a permanently running, publicly reachable URL to catch Google's redirect. That's the "too much hosting" problem. selander_bridge defaults to Google's installed-app / loopback flow instead: a browser opens, you log in, Google redirects to a local port that only exists for a few seconds, and the resulting refresh token is cached to disk. Every app that imports this library and reuses the same account key skips the login screen after the first time.

If every account you need belongs to a Workspace domain you administer, you can skip browser login entirely with ServiceAccountAuthManager (domain-wide delegation) — zero hosting, zero interaction.

Install

pip install selander-bridge

One-time Google Cloud setup

Before running your code, you must configure a Google Cloud project to get your client_secret.json and enable the APIs you plan to use. If you skip enabling the APIs, your code will crash.

Please follow our detailed step-by-step guide: 👉 Google Cloud Setup Guide

Usage

from selander_bridge import (
    ContactsClient,
    DriveClient,
    GoogleAuthManager,
    SCOPE_CONTACTS,
)

auth = GoogleAuthManager(
    client_secrets_file="client_secret.json",
    scopes=[*ContactsClient.scopes, *DriveClient.scopes, SCOPE_CONTACTS],
)

# First call opens a browser once; after that, the cached token is reused.
contacts = ContactsClient(auth, account="me@gmail.com")
for person in contacts.list_contacts():
    print(person.get("names"))

created = contacts.create_contact(
    given_name="Ada",
    family_name="Lovelace",
    email="ada@example.com",
)

contacts.update_contact(
    created["resourceName"],
    body={"names": [{"givenName": "Ada", "familyName": "Byron"}]},
    update_person_fields="names",
)

contacts.delete_contact(created["resourceName"])

drive = DriveClient(auth, account="me@gmail.com")
drive.upload_file("report.pdf", name="Q2 Report.pdf")

Use a different account string per Google account you need to talk to — each gets its own cached token under ~/.selander_bridge/tokens/.

Extending to more Workspace APIs

Every wrapper follows the same shape. To add Calendar, Sheets, Gmail, etc., copy drive.py as a template:

from .base import BaseService, wrap_http_errors

class CalendarClient(BaseService):
    api_name = "calendar"
    api_version = "v3"
    scopes = ("https://www.googleapis.com/auth/calendar.readonly",)

    @wrap_http_errors
    def list_events(self, calendar_id="primary", max_results=50):
        resp = self.service.events().list(
            calendarId=calendar_id, maxResults=max_results
        ).execute()
        return resp.get("items", [])

Then export it from selander_bridge/__init__.py.

Project layout

selander_bridge/
├── pyproject.toml
├── README.md
├── src/selander_bridge/
│   ├── __init__.py     # public exports
│   ├── auth.py         # GoogleAuthManager, ServiceAccountAuthManager, TokenStore
│   ├── base.py         # BaseService (shared plumbing), wrap_http_errors
│   ├── contacts.py     # ContactsClient (People API)
│   ├── drive.py        # DriveClient
│   └── exceptions.py
└── tests/
    └── test_imports.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selander_bridge-0.1.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

selander_bridge-0.1.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file selander_bridge-0.1.1.tar.gz.

File metadata

  • Download URL: selander_bridge-0.1.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for selander_bridge-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b9ae636ffbbf669e231c7c31c8b4732958a38910fd4b5034220e1693d35a5802
MD5 81be5a216c211024dc28db5acbc6128a
BLAKE2b-256 6cbb0f3341757ae811a309b5e935d46d7287b0235d4bf6777b433b00e115f75d

See more details on using hashes here.

File details

Details for the file selander_bridge-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for selander_bridge-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ebd77c4c0175bdb2e2b02c6b754163617da228d070bc87f4e6c38c38ac024881
MD5 5e134bb61dc79c6e3373b31c450ea4ce
BLAKE2b-256 4eb66ef5d83399f8119b26a300c675ab4e8ac8e10cac78064754ef8745c95b9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page