Loading Data from X
to YugabyteDB
Using Python's dlt
We will be using the dlt PostgreSQL destination to connect to YugabyteDB. You can get the connection string for your YugabyteDB database as described in the YugabyteDB Docs.
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 X
's core elements like Posts, Direct Messages, Spaces, Lists, users, and more. YugabyteDB
is a distributed PostgreSQL for modern apps. It allows running business-critical applications on a distributed database with built-in resilience, seamless scalability, and flexible geo-distribution using PostgreSQL-compatible and Cassandra-inspired APIs. This documentation provides guidance on loading data from X
into YugabyteDB
using the open source python library called dlt
. Further information about X
can be found at https://www.x.com/.
dlt
Key Features
- Pipeline Metadata:
dlt
pipelines leverage metadata to provide governance capabilities, including load IDs for tracking data loads and facilitating data lineage and traceability. Read more - Schema Enforcement and Curation:
dlt
empowers users to enforce and curate schemas, ensuring data consistency and quality. Learn more - Scalability via Iterators, Chunking, and Parallelization:
dlt
offers scalable data extraction by leveraging iterators, chunking, and parallelization techniques. Read more - Snowflake Authentication:
dlt
supports multiple authentication types for Snowflake, including password, key pair, and external authentication. Learn more - How
dlt
Works: Understand the process of extracting, normalizing, and loading data withdlt
. Learn more
Getting started with your pipeline locally
dlt-init-openapi
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
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
.
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
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 postgres and supply the credentials as outlined in the destination doc linked below.
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 YugabyteDB
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 set up continuous integration and deployment pipelines using GitHub Actions.
- Deploy with Airflow and Google Composer: Follow this guide to deploy your pipeline using Airflow and Google Composer.
- Deploy with Google Cloud Functions: Discover how to deploy your pipeline using Google Cloud Functions.
- Explore more deployment options: Check out additional methods for deploying your pipeline here.
The running in production section will teach you about:
- How to Monitor your pipeline: Learn how to effectively monitor your
dlt
pipeline in production to ensure smooth operation and quick identification of issues. How to Monitor your pipeline - Set up alerts: Configure alerts to get notified about important events and potential issues in your
dlt
pipeline. Set up alerts - Set up tracing: Implement tracing to gather detailed runtime information about your
dlt
pipeline, helping you diagnose and resolve issues more efficiently. And 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 Name | Write Disposition | Description |
---|---|---|
get_2_compliance_jobs_id_response | append | Retrieves details of a specific compliance job |
get_2_users_id_response | append | Retrieves details of a specific user by ID |
user | append | Contains information about a user |
rule | append | Contains information about a rule |
get_2_tweets_id_response | append | Retrieves details of a specific tweet by ID |
search_count | append | Contains search count data |
dm_event | append | Contains information about a direct message event |
problem | append | Contains information about a problem |
list | append | Contains information about a list |
get_2_users_by_username_username_response | append | Retrieves details of a specific user by username |
tweet | append | Contains information about a tweet |
openapus | append | Contains information about open API usage |
compliance_job | append | Contains information about compliance jobs |
get_2_spaces_id_response | append | Retrieves details of a specific space by ID |
get_2_lists_id_response | append | Retrieves details of a specific list by ID |
space | append | Contains information about a space |
Additional pipeline guides
- Load data from IBM Db2 to AlloyDB in python with dlt
- Load data from The Local Filesystem to Timescale in python with dlt
- Load data from HubSpot to EDB BigAnimal in python with dlt
- Load data from X to Microsoft SQL Server in python with dlt
- Load data from Google Cloud Storage to Snowflake in python with dlt
- Load data from Notion to The Local Filesystem in python with dlt
- Load data from Chargebee to Google Cloud Storage in python with dlt
- Load data from Google Sheets to Azure Cosmos DB in python with dlt
- Load data from Star Trek to Redshift in python with dlt
- Load data from Cisco Meraki to MotherDuck in python with dlt