Skip to main content

Python Guide: Loading Zendesk Data to AWS S3 with dlt

Connecting other file destinations

This document describes how to set up loading to aws 3, but our filesystem source can not only load to s3, but also to Google Cloud Storage, Google Drive, Azure, or local filesystem. Learn more about this here.

Need help deploying these pipelines, or figuring out how to run them in your data stack?

Join our Slack community or book a call with our support engineer Adrian.

dlt is an open-source Python library utilized for data loading tasks. This technical documentation provides a guide on how to use dlt to extract data from Zendesk, a renowned customer service software trusted by over 200,000 customers worldwide. Zendesk allows interaction with customers via various channels such as text, mobile, phone, email, live chat, and social media. The data extracted from Zendesk using dlt will be loaded into AWS S3, a remote file system and bucket storage service. AWS S3 is primarily used as a staging area for other destinations, but can also be used to quickly build a data lake. More information about Zendesk can be found here.

dlt Key Features

  • Pipeline Metadata: dlt pipelines leverage metadata to provide governance capabilities. This metadata includes load IDs, which consist of a timestamp and pipeline name. Load IDs enable incremental transformations and data vaulting by tracking data loads and facilitating data lineage and traceability. Read more about lineage.
  • Schema Enforcement and Curation: dlt empowers users to enforce and curate schemas, ensuring data consistency and quality. Schemas define the structure of normalized data and guide the processing and loading of data. By adhering to predefined schemas, pipelines maintain data integrity and facilitate standardized data handling practices. Read more: Adjust a schema docs.
  • Schema evolution: dlt enables proactive governance by alerting users to schema changes. When modifications occur in the source data’s schema, dlt notifies stakeholders, allowing them to take necessary actions. Read more about Schema Evolution.
  • Scaling and finetuning: dlt offers several mechanism and configuration options to scale up and finetune pipelines, including running extraction, normalization and load in parallel, writing sources and resources that are run in parallel via thread pools and async execution, and finetuning the memory buffers, intermediary file sizes and compression options. Read more about performance.
  • Advanced Usage: dlt is a constantly growing library that supports many features and use cases needed by the community. You can join the Slack community to find recent releases or discuss what you can build with dlt.

Getting started with your pipeline locally

0. Prerequisites

dlt requires Python 3.8 or higher. Additionally, you need to have the pip package manager installed, and we recommend using a virtual environment to manage your dependencies. You can learn more about preparing your computer for dlt in our installation reference.

1. Install dlt

First you need to install the dlt library with the correct extras for AWS S3:

pip install "dlt[filesystem]"

The dlt cli has a useful command to get you started with any combination of source and destination. For this example, we want to load data from Zendesk to AWS S3. You can run the following commands to create a starting point for loading data from Zendesk to AWS S3:

# create a new directory
mkdir my-zendesk-pipeline
cd my-zendesk-pipeline
# initialize a new pipeline with your source and destination
dlt init zendesk filesystem
# install the required dependencies
pip install -r requirements.txt

The last command will install the required dependencies for your pipeline. The dependencies are listed in the requirements.txt:

dlt[filesystem]>=0.3.8

You now have the following folder structure in your project:

my-zendesk-pipeline/
├── .dlt/
│ ├── config.toml # configs for your pipeline
│ └── secrets.toml # secrets for your pipeline
├── zendesk/ # folder with source specific files
│ └── ...
├── zendesk_pipeline.py # your main pipeline script
├── requirements.txt # dependencies for your pipeline
└── .gitignore # ignore files for git (not required)

2. Configuring your source and destination credentials

The dlt cli will have created a .dlt directory in your project folder. This directory contains a config.toml file and a secrets.toml file that you can use to configure your pipeline:

config.toml

# put your configuration values here

[runtime]
log_level="WARNING" # the system log level of dlt
# use the dlthub_telemetry setting to enable/disable anonymous usage data reporting, see https://dlthub.com/docs/telemetry
dlthub_telemetry = true

secrets.toml

# put your secret values and credentials here. do not share this file and do not push it to github

[sources.zendesk.credentials]
subdomain = "subdomain" # please set me up!
email = "email" # please set me up!
password = "password" # please set me up!

[destination.filesystem]
bucket_url = "bucket_url" # please set me up!

[destination.filesystem.credentials]
aws_access_key_id = "aws_access_key_id" # please set me up!
aws_secret_access_key = "aws_secret_access_key" # please set me up!
Further help setting up your source and destinations

Please consult the detailed setup instructions for the AWS S3 destination in the dlt destinations documentation.

Likewise you can find the setup instructions for Zendesk source in the dlt verifed sources documentation.

3. Running your pipeline for the first time

The dlt cli has also created a main pipeline script for you at zendesk_pipeline.py, as well as a folder zendesk that contains additional python files for your source. These files are your local copies which you can modify to fit your needs. In some cases you may find that you only need to do small changes to your pipelines or add some configurations, in other cases these files can serve as a working starting point for your code, but will need to be adjusted to do what you need them to do.

The main pipeline script will look something like this:

import time
from typing import Any

import dlt
from dlt.common.time import timedelta
from zendesk import (
pendulum,
zendesk_chat,
zendesk_talk,
zendesk_support,
make_date_ranges,
)


def incremental_load_all_default() -> Any:
"""
Loads all possible tables for Zendesk Support, Chat, Talk
"""
# FULL PIPELINE RUN
pipeline = dlt.pipeline(
pipeline_name="dlt_zendesk_pipeline",
destination='filesystem',
full_refresh=False,
dataset_name="sample_zendesk_data3",
)

# zendesk support source function
data_support = zendesk_support(load_all=True)
# zendesk chat source function
data_chat = zendesk_chat()
# zendesk talk source function
data_talk = zendesk_talk()
# run pipeline with all 3 sources
info = pipeline.run(data=[data_support, data_chat, data_talk])
return info


def load_support_with_pivoting() -> Any:
"""
Loads Zendesk Support data with pivoting. Simply done by setting the pivot_ticket_fields to true - default option. Loads only the base tables.
"""
pipeline = dlt.pipeline(
pipeline_name="zendesk_support_pivoting",
destination='filesystem',
full_refresh=False,
)
data = zendesk_support(load_all=False, pivot_ticket_fields=True)
info = pipeline.run(data=data)
return info


def incremental_load_all_start_date() -> Any:
"""
Implements incremental load when possible to Support, Chat and Talk Endpoints. The default behaviour gets data since the last load time saved in dlt state or
1st Jan 2000 if there has been no previous loading of the resource. With this setting, the sources will load data since the given data for all incremental endpoints.
Last load time will still be updated.
"""

# Choosing starting point for incremental load - optional, the default is the last load time. If no last load time
# the start time will be the 1st day of the millennium
# start time needs to be a pendulum datetime object
start_date = pendulum.DateTime(year=2023, month=1, day=1).in_timezone("UTC")

pipeline = dlt.pipeline(
pipeline_name="dlt_zendesk_pipeline",
destination='filesystem',
full_refresh=False,
dataset_name="sample_zendesk_data",
)
data = zendesk_support(load_all=True, start_date=start_date)
data_chat = zendesk_chat(start_date=start_date)
data_talk = zendesk_talk(start_date=start_date)
info = pipeline.run(data=[data, data_chat, data_talk])
return info


def incremental_load_with_backloading() -> Any:
"""Backload historic data in ranges. In this method we load all tickets so far created since Jan 1st 2023 but one week at a time
and then switch to incrementally loading new tickets.
This can useful to reduce the potiential failure window when loading large amounts of historic data.
This approach can be used with all incremental Zendesk sources.
"""
pipeline = dlt.pipeline(
pipeline_name="dlt_zendesk_pipeline",
destination='filesystem',
full_refresh=False,
dataset_name="sample_zendesk_data",
)

# Load ranges of dates to load between January 1st 2023 and today
min_start_date = pendulum.DateTime(year=2023, month=1, day=1).in_timezone("UTC")
max_end_date = pendulum.today()
# Generate tuples of date ranges, each with 1 week in between.
ranges = make_date_ranges(min_start_date, max_end_date, timedelta(weeks=1))

# Run the pipeline in a loop for each 1 week range
for start, end in ranges:
print(f"Loading tickets between {start} and {end}")
data = zendesk_support(start_date=start, end_date=end).with_resources("tickets")
info = pipeline.run(data=data)
print(info)

# Backloading is done, now we continue loading with incremental state, starting where the backloading left off
print(f"Loading with incremental state, starting at {end}")
data = zendesk_support(start_date=end).with_resources("tickets")
info = pipeline.run(data)
print(info)


if __name__ == "__main__":
# simple run where everything is loaded
start = time.time()
load_info = incremental_load_all_default()
end = time.time()
print(load_info)
print(f"Time taken: {end-start}")

Provided you have set up your credentials, you can run your pipeline like a regular python script with the following command:

python zendesk_pipeline.py

4. Inspecting your load result

You can now inspect the state of your pipeline with the dlt cli:

dlt pipeline dlt_zendesk_pipeline info

You can also use streamlit to inspect the contents of your AWS S3 destination for this:

# install streamlit
pip install streamlit
# run the streamlit app for your pipeline with the dlt cli:
dlt pipeline dlt_zendesk_pipeline show

5. Next steps to get your pipeline running in production

One of the beauties of dlt is, that we are just a plain Python library, so you can run your pipeline in any environment that supports Python >= 3.8. We have a couple of helpers and guides in our docs to get you there:

The Deploy section will show you how to deploy your pipeline to

  • Deploy with Github Actions: dlt can be deployed using Github Actions. This allows you to automate your workflows and run tasks in response to specific events. For more information on how to deploy dlt using Github Actions, check out the guide here.
  • Deploy with Airflow: dlt can also be deployed using Airflow. This is a platform used to programmatically author, schedule, and monitor workflows. For more information on how to deploy dlt using Airflow, check out the guide here.
  • Deploy with Google Cloud Functions: You can deploy dlt using Google Cloud Functions. This is a serverless execution environment for building and connecting cloud services. For more information on how to deploy dlt using Google Cloud Functions, check out the guide here.
  • Other Deployment Options: There are other options for deploying dlt as well. For more information on these, check out the guide here.

The running in production section will teach you about:

  • Monitoring your pipeline: dlt provides tools for monitoring your data pipeline, ensuring that you can keep track of your data's flow and troubleshoot any issues that may arise. Check out this guide on how to monitor your pipeline.
  • Setting up alerts: With dlt, you can set up alerts to notify you of any issues in your data pipeline. This can help you respond quickly to any problems and keep your data flow running smoothly. Learn more about setting up alerts.
  • Setting up tracing: Tracing is a powerful tool that dlt offers for understanding the flow of data through your pipeline. It can help you identify bottlenecks and understand where your data is at any given time. Discover more about setting up tracing.

Available Sources and Resources

For this verified source the following sources and resources are available

Source zendesk_chat

Zendesk Chat source provides detailed chat session data including user information and messages.

Resource NameWrite DispositionDescription
chatsmergeThis resource includes details about the chats in Zendesk. It includes information such as whether the chat has been deleted, the id, message, details about the session (browser, city, country code, country name, end date, id, ip, platform, region, start date, user agent), timestamp, type of chat, whether it is unread, update timestamp, and details about the visitor (email, id, name, notes, phone).

Source zendesk_support

The source 'zendesk_support' provides comprehensive data on customer service interactions, including ticket details, user information, and organizational metrics.

Resource NameWrite DispositionDescription
activitiesreplaceActivities in Zendesk are logs of all the changes and updates made to tickets.
automationsreplaceAutomations in Zendesk are business rules you define that run in the background of your support operations.
brandsreplaceBrands in Zendesk allow you to manage multiple brands in a single account.
custom_agent_rolesreplaceCustom agent roles in Zendesk allow you to customize the access and permissions of your agents.
dynamic_contentreplaceDynamic content in Zendesk allows you to write one version of an automated response and then translate it into other languages.
group_membershipsreplaceGroup memberships in Zendesk define the groups an agent belongs to.
groupsreplaceGroups in Zendesk are used to route tickets to the right people in your organization.
job_statusreplaceJob statuses in Zendesk provide information about the completion status of a job.
macrosreplaceMacros in Zendesk are predefined responses or sets of actions.
organization_fieldsreplaceOrganization fields in Zendesk are custom fields you can create for organizations.
organization_membershipsreplaceOrganization memberships in Zendesk define the organizations a user belongs to.
organizationsreplaceOrganizations in Zendesk are groups of your end-users.
recipient_addressesreplaceRecipient addresses in Zendesk are the email addresses associated with your support address.
requestsreplaceRequests in Zendesk are the tickets that end-users submit.
satisfaction_ratingsreplaceSatisfaction ratings in Zendesk are the ratings that your end-users can give to your support.
sharing_agreementsreplaceSharing agreements in Zendesk define how tickets are shared with other Zendesk instances.
skipsreplaceSkips in Zendesk are tickets that were skipped in a play queue.
sla_policiesreplaceSLA policies in Zendesk are the service level agreements you define for your tickets.
suspended_ticketsreplaceSuspended tickets in Zendesk are tickets that have been marked as spam or have been suspended for some other reason.
tagsreplaceTags in Zendesk are keywords or phrases that you can add to tickets.
targetsreplaceTargets in Zendesk are third-party applications or services that you can send notifications to.
ticket_eventsappendTicket events in Zendesk are the changes and updates made to a ticket.
ticket_fieldsreplaceTicket fields in Zendesk are the fields that a ticket form is composed of.
ticket_formsreplaceTicket forms in Zendesk are the different forms you can create for different types of tickets.
ticket_metric_eventsappendTicket metric events in Zendesk are the metrics associated with a ticket.
ticket_metricsreplaceTicket metrics in Zendesk are the metrics associated with a ticket.
ticketsmergeTickets in Zendesk are the means by which your end-users request help from your team.
triggersreplaceTriggers in Zendesk are business rules you define that automatically perform actions based on certain conditions.
user_fieldsreplaceUser fields in Zendesk are custom fields you can create for users.
usersreplaceUsers in Zendesk are anyone who interacts with the Zendesk product.
viewsreplaceViews in Zendesk are collections of tickets based on certain criteria.

Source zendesk_talk

Zendesk_talk provides data on call activity, agent activity, settings, greetings, and queue status.

Resource NameWrite DispositionDescription
addressesreplaceThis resource contains the addresses associated with Zendesk Talk.
agents_activityreplaceThis resource contains information about the activity of agents in Zendesk Talk.
callsreplaceThis resource contains information about the calls made in Zendesk Talk.
calls_incrementalmergeThis resource contains incremental information about the calls made in Zendesk Talk.
current_queue_activityreplaceThis resource contains information about the current activity in the queue of Zendesk Talk.
greeting_categoriesreplaceThis resource contains information about the categories of greetings in Zendesk Talk.
greetingsreplaceThis resource contains information about the greetings used in Zendesk Talk.
ivrsreplaceThis resource contains information about the Interactive Voice Response (IVR) systems in Zendesk Talk.
legs_incrementalmergeThis resource contains incremental information about the legs (or parts) of calls in Zendesk Talk.
linesreplaceThis resource contains information about the lines used in Zendesk Talk.
phone_numbersreplaceThis resource contains information about the phone numbers associated with Zendesk Talk.
settingsreplaceThis resource contains information about the settings configured in Zendesk Talk.

Additional pipeline guides

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.