Twist Python API Docs | dltHub

Build a Twist-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.

Last updated:

Twist is a team communication platform with a REST API to access workspaces, channels, threads, messages, users, and integrations. The REST API base URL is https://api.twist.com/api/v3 and All requests require a Bearer token for authentication.

dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Twist data in under 10 minutes.


What data can I load from Twist?

Here are some of the endpoints you can load from Twist:

ResourceEndpointMethodData selectorDescription
users_get_session_user/api/v3/users/get_session_userGET(object)Get current user for token (returns a User object)
workspaces_getone/api/v3/workspaces/getoneGET(object)Get single workspace by id
channels_get/api/v3/channels/getGETdataGet all channels in a workspace
threads_get/api/v3/threads/getGETdataGet all threads in a channel
comments_get/api/v3/comments/getGETdataGet all comments in a thread
conversation_messages_get/api/v3/conversation_messages/getGETdataGet messages for a conversation
inbox_get/api/v3/inbox/getGETdataGet authenticated user's inbox (threads list)
search_query/api/v3/search/queryGETresultsFull-text search across workspace (returns paginated results and next_cursor_mark)
users_login/api/v3/users/loginPOST(object)Login user and retrieve user token (example for testing)
batch/api/v3/batchPOST(array of responses)Batch multiple requests into one HTTP call

How do I authenticate with the Twist API?

API uses OAuth2 for integrations and allows personal/test tokens for development. Authorized requests use the HTTP Authorization header: "Authorization: Bearer ".

1. Get your credentials

  1. Create an integration/app at Twist app console (https://twist.com/app_console/create_app). 2) Configure an OAuth redirect URL and note the Client ID and Client Secret. 3) Implement OAuth2 authorization code flow to obtain an access token, or use the integration's test token from the integration details for development. 4) For personal quick tests, you can also log in via POST /api/v3/users/login to get a user token (not for production integrations).

2. Add them to .dlt/secrets.toml

[sources.twist_source] token = "your_oauth_or_user_token_here"

dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.


How do I set up and run the pipeline?

Set up a virtual environment and install dlt:

uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"

1. Install the dlt AI Workbench:

dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex

This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →

2. Install the rest-api-pipeline toolkit:

dlt ai toolkit rest-api-pipeline install

This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →

3. Start LLM-assisted coding:

Use /find-source to load data from the Twist API into DuckDB.

The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.

4. Run the pipeline:

python twist_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline twist_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset twist_data The duckdb destination used duckdb:/twist.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline twist_pipeline show

This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.


Python pipeline example

This example loads channels_get and threads_get from the Twist API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:

import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def twist_source(token=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://api.twist.com/api/v3", "auth": { "type": "bearer", "token": token, }, }, "resources": [ {"name": "channels_get", "endpoint": {"path": "channels/get", "data_selector": "data"}}, {"name": "threads_get", "endpoint": {"path": "threads/get", "data_selector": "data"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="twist_pipeline", destination="duckdb", dataset_name="twist_data", ) load_info = pipeline.run(twist_source()) print(load_info)

To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.


How do I query the loaded data?

Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.

Python (pandas DataFrame):

import dlt data = dlt.pipeline("twist_pipeline").dataset() sessions_df = data.threads_get.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM twist_data.threads_get LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("twist_pipeline").dataset() data.threads_get.df().head()

See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.


What destinations can I load Twist data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample value
DuckDB (local, default)"duckdb"
PostgreSQL"postgres"
BigQuery"bigquery"
Snowflake"snowflake"
Redshift"redshift"
Databricks"databricks"
Filesystem (S3, GCS, Azure)"filesystem"

Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.


Troubleshooting

Authentication failures

If the Authorization header is missing, malformed, or contains an invalid token the API returns HTTP 401 with an error JSON (e.g., {"error_uuid":"...","error_code":200,"error_string":"Invalid token"} or {"error":"BAD_REQUEST","error_message":"Invalid scope"}). Ensure requests include: Authorization: Bearer <token>.

Rate limits and request size

Requests must respect body size limits (common limit 5 MB). The public docs do not publish a precise rate limit; handle 429 responses with exponential backoff. Use the /api/v3/batch endpoint to combine calls and reduce request count.

Pagination quirks

List endpoints accept parameters such as limit, newer_than_ts, older_than_ts, before_id, after_id or cursor_mark. The search endpoint returns next_cursor_mark for pagination. Comment and message endpoints also support from_obj_index, to_obj_index, and limit.

Common error formats

Errors are JSON objects. Example: { "error_uuid": "f699b0e0caa4446e847e17cc1d42801b", "error_code": 200, "error_extra": {}, "error_string": "Invalid token" }. HTTP status codes follow standard meanings (400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 500 Internal Server Error).

Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.


Next steps

Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:

  • data-exploration — Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.
  • dlthub-runtime — Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install

Was this page helpful?

Community Hub

Need more dlt context for Twist?

Request dlt skills, commands, AGENT.md files, and AI-native context.