Skip to main content

Loading Data from X to MotherDuck using dlt in Python

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 Violetta.

X, commonly referred to by its former name Twitter, is a social networking service. The X API enables programmatic access to core elements like Posts, Direct Messages, Spaces, Lists, users, and more. This documentation provides guidelines on how to load data from X into MotherDuck. MotherDuck is a fast in-process analytical database built on DuckDB, which supports a feature-rich SQL dialect and deep integrations into client APIs. Using the open-source python library dlt, you can efficiently transfer and manage your data from X to MotherDuck. For more information about X, visit their website.

dlt Key Features

  • Easy to get started: dlt is a Python library that is easy to use and understand. It is designed to be simple to use and easy to understand. Type pip install dlt and you are ready to go. Learn more
  • MotherDuck integration: Seamlessly integrate with MotherDuck for efficient data loading and management. Learn more
  • Comprehensive tutorial: Follow a step-by-step guide to build a pipeline that loads data from the GitHub API into DuckDB. Learn more
  • Governance support: Robust governance support through pipeline metadata, schema enforcement, and schema change alerts. Learn more
  • Performance tuning: Offers several mechanisms and configuration options to scale up and fine-tune pipelines. Learn more

Getting started with your pipeline locally

OpenAPI Source Generator dlt-init-openapi

This walkthrough makes use of the dlt-init-openapi generator cli tool. You can read more about it here. The code generated by this tool uses the dlt rest_api verified source, docs for this are here.

0. Prerequisites

dlt and dlt-init-openapi requires Python 3.9 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 and dlt-init-openapi

First you need to install the dlt-init-openapi cli tool.

pip install dlt-init-openapi

The dlt-init-openapi cli is a powerful generator which you can use to turn any OpenAPI spec into a dlt source to ingest data from that api. The quality of the generator source is dependent on how well the API is designed and how accurate the OpenAPI spec you are using is. You may need to make tweaks to the generated code, you can learn more about this here.

# generate pipeline
# NOTE: add_limit adds a global limit, you can remove this later
# NOTE: you will need to select which endpoints to render, you
# can just hit Enter and all will be rendered.
dlt-init-openapi x --url https://raw.githubusercontent.com/dlt-hub/openapi-specs/main/open_api_specs/Business/twitter.yaml --global-limit 2
cd x_pipeline
# install generated requirements
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>=0.4.12

You now have the following folder structure in your project:

x_pipeline/
├── .dlt/
│ ├── config.toml # configs for your pipeline
│ └── secrets.toml # secrets for your pipeline
├── rest_api/ # The rest api verified source
│ └── ...
├── x/
│ └── __init__.py # TODO: possibly tweak this file
├── x_pipeline.py # your main pipeline script
├── requirements.txt # dependencies for your pipeline
└── .gitignore # ignore files for git (not required)

1.1. Tweak x/__init__.py

This file contains the generated configuration of your rest_api. You can continue with the next steps and leave it as is, but you might want to come back here and make adjustments if you need your rest_api source set up in a different way. The generated file for the x source will look like this:

Click to view full file (1252 lines)

from typing import List

import dlt
from dlt.extract.source import DltResource
from rest_api import rest_api_source
from rest_api.typing import RESTAPIConfig


@dlt.source(name="x_source", max_table_nesting=2)
def x_source(
token: str = dlt.secrets.value,
base_url: str = dlt.config.value,
) -> List[DltResource]:

# source configuration
source_config: RESTAPIConfig = {
"client": {
"base_url": base_url,
"auth": {

"type": "bearer",
"token": token,

},
},
"resources":
[
# Returns recent Compliance Jobs for a given job type and optional job status
{
"name": "list_batch_compliance_jobs",
"table_name": "compliance_job",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/compliance/jobs",
"params": {
"type": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "status": "OPTIONAL_CONFIG",
# "compliance_job.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns DM Events for a DM Conversation
{
"name": "get_dm_conversations_with_participant_id_dm_events",
"table_name": "dm_event",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/dm_conversations/with/{participant_id}/dm_events",
"params": {
"participant_id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "event_types": "['MessageCreate', 'ParticipantsLeave', 'ParticipantsJoin']",
# "dm_event.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns DM Events for a DM Conversation
{
"name": "get_dm_conversations_id_dm_events",
"table_name": "dm_event",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/dm_conversations/{id}/dm_events",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "event_types": "['MessageCreate', 'ParticipantsLeave', 'ParticipantsJoin']",
# "dm_event.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns recent DM Events across DM conversations
{
"name": "get_dm_events",
"table_name": "dm_event",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/dm_events",
"params": {
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "event_types": "['MessageCreate', 'ParticipantsLeave', 'ParticipantsJoin']",
# "dm_event.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a single Compliance Job by ID
{
"name": "get_batch_compliance_job",
"table_name": "get_2_compliance_jobs_id_response",
"endpoint": {
"data_selector": "$",
"path": "/2/compliance/jobs/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "list_batch_compliance_jobs",
"field": "id",
},
# the parameters below can optionally be configured
# "compliance_job.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a List.
{
"name": "list_id_get",
"table_name": "get_2_lists_id_response",
"endpoint": {
"data_selector": "$",
"path": "/2/lists/{id}",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "list.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a variety of information about the Space specified by the requested ID
{
"name": "find_space_by_id",
"table_name": "get_2_spaces_id_response",
"endpoint": {
"data_selector": "$",
"path": "/2/spaces/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "find_spaces_by_ids",
"field": "id",
},
# the parameters below can optionally be configured
# "space.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "topic.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a variety of information about the Tweet specified by the requested ID.
{
"name": "find_tweet_by_id",
"table_name": "get_2_tweets_id_response",
"endpoint": {
"data_selector": "$",
"path": "/2/tweets/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "find_tweets_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# This endpoint returns information about a User. Specify User by username.
{
"name": "find_user_by_username",
"table_name": "get_2_users_by_username_username_response",
"endpoint": {
"data_selector": "$",
"path": "/2/users/by/username/{username}",
"params": {
"username": {
"type": "resolve",
"resource": "find_users_by_username",
"field": "username",
},
# the parameters below can optionally be configured
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# This endpoint returns information about a User. Specify User by ID.
{
"name": "find_user_by_id",
"table_name": "get_2_users_id_response",
"endpoint": {
"data_selector": "$",
"path": "/2/users/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a User's followed Lists.
{
"name": "user_followed_lists",
"table_name": "list",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/followed_lists",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "list.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Get a User's List Memberships.
{
"name": "get_user_list_memberships",
"table_name": "list",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/list_memberships",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "list.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Get a User's Owned Lists.
{
"name": "list_user_owned_lists",
"table_name": "list",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/owned_lists",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "list.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Get a User's Pinned Lists.
{
"name": "list_user_pinned_lists",
"table_name": "list",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/pinned_lists",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "list.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Full OpenAPI Specification in JSON format. (See https://github.com/OAI/OpenAPI-Specification/blob/master/README.md)
{
"name": "get_open_api_spec",
"table_name": "openapus",
"endpoint": {
"data_selector": "$",
"path": "/2/openapi.json",
"paginator": "auto",
}
},
# Streams 100% of compliance data for Tweets
{
"name": "get_tweets_compliance_stream",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/tweets/compliance/stream",
"params": {
"partition": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "backfill_minutes": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Streams 100% of public Tweets.
{
"name": "get_tweets_firehose_stream",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/tweets/firehose/stream",
"params": {
"partition": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "backfill_minutes": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Streams 100% of labeling events applied to Tweets
{
"name": "get_tweets_label_stream",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/tweets/label/stream",
"params": {
# the parameters below can optionally be configured
# "backfill_minutes": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Streams a deterministic 1% of public Tweets.
{
"name": "sample_stream",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/tweets/sample/stream",
"params": {
# the parameters below can optionally be configured
# "backfill_minutes": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Streams a deterministic 10% of public Tweets.
{
"name": "get_tweets_sample_10_stream",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/tweets/sample10/stream",
"params": {
"partition": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "backfill_minutes": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Streams Tweets matching the stream's active rule set.
{
"name": "search_stream",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/tweets/search/stream",
"params": {
# the parameters below can optionally be configured
# "backfill_minutes": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Streams 100% of compliance data for Users
{
"name": "get_users_compliance_stream",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/users/compliance/stream",
"params": {
"partition": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "backfill_minutes": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# This endpoint returns information about the requesting User.
{
"name": "find_my_user",
"table_name": "problem",
"endpoint": {
"data_selector": "errors",
"path": "/2/users/me",
"params": {
# the parameters below can optionally be configured
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns rules from a User's active rule set. Users can fetch all of their rules or a subset, specified by the provided rule ids.
{
"name": "get_rules",
"table_name": "rule",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/search/stream/rules",
"params": {
# the parameters below can optionally be configured
# "ids": "OPTIONAL_CONFIG",
# "max_results": "1000",
# "pagination_token": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Tweet Counts that match a search query.
{
"name": "tweet_counts_full_archive_search",
"table_name": "search_count",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/counts/all",
"params": {
"query": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "since_id": "OPTIONAL_CONFIG",
# "until_id": "OPTIONAL_CONFIG",
# "next_token": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "granularity": "hour",
# "search_count.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Tweet Counts from the last 7 days that match a search query.
{
"name": "tweet_counts_recent_search",
"table_name": "search_count",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/counts/recent",
"params": {
"query": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "since_id": "OPTIONAL_CONFIG",
# "until_id": "OPTIONAL_CONFIG",
# "next_token": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "granularity": "hour",
# "search_count.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a variety of information about the Spaces specified by the requested IDs
{
"name": "find_spaces_by_ids",
"table_name": "space",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/spaces",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "space.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "topic.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a variety of information about the Spaces created by the provided User IDs
{
"name": "find_spaces_by_creator_ids",
"table_name": "space",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/spaces/by/creator_ids",
"params": {
"user_ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "space.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "topic.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Spaces that match the provided query.
{
"name": "search_spaces",
"table_name": "space",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/spaces/search",
"params": {
"query": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "state": "all",
# "max_results": "100",
# "space.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "topic.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Tweets associated with the provided List ID.
{
"name": "lists_id_tweets",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/lists/{id}/tweets",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Retrieves Tweets shared in the specified Space.
{
"name": "space_tweets",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/spaces/{id}/tweets",
"params": {
"id": {
"type": "resolve",
"resource": "find_spaces_by_ids",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "100",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a variety of information about the Tweet specified by the requested ID.
{
"name": "find_tweets_by_id",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Tweets that match a search query.
{
"name": "tweets_fullarchive_search",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/search/all",
"params": {
"query": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "since_id": "OPTIONAL_CONFIG",
# "until_id": "OPTIONAL_CONFIG",
# "max_results": "10",
# "next_token": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "sort_order": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Tweets from the last 7 days that match a search query.
{
"name": "tweets_recent_search",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/search/recent",
"params": {
"query": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "since_id": "OPTIONAL_CONFIG",
# "until_id": "OPTIONAL_CONFIG",
# "max_results": "10",
# "next_token": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "sort_order": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a variety of information about each Tweet that quotes the Tweet specified by the requested ID.
{
"name": "find_tweets_that_quote_a_tweet",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/{id}/quote_tweets",
"params": {
"id": {
"type": "resolve",
"resource": "find_tweets_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "10",
# "pagination_token": "OPTIONAL_CONFIG",
# "exclude": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Tweet objects that have been bookmarked by the requesting User
{
"name": "get_users_id_bookmarks",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/bookmarks",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Tweets liked by the provided User ID
{
"name": "users_id_liked_tweets",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/liked_tweets",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Tweet objects that mention username associated to the provided User ID
{
"name": "users_id_mentions",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/mentions",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "since_id": "OPTIONAL_CONFIG",
# "until_id": "OPTIONAL_CONFIG",
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns Tweet objects that appears in the provided User ID's home timeline
{
"name": "users_id_timeline",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/timelines/reverse_chronological",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "since_id": "OPTIONAL_CONFIG",
# "until_id": "OPTIONAL_CONFIG",
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "exclude": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Tweets authored by the provided User ID
{
"name": "users_id_tweets",
"table_name": "tweet",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/tweets",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "since_id": "OPTIONAL_CONFIG",
# "until_id": "OPTIONAL_CONFIG",
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "exclude": "OPTIONAL_CONFIG",
# "start_time": "OPTIONAL_CONFIG",
# "end_time": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "media.fields": "OPTIONAL_CONFIG",
# "poll.fields": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "place.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users that follow a List by the provided List ID
{
"name": "list_get_followers",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/lists/{id}/followers",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users that are members of a List by the provided List ID.
{
"name": "list_get_members",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/lists/{id}/members",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Retrieves the list of Users who purchased a ticket to the given space
{
"name": "space_buyers",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/spaces/{id}/buyers",
"params": {
"id": {
"type": "resolve",
"resource": "find_spaces_by_ids",
"field": "id",
},
# the parameters below can optionally be configured
# "pagination_token": "OPTIONAL_CONFIG",
# "max_results": "100",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users that have liked the provided Tweet ID
{
"name": "tweets_id_liking_users",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/{id}/liking_users",
"params": {
"id": {
"type": "resolve",
"resource": "find_tweets_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users that have retweeted the provided Tweet ID
{
"name": "tweets_id_retweeting_users",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/tweets/{id}/retweeted_by",
"params": {
"id": {
"type": "resolve",
"resource": "find_tweets_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# This endpoint returns information about Users. Specify Users by their ID.
{
"name": "find_users_by_id",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# This endpoint returns information about Users. Specify Users by their username.
{
"name": "find_users_by_username",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/by",
"params": {
"usernames": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users that are blocked by the provided User ID
{
"name": "users_id_blocking",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/blocking",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users who are followers of the specified User ID.
{
"name": "users_id_followers",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/followers",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users that are being followed by the provided User ID
{
"name": "users_id_following",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/following",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "OPTIONAL_CONFIG",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
# Returns a list of Users that are muted by the provided User ID
{
"name": "users_id_muting",
"table_name": "user",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/2/users/{id}/muting",
"params": {
"id": {
"type": "resolve",
"resource": "find_users_by_id",
"field": "id",
},
# the parameters below can optionally be configured
# "max_results": "100",
# "pagination_token": "OPTIONAL_CONFIG",
# "user.fields": "OPTIONAL_CONFIG",
# "expansions": "OPTIONAL_CONFIG",
# "tweet.fields": "OPTIONAL_CONFIG",

},
"paginator": "auto",
}
},
]
}

return rest_api_source(source_config)

2. Configuring your source and destination credentials

info

dlt-init-openapi will try to detect which authentication mechanism (if any) is used by the API in question and add a placeholder in your secrets.toml.

  • If you know your API needs authentication, but none was detected, you can learn more about adding authentication to the rest_api here.
  • OAuth detection currently is not supported, but you can supply your own authentication mechanism as outlined here.

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. The automatically created version of these files look like this:

generated config.toml


[runtime]
log_level="INFO"

[sources.x]
# Base URL for the API
# Twitter API
base_url = "https://api.twitter.com"

generated secrets.toml


[sources.x]
# secrets for your x source
token = "FILL ME OUT" # TODO: fill in your credentials

2.1. Adjust the generated code to your usecase

Further help setting up your source and destinations

At this time, the dlt-init-openapi cli tool will always create pipelines that load to a local duckdb instance. Switching to a different destination is trivial, all you need to do is change the destination parameter in x_pipeline.py to motherduck and supply the credentials as outlined in the destination doc linked below.

  • Read more about setting up the rest_api source in our docs.
  • Read more about setting up the MotherDuck destination in our docs.

3. Running your pipeline for the first time

The dlt cli has also created a main pipeline script for you at x_pipeline.py, as well as a folder x 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 dlt

from x import x_source


if __name__ == "__main__":
pipeline = dlt.pipeline(
pipeline_name="x_pipeline",
destination='duckdb',
dataset_name="x_data",
progress="log",
export_schema_path="schemas/export"
)
source = x_source()
info = pipeline.run(source)
print(info)

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

python x_pipeline.py

4. Inspecting your load result

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

dlt pipeline x_pipeline info

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

# install streamlit
pip install streamlit
# run the streamlit app for your pipeline with the dlt cli:
dlt pipeline x_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: Learn how to deploy your dlt pipeline using GitHub Actions, a free CI/CD runner. Follow the guide here.
  • Deploy with Airflow and Google Composer: Deploy your dlt pipeline with Airflow, using Google Composer for a managed environment. Detailed instructions can be found here.
  • Deploy with Google Cloud Functions: Use Google Cloud Functions to deploy your dlt pipeline. The step-by-step guide is available here.
  • Explore Other Deployment Options: Discover more ways to deploy your dlt pipeline by checking out additional guides here.

The running in production section will teach you about:

  • How to Monitor your pipeline: Learn how to effectively monitor your dlt pipeline to ensure smooth and efficient data processing. How to Monitor your pipeline
  • Set up alerts: Set up alerts to be notified of any issues or anomalies in your pipeline execution. Set up alerts
  • Set up tracing: Implement tracing to get detailed insights into the performance and behavior of your dlt pipeline. Set up tracing

Available Sources and Resources

For this verified source the following sources and resources are available

Source X

Source X for service X provides user, tweet, list, compliance, and space data.

Resource NameWrite DispositionDescription
get_2_compliance_jobs_id_responseappendRetrieves details of a specific compliance job
get_2_users_id_responseappendRetrieves details of a specific user by ID
userappendContains information about a user
ruleappendContains information about a rule
get_2_tweets_id_responseappendRetrieves details of a specific tweet by ID
search_countappendContains search count data
dm_eventappendContains information about a direct message event
problemappendContains information about a problem
listappendContains information about a list
get_2_users_by_username_username_responseappendRetrieves details of a specific user by username
tweetappendContains information about a tweet
openapusappendContains information about open API usage
compliance_jobappendContains information about compliance jobs
get_2_spaces_id_responseappendRetrieves details of a specific space by ID
get_2_lists_id_responseappendRetrieves details of a specific list by ID
spaceappendContains information about a space

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.