Skip to content

Releases: nylas/nylas-python

v5.3.0

26 Nov 18:47
Compare
Choose a tag to compare

This new release of the Nylas Python SDK brings a slew of new features with support to many new Nylas APIs as well as new features to enhance existing models.

New Features

  • Add support for Scheduler API
  • Add support for Event notifications
  • Add support for Component CRUD
  • Add metadata support for Calendar, Message and Account

Enhancements

  • Improve error details returned from the API

Usage

Scheduler API

To create a new Scheduler page:

scheduler = nylas.scheduler.create()
scheduler.access_tokens = ["ACCESS_TOKEN"]
scheduler.name = "Python SDK Example"
scheduler.slug = "py_example_1"
scheduler.save()

To return all Scheduler pages:

scheduler_list = nylas.scheduler.all()

To return a single Scheduler page:

scheduler = nylas.scheduler.get('SCHEDULER_ID')

To update a Scheduler page:

scheduler = nylas.scheduler.get('SCHEDULER_ID')
scheduler.name = "Updated page name"
scheduler.save()

To delete a Scheduler page:

nylas.scheduler.delete('SCHEDULER_ID')

To get available calendars for a Scheduler page:

scheduler = nylas.scheduler.get('SCHEDULER_ID')
calendars = scheduler.get_available_calendars()

To upload an image:

scheduler = nylas.scheduler.get('SCHEDULER_ID')
scheduler.upload_image(content_type: "image/png", object_name: "test.png")

Checking Provider Availability

# Google Availability
google_availability = nylas.scheduler.get_google_availability()

# Office 365 Availability
o365_availability = nylas.scheduler.get_office_365_availability()

Get page information/configuration

page_config = nylas.scheduler.get_page_slug('slug')

Retrieve available time slots

available_timeslots = nylas.scheduler.get_available_time_slots('slug')

Book a time slot

slot = SchedulerTimeSlot.create(nylas)
slot.account_id = "test-account-id"
slot.calendar_id = "test-calendar-id"
slot.emails = ["[email protected]"]
slot.host_name = "Host"
slot.start = datetime.utcfromtimestamp(1636728347)
slot.end = datetime.utcfromtimestamp(1636731958)

timeslot_to_book = SchedulerBookingRequest.create(nylas)
timeslot_to_book.additional_values = {
    "test": "yes",
}
timeslot_to_book.email = "[email protected]"
timeslot_to_book.locale = "en_US"
timeslot_to_book.name = "Recipient Doe"
timeslot_to_book.timezone = "America/New_York"
timeslot_to_book.slot = slot

booking_confirmation = nylas.scheduler.book_time_slot("slug", timeslot_to_book)

Confirm a booking

booking_confirmation = nylas.scheduler.confirm_booking('slug', 'edit-hash');

Cancel a booking

nylas.scheduler.cancel_booking('slug', 'edit-hash', 'reason');

Event Notifications

To create a notification for an event:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

# Create a new event
event = nylas.events.create()

# Add notification details to the event
event.notifications = [
  {
    body: "Reminding you about our meeting.",
    minutes_before_event: 600,
    subject: "Test Event Notification",
    type: "email"
  },
  {
    type: "webhook",
    minutes_before_event: 600,
    url: "https://hooks.service.com/services/T01A03EEXDE/B01TBNH532R/HubIZu1zog4oYdFqQ8VUcuiW",
    payload: json.dumps({
      text: "Your reminder goes here!"
    })
  },
  {
    type: "sms",
    minutes_before_event: 60,
    message: "Test Event Notfication"
  }
]

To retrieve event notification details of an event:

# Get an event
event = nylas.events.get("EVENT_ID")

# Add notification details to the event
minutes_before_event = event.notifications[0].["minutes_before_event"]
type = event.notifications[0].["type"]
body = event.notifications[0].["body"]
url = event.notifications[0].["url"]
subject = event.notifications[0].["subject"]
payload = event.notifications[0].["payload"]
message = event.notifications[0].["message"]

To update an event with a notification:

# Get an event
event = nylas.events.get("EVENT_ID")

event.notifications = [{
    body: "Reminding you about our meeting.",
    minutes_before_event: 600,
    subject: "Test Event Notification",
    type: "email"
  }]
event.save()

To delete a notification from an event:

# Get an event
event = nylas.events.get("EVENT_ID")

event.notifications = []
event.save()

Component CRUD

To create a new component:

component = nylas.components.create()
component.name = "Python Component"
component.type = "agenda"
component.public_account_id = "ACCOUNT_PUBLIC_ID"
component.access_token = "ACCOUNT_ACCESS_TOKEN"
component.save()

To get all components:

components = nylas.components.all()

To get a specific component:

component = nylas.components.get("{COMPONENT_ID}")

To update a component:

component = nylas.components.get("{COMPONENT_ID}")
component.name = "Updated"
component.save()

To delete a component:

nylas.components.delete("{COMPONENT_ID}")

Expanded Metadata support

Adding Metadata to Calendar

calendar = nylas.calendars.create()
calendar.name = "My New Calendar"
calendar.description = "Description of my new calendar"
calendar.location = "Location description"
calendar.timezone = "America/Los_Angeles"
calendar.metadata = {
  "event_type": "gathering"
}
calendar.save()

# Or you can update a calendar with metadata

calendar = nylas.calendars.first()

calendar.metadata = {
  "event_type": "gathering"
}
calendar.save()

Query Calendars by Metadata

calendars = nylas.calendars.where(metadata_pair={event_type: "gathering"})

Adding Metadata to Message

message = nylas.messages.first()

message.metadata = {
  "test": "true"
}
message.save()

Adding Metadata to Account

account = api.accounts[0]

account.metadata = {
  "test": "true"
}
account.save()

Query Account by Metadata

accounts = api.accounts.where(metadata_key="test");

v5.2.0

24 Sep 20:50
Compare
Choose a tag to compare

This new release of the Nylas Python SDK brings a couple of critical fixes as well as enhancing support for Event Conference Sync with Auto Create Meetings (Private Beta) support as well as improving calendar availability support.

New Features

  • Add support for calendar consecutive availability
  • Add dynamic conferencing link creation support

Usage

Consecutive Availability

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

emails = [["[email protected]"], ["[email protected]", "[email protected]"]]
duration = 30
interval = 60
start_at = 1632236400
end_at = 1632240000
open_hours = api_client.open_hours(
    [
        "[email protected]",
        "[email protected]",
        "[email protected]",
        "[email protected]",
    ],
    [0],
    "America/Chicago",
    "10:00",
    "14:00",
)
free_busy = [
    {
        "email": "[email protected]",
        "time_slots": [
            {
                "object": "time_slot",
                "status": "busy",
                "start_time": 1632236400,
                "end_time": 1632240000,
            }
        ],
    }
]
api_client.consecutive_availability(
    emails,
    duration,
    interval,
    start_at,
    end_at,
    free_busy=free_busy,
    open_hours=open_hours,
)

Auto Create Meetings

To have Nylas autocreate the conference field for you, pass the autocreate object to the new event:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

#Create a new event
event = nylas.events.create()

# add conferencing details
event.conferencing = {
    "provider": "Zoom Meeting",
    "conferencing": {
        "autocreate": {
            "settings": {
                "password": "1234",
            },
        },
    },
}

A few notes and things to keep in mind:

  • Only one of details or autocreate can be present, and we have implemented client-side checking to enforce this rule
  • Autocreating conferencing data is an asynchronous operation on the server-side. The Event object returned will not have a conferencing field, but it should be available in a future get call once the conference is created on the backend. The initial Event object returned will have a jobStatusId value which can be used to check on the status of conference creation.
  • The settings object within the autocreate object maps to the settings the Nylas API will send to the conference provider for the conference creation. For example with Zoom the settings object maps to Zoom's Create a Meeting object.

v5.1.0

31 Aug 17:54
Compare
Choose a tag to compare

This new release of the Nylas Python SDK brings a couple of critical fixes as well as adding support for Event Conference Sync (Beta).

New Features

  • Add Event conferencing support

Enhancements

  • Fix categorized_at type to be epoch in NeuralCategorizer
  • Fix error when creating events by filtering of "None" value attributes before making requests

v5.0.0

21 Jul 21:07
Compare
Choose a tag to compare

👋 Hey there! It's been a while but we have a new action-packed release for the Python SDK! This new release addresses a lot of issues and bugs. Furthermore we have some new exciting features such as support for the new Nylas Neural API, Event Metadata, and support for new Room Resources fields! Please note that with this release you may need to update your configuration as we have changed the names of the API configuration variables. More information can be found below under "Breaking Changes".

New Features

  • Add support for the Nylas Neural API (#163)
  • Add metadata support (#152)
  • Add new Room Resource fields (#156)
  • Add Nylas-API-Version header support (#157)

Enhancements

  • Transitioned from app_id and app_secret naming to client_id and client_secret (#159)
  • Fix adding a tracking object to an existing draft (#153)
  • Fix issue when converting offset-aware datetime objects to timestamp (#154)
  • Fix limit value in filter not being used when making .all() call (#155)
  • Fix from_ field set by attribute on draft ignored (#162)
  • Remove bumpversion from a required dependency to an extra dependency (#158)

Breaking Changes

API Configuration

The Python SDK previously used the variable names app_id and app_secret for the API configuration. They have now changed to client_id and client_secret. In the other Nylas components like the API and other SDKs the values are referred to as the Client ID and the Client Secret so this change was made for consistency and to reduce confusion.

If you were previously initializing APIClient by passing in the credentials as a variable assignment, you are required to update your code to reflect the new credential variable names:

client = APIClient(
        client_id="CLIENT_ID",
        client_secret="CLIENT_SECRET",
    )

If you were initializing it by just passing in the values in order like so:

client = APIClient(
        "CLIENT_ID",
        "CLIENT_SECRET",
    )

then no change is required on your part.

Using New Features

Neural API

To use Sentiment Analysis:

# To perform sentiment analysis on a message, pass in the list of message ID:
message_analysis = nylas.neural.sentiment_analysis_message([MESSAGE_ID])

# To perform sentiment analysis on just text, pass in a string:
text_analysis = nylas.neural.sentiment_analysis_text("Hi, thank you so much for reaching out! We can catch up tomorrow.")

To use Signature Extraction:

const signature = nylas.neural.extract_signature([MESSAGE_ID])

# The method also accepts two optional parameters
# parseContact, a boolean for whether Nylas should parse the contact from the signature (API defaults to true)
# options, an object of options that can be enabled for the Neural endpoint, of type NeuralMessageOptions:
options = NeuralMessageOptions(
    ignore_links=False,
    ignore_images=False,
    ignore_tables=False,
    remove_conclusion_phrases=False,
    images_as_markdowns=False
)

signature = nylas.neural.extract_signature([MESSAGE_ID], true, options)

and to parse the contact and convert it to the standard Nylas contact object:

contact = signature[0].contacts.to_contact_object()

To use Clean Conversations:

convo = nylas.neural.clean_conversation([MESSAGE_ID])

# You can also pass in an object of options that can be enabled for the Neural endpoint, of type NeuralMessageOptions
convo = nylas.neural.clean_conversation([MESSAGE_ID], options);

and to extract images from the result:

convo[0].extract_images()

To use Optical Character Recognition:

ocr = nylas.neural.ocr_request(FILE_ID)

# This endpoint also supports a second, optional parameter for an array specifying the pages that the user wants analyzed:
ocr = nylas.neural.ocr_request(FILE_ID, [2, 3])

To use Categorizer

cat = nylas.neural.categorize([MESSAGE_ID])

# You can also send a request to recategorize the message:
cat = cat[0].recategorize("conversation")

Event Metadata

# To filter using either metadata_key or metadata_value you can pass in a string:
events = nylas.events.where(metadata_key='hello').all()

# or, you can pass in multiple strings as an array:
events = nylas.events.where(metadata_value=['value1', 'value2']).all()

# To filter on `metadata_pair` you can pass in a `dict` of key-value pairs to use in the query:
events = nylas.events.where(metadata_pair={'hello': 'world'}).all()

v4.12.1

17 Jul 12:04
Compare
Choose a tag to compare
Bump version: 4.12.0 → 4.12.1

v4.12.0

30 Jun 20:57
Compare
Choose a tag to compare
Bump version: 4.11.0 → 4.12.0

v4.11.0

09 Jun 10:13
Compare
Choose a tag to compare
Bump version: 4.10.0 → 4.11.0

v4.9.0

10 Feb 14:32
Compare
Choose a tag to compare
Bump version: 4.8.1 → 4.9.0

4.7.0

02 Apr 21:40
Compare
Choose a tag to compare
v4.7.0

Bump version: 4.6.2 → 4.7.0

v3.0.0

10 Aug 00:18
Compare
Choose a tag to compare

Release Notes

Large changes

  • The Nylas Python SDK now fully supports both Python 2.7 and Python 3.3+.
  • The SDK has a new dependency: the
    URLObject library.
    This dependency will be automatically installed when you upgrade.
  • The SDK now automatically converts between timestamps and Python datetime
    objects. These automatic conversions are opt-in: your existing code should
    continue to work unmodified. See the "Timestamps and Datetimes"
    section of this document for more information.

Small changes

  • The SDK now has over 95% automated test coverage.
  • Previously, trying to access the following model properties would raise an error:
    Folder.threads, Folder.messages, Label.threads, Label.messages.
    These properties should now work as expected.
  • The Thread model now exposes the last_message_received_timestamp and
    last_message_sent_timestamp properties, obtained from the Nylas API.
  • Previously, if you created a Draft object, saved it, and then
    deleted it without modifying it further, the deletion would fail silently.
    Now, the SDK will actually attempt to delete a newly-saved Draft object,
    and will raise an error if it is unable to do so.
  • Previously, you could initialize an APIClient with an api_server
    value set to an http:// URL. Now, APIClient will verify that the
    api_server value starts with https://, and will raise an error if it
    does not.
  • The APIClient constructor no longers accepts the auth_server argument,
    as it was never used for anything.
  • The nylas.client.util.url_concat and nylas.client.util.generate_id
    functions have been removed. These functions were meant for internal use,
    and were never documented or expected to be used by others.
  • You can now pass a state argument to APIClient.authentication_url(),
    as per the OAuth 2.0 spec.

Timestamps and Datetimes

Some properties in the Nylas API use timestamp integers to represent a specific
moment in time, such as Message.date. The Python SDK now exposes new properties
that have converted these existing properties from integers to Python datetime
objects. You can still access the existing properties to get the timestamp
integer -- these new properties are just a convenient way to access Python
datetime objects, if you want them.

This table summarizes the new datetime properties, and which existing timestamp
properties they match up with.

New Property (datetime) Existing Property (timestamp)
Message.received_at Message.date
Thread.first_message_at Thread.first_message_timestamp
Thread.last_message_at Thread.last_message_timestamp
Thread.last_message_received_at Thread.last_message_received_timestamp
Thread.last_message_sent_at Thread.last_message_sent_timestamp
Draft.last_modified_at Draft.date
Event.original_start_at Event.original_start_time

You can also use datetime objects when filtering on models with the .where()
method. For example, if you wanted to find all messages that were received
before Jan 1, 2015, previously you would run this code:

client.messages.where(received_before=1420070400).all()

That code will still work, but if you prefer, you can run this code instead:

from datetime import datetime

client.messages.where(received_before=datetime(2015, 1, 1)).all()

You can now use datetimes with the following filters:

  • client.messages.where(received_before=datetime())
  • client.messages.where(received_after=datetime())
  • client.threads.where(last_message_before=datetime())
  • client.threads.where(last_message_after=datetime())
  • client.threads.where(started_before=datetime())
  • client.threads.where(started_after=datetime())

Full Changelog