Quick Start Guide

This guide will walk you through building a complete application using Gspace.

Project Setup

Create a new directory and set up your project:

bash
mkdir gspace-app
cd gspace-app
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install gspace

Example Application

Let's build a simple application that:

  1. Lists upcoming calendar events
  2. Sends email reminders for events
  3. Uploads event summaries to Drive
python
from gspace import GSpace
from datetime import datetime, timedelta

# Initialize
gspace = GSpace.from_oauth(
    credentials_file="credentials.json",
    scopes=["calendar", "gmail", "drive"]
)

# Get services
calendar = gspace.calendar()
gmail = gspace.gmail()
drive = gspace.drive()

# Get upcoming events
events = calendar.list_events(
    time_min=datetime.now(),
    time_max=datetime.now() + timedelta(days=7),
    max_results=10
)

print(f"Found {len(events)} upcoming events")

# Process each event
for event in events:
    summary = event.get('summary', 'No title')
    start = event.get('start', {}).get('dateTime', 'Unknown')
    
    # Send reminder email
    gmail.send_simple_email(
        to="user@example.com",
        subject=f"Reminder: {summary}",
        body=f"You have an event '{summary}' starting at {start}"
    )
    
    # Create summary file
    content = f"Event: {summary}\nStart: {start}\n"
    drive.upload_file(
        file_path=content.encode(),
        name=f"{summary}_summary.txt",
        mime_type="text/plain"
    )
    
    print(f"Processed: {summary}")

print("Done!")

Error Handling

Always wrap API calls in try-except blocks:

python
try:
    event = calendar.create_event(...)
except Exception as e:
    print(f"Error creating event: {e}")

Next Steps