Nylas Python SDK

6.14.3 · active · verified Thu Apr 16

The Nylas Python SDK provides convenient Python bindings for interacting with the Nylas API platform (v3). It simplifies access to email, calendar, and contacts functionalities, abstracting away direct HTTP requests. Currently at version 6.14.3, the library maintains an active release cadence with frequent updates and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the Nylas Python SDK client using API key authentication and then lists the calendars associated with a given grant ID. Ensure your `NYLAS_API_KEY`, `NYLAS_API_URI`, and `NYLAS_GRANT_ID` are set as environment variables or replaced in the code.

import os
from nylas import Client
from nylas.models.errors import NylasAPIError

# Ensure environment variables are set for authentication
NYLAS_API_KEY = os.environ.get('NYLAS_API_KEY', 'YOUR_NYLAS_API_KEY')
NYLAS_API_URI = os.environ.get('NYLAS_API_URI', 'https://api.us.nylas.com') # Or https://api.eu.nylas.com
NYLAS_GRANT_ID = os.environ.get('NYLAS_GRANT_ID', 'YOUR_NYLAS_GRANT_ID')

if NYLAS_API_KEY == 'YOUR_NYLAS_API_KEY' or NYLAS_GRANT_ID == 'YOUR_NYLAS_GRANT_ID':
    print("Please set NYLAS_API_KEY and NYLAS_GRANT_ID environment variables or replace placeholders.")
else:
    try:
        # Initialize the Nylas client
        nylas = Client(
            api_key=NYLAS_API_KEY,
            api_uri=NYLAS_API_URI
        )

        # Example: List calendars for the authenticated grant
        print(f"Attempting to list calendars for Grant ID: {NYLAS_GRANT_ID}")
        calendars, request_id, next_cursor = nylas.calendars.list(identifier=NYLAS_GRANT_ID)

        if calendars:
            print("Successfully retrieved calendars:")
            for calendar in calendars:
                print(f"  - {calendar.name} (ID: {calendar.id}, Read-only: {calendar.read_only})")
        else:
            print("No calendars found for this grant.")

    except NylasAPIError as e:
        print(f"Nylas API Error: {e.status_code} - {e.message}")
        print(f"Details: {e.error_response}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →