Skip to main content

A simplified Python interface for Google APIs

Project description

EasyGoogleAPI

PyPI version Python versions License: MIT

A simplified Python interface for Google APIs. One class, seven services, typed responses, zero boilerplate.

Python 3.12+ required.

Quick Start

pip install easygoogleapi
from easygoogleapi import GoogleService

google = GoogleService(
    credentials_path="credentials.json",
    services=["calendar", "drive", "gmail"],
)

# Typed models with IDE autocompletion
for event in google.calendar.list_events():
    print(event.summary, event.start)

# Auto-paginating iteration
for file in google.drive.list_files():
    print(file.name, file.mime_type)

# Simple email sending
google.gmail.send(to="user@example.com", subject="Hello", body="World")

Features

  • Typed response modelsfile.name, not file["name"]. Full IDE autocompletion.
  • Auto-paginationfor file in drive.list_files() iterates across all pages automatically.
  • Async supportAsyncGoogleService for FastAPI and async frameworks.
  • PKCE-secured OAuth — RFC 7636 enabled by default on all flows.
  • Scope presetsscope_preset="readonly" for minimal permissions.
  • Middleware hooks — before/after request hooks with correlation IDs and timing.
  • 7 services — Calendar, Drive, Gmail, Sheets, Docs, Forms, Meet.
  • Automatic retries — Exponential backoff with jitter for transient errors.
  • Multi-user token storage — Pluggable TokenStore interface with JSON file, in-memory, Django, and Redis backends.

Typed Models

All service methods return typed dataclass models:

file = google.drive.get_file("file_id")
print(file.name)           # str
print(file.mime_type)       # str
print(file.web_view_link)  # str | None
print(file.to_dict())      # dict for serialization

Auto-Pagination

List methods return PageIterator — just iterate:

# Automatically fetches all pages
all_files = list(google.drive.list_files(query="mimeType='application/pdf'"))

# Or iterate lazily
for msg in google.gmail.list_messages(query="is:unread"):
    print(msg.id, msg.snippet)

# Single-page manual control when needed
page = google.drive.list_files_page(page_size=10)
print(page.files, page.next_page_token)

Async Support

from easygoogleapi import AsyncGoogleService

async with AsyncGoogleService(
    credentials_path="credentials.json",
    services=["drive"],
) as google:
    page = await google.drive.list_files_page()
    for file in page.files:
        print(file.name)

Scope Presets

# Read-only access — safer for read-only apps
google = GoogleService(
    credentials_path="credentials.json",
    services=["drive", "gmail"],
    scope_preset="readonly",
)

Middleware

from easygoogleapi import GoogleService, MiddlewareChain

middleware = MiddlewareChain()

@middleware.before_request
def log_request(ctx):
    print(f"[{ctx.correlation_id[:8]}] {ctx.service_name}.{ctx.method_name}")

@middleware.after_request
def log_response(ctx):
    print(f"[{ctx.request.correlation_id[:8]}] {ctx.duration_ms:.0f}ms")

google = GoogleService(
    credentials_path="credentials.json",
    services=["drive"],
    middleware=middleware,
)

Multi-User OAuth

from easygoogleapi import GoogleService, FileTokenStore

store = FileTokenStore(Path("./tokens"))

google = GoogleService.for_user(
    user_id="user_123",
    token_store=store,
    credentials_path="oauth_client.json",
    services=["calendar", "gmail"],
)

Service Account

google = GoogleService.for_service_account(
    credentials_path="service_account.json",
    services=["drive"],
    impersonate_user="user@domain.com",
)

Escape Hatch

Every service exposes .raw for direct access to the underlying Google API resource:

# When you need something not wrapped by EasyGoogleAPI
raw_result = google.drive.raw.files().list(q="trashed=true").execute()

License

MIT

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

easygoogleapi-2.0.0.tar.gz (40.4 kB view details)

Uploaded Source

Built Distribution

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

easygoogleapi-2.0.0-py3-none-any.whl (54.8 kB view details)

Uploaded Python 3

File details

Details for the file easygoogleapi-2.0.0.tar.gz.

File metadata

  • Download URL: easygoogleapi-2.0.0.tar.gz
  • Upload date:
  • Size: 40.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for easygoogleapi-2.0.0.tar.gz
Algorithm Hash digest
SHA256 410f89425762796478e311ccceacc9baeaab7ae1d2423ec501469931524206a2
MD5 98eebf0e3414b5d2f7800c44bbd82433
BLAKE2b-256 c704272cfd3be8316af55017fd0577afeb16ea524520cd30450a331f84600846

See more details on using hashes here.

File details

Details for the file easygoogleapi-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: easygoogleapi-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 54.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for easygoogleapi-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 218981be92954c28d217c104170020cf05b25d686bd6009c495ad3db4a73ef11
MD5 1c779b5adea7a7543c058f1013af326a
BLAKE2b-256 9aad2e15e07a070897de1b2beffd0f56974506d04f42f7be9556d303b447ad42

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