Communitygithub.com

dlt(資料載入工具)— 以 Python 為優先的資料擷取

你是一位 dlt 專家,dlt 是用於建立資料管線的開源 Python 函式庫。你協助開發人員使用簡單的 Python 裝飾器,從任何 API、檔案或資料庫將資料載入倉儲與資料湖,具備自動綱要推論、增量載入及內建資料合約。dlt 是「資料管線的 requests 函式庫」。

dlt(資料載入工具)— 以 Python 為優先的資料擷取 是什麼?

dlt(Data Load Tool)是一個開源的 Python 函式庫,專為簡化資料管線的建置而設計。它讓開發者能透過簡單的 Python 裝飾器(例如 `@dlt.resource`),從任何 API、檔案或資料庫中提取資料,並載入到如 BigQuery、Snowflake、PostgreSQL、DuckDB 等資料倉儲或資料湖中。dlt 會自動推論資料綱要、支援增量載入(透過追蹤游標避免重複處理),並提供內建的資料合約機制,讓使用者能控制其管線的演化行為(例如固定或允許綱要演變)。dlt 的設計哲學是「資料管線的 requests 函式庫」,強調以 Python 為中心、無需繁瑣設定的開發體驗。它支援多種部署情境,包括本地開發(以 DuckDB 作為目的地)、以及透過 cron、Airflow、Dagster、GitHub Actions 或 Lambda 等排程工具進行生產環境部署。

相容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/TerminalSkills/skills/tree/HEAD/skills/dlt

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

dlt(Data Load Tool)— Python-First 資料擷取

您是 dlt 的專家,dlt 是一個用於建立資料管線的開源 Python 函式庫。您協助開發人員使用簡單的 Python 裝飾器,從任何 API、檔案或資料庫中載入資料到倉儲與資料湖中,具備自動綱要推論、增量載入及內建資料合約。dlt 是「資料管線的 requests 函式庫」。

核心功能

基本管線

import dlt

# 最簡單的管線:Python generator → 倉儲
@dlt.resource(write_disposition="append")
def github_events():
    """載入 GitHub 事件的儲存庫。"""
    import requests
    response = requests.get("https://api.github.com/repos/org/repo/events")
    yield from response.json()

# 執行管線
pipeline = dlt.pipeline(
    pipeline_name="github_events",
    destination="bigquery",               # 或:postgres, snowflake, duckdb, motherduck
    dataset_name="raw_github",
)
load_info = pipeline.run(github_events())
print(load_info)                          # 綱要自動推論

增量載入

@dlt.resource(
    write_disposition="merge",            # Upsert:更新既有、插入新增
    primary_key="id",
)
def orders(
    updated_at=dlt.sources.incremental(
        "updated_at",
        initial_value="2025-01-01T00:00:00Z"
    )
):
    """增量載入訂單 — 僅載入上次執行後新增/變更的資料。

    dlt 會在每次執行之間自動追蹤游標。
    無需手動記錄狀態。
    """
    import requests
    page = 1
    while True:
        response = requests.get("https://api.shop.com/orders", params={
            "updated_after": updated_at.last_value,
            "page": page,
            "per_page": 100,
        })
        data = response.json()
        if not data:
            break
        yield from data
        page += 1

REST API 來源(宣告式)

from dlt.sources.rest_api import rest_api_source

# 宣告式 API 來源 — 標準 REST API 無需撰寫程式碼
source = rest_api_source({
    "client": {
        "base_url": "https://api.hubspot.com/crm/v3/",
        "auth": { "type": "bearer", "token": dlt.secrets["hubspot_token"] },
        "paginator": { "type": "offset", "limit": 100, "offset_param": "offset" },
    },
    "resources": [
        {
            "name": "contacts",
            "endpoint": { "path": "objects/contacts" },
            "write_disposition": "merge",
            "primary_key": "id",
        },
        {
            "name": "deals",
            "endpoint": { "path": "objects/deals" },
            "write_disposition": "merge",
            "primary_key": "id",
        },
    ],
})

pipeline = dlt.pipeline(destination="bigquery", dataset_name="raw_hubspot")
pipeline.run(source)

資料合約

# 強制綱要合約 — 在意外變更時明確失敗
@dlt.resource(
    write_disposition="merge",
    primary_key="id",
    columns={
        "id": {"data_type": "bigint", "nullable": False},
        "email": {"data_type": "text", "nullable": False},
        "plan": {"data_type": "text", "nullable": False},
        "mrr_cents": {"data_type": "bigint"},
    },
    schema_contract="evolve",             # "freeze" | "evolve" | "discard_value" | "discard_row"
)
def customers():
    # 如果 API 回傳意外欄位,dlt 會根據合約設定處理
    yield from fetch_customers()

安裝

pip install dlt[bigquery]                 # + 目的地適配器
# 其他目的地:dlt[snowflake], dlt[postgres], dlt[duckdb], dlt[motherduck]

最佳實務

  1. 從 DuckDB 開始 — 以 destination="duckdb" 進行本地開發,生產時切換至 BigQuery/Snowflake
  2. 對 API 使用增量載入 — 使用 dlt.sources.incremental 實現有狀態載入;dlt 會自動在執行期間追蹤游標
  3. REST API 來源 — 標準 REST API 使用宣告式的 rest_api_source;僅對複雜 API 撰寫自訂資源
  4. 合併實體 — 對實體表使用 write_disposition="merge" 搭配 primary_key;事件串流則使用 append
  5. 綱要合約 — 在生產環境設定 schema_contract="freeze" 以立即捕捉破壞性 API 變更
  6. 機密管理 — 使用以環境變數或 .dlt/secrets.toml 支援的 dlt.secrets["key"]
  7. 轉換 — 在載入過程中使用 add_map() 進行逐列轉換;較重的轉換應交由 dbt
  8. 隨處部署 — dlt 是函式庫而非服務;可透過 cron、Airflow、Dagster、GitHub Actions 或 Lambda 部署

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

TerminalSkills/skills

>- Run GitHub Actions locally with act. Use when a user asks to test GitHub Actions workflows locally, debug CI pipelines without pushing, or run workflows offline.

TerminalSkills/skills

>- You are an expert in AG2 (formerly AutoGen), the open-source multi-agent conversation framework. You help developers build systems where multiple AI agents collaborate through structured conversations — with tool use, human-in-the-loop, code execution, group chat orchestration, and nested conversations — for complex tasks like software development, research, and data analysis.

TerminalSkills/skills

>- Generate short-form videos with AI — script writing, text-to-speech narration, stock footage selection, subtitle generation, and video assembly. Use when: creating TikTok/YouTube Shorts/Reels content, automating video production, building content pipelines.

TerminalSkills/skills

>- Animate 3D objects and characters in Blender with Python. Use when the user wants to keyframe properties, create armatures and rigs, set up IK/FK chains, animate shape keys for facial animation, edit F-Curves, use the NLA editor to blend actions, add drivers for expression-based animation, or script any animation workflow in Blender.

TerminalSkills/skills

>- Automate motion capture and tracking workflows in Blender with Python. Use when the user wants to import BVH or FBX mocap data, retarget motion to armatures, track camera or object motion from video, solve camera motion, clean up motion capture data, or script any tracking pipeline in Blender.

TerminalSkills/skills

>- You are an expert in Bolt.new by StackBlitz, the AI-powered full-stack development environment that runs entirely in the browser. You help developers go from idea to deployed app in minutes using natural language prompts — Bolt generates complete applications with frontend, backend, database, and deployment, all running in a WebContainer without local setup.

TerminalSkills/skills

>- Assists with using Bun as an all-in-one JavaScript/TypeScript runtime, package manager, bundler, and test runner. Use when building HTTP servers, managing packages, running tests, or migrating from Node.js. Trigger words: bun, bun serve, bun install, bun test, bun build, javascript runtime, bun runtime.

TerminalSkills/skills

>- Self-host customer support with Chatwoot. Use when a user asks to set up open-source customer support, add live chat without SaaS costs, build a multi-channel inbox, or deploy a free Intercom alternative.

TerminalSkills/skills

>- You are an expert in Chi, the lightweight, idiomatic Go HTTP router built on `net/http`. You help developers build composable HTTP services using Chi's middleware stack, route groups, URL parameters, sub-routers, and context-based request scoping — providing Express-like ergonomics while staying 100% compatible with Go's standard library.

TerminalSkills/skills

When the user wants to edit, review, or improve existing marketing copy. Also use when the user mentions 'edit this copy,' 'review my copy,' 'copy feedback,' 'proofread,' 'polish this,' 'make this better,' or 'copy sweep.' This skill provides a systematic approach to editing marketing copy through multiple focused passes.

TerminalSkills/skills

>- Add live chat and customer support with Crisp. Use when a user asks to add a chat widget, implement live customer support, set up a help desk, create a knowledge base, or add a chatbot to a website.

TerminalSkills/skills

>- Assists with building custom interactive data visualizations using D3.js. Use when creating charts, graphs, maps, force layouts, or hierarchical diagrams that require fine-grained control beyond what charting libraries provide. Trigger words: d3, data visualization, chart, svg, scales, force graph, treemap, choropleth.

TerminalSkills/skills

dbt (data build tool) transforms data in your warehouse using SQL SELECT statements. Learn project setup, models, tests, documentation, incremental materializations, and integration with data warehouses like PostgreSQL, BigQuery, and Snowflake.

TerminalSkills/skills

Data Version Control for ML projects. Track large datasets and models alongside Git, build reproducible ML pipelines, and run experiments with metric comparison. Works with any storage backend including S3, GCS, Azure, and local filesystems.

TerminalSkills/skills

>- You are an expert in E2B, the cloud platform for running AI-generated code in secure sandboxes. You help developers give AI agents the ability to execute code, install packages, read/write files, and run long processes in isolated cloud environments — each sandbox is a lightweight VM that boots in ~150ms with full Linux, filesystem, and networking.

TerminalSkills/skills

>- Transcode, convert, edit, and process audio and video with FFmpeg. Use when a user asks to convert video formats (webm to mp4, mkv to mp4), extract audio from video, compress video files, trim or cut clips, concatenate videos, add subtitles, create thumbnails, apply filters, change resolution or bitrate, re-encode media, create GIFs from video, add watermarks, normalize audio, stream media, or build automated media processing pipelines.

TerminalSkills/skills

>- Create advanced animations with GSAP. Use when building complex timelines, scroll-driven animations, SVG morphing, text animations, or high-performance web animations beyond CSS capabilities.

TerminalSkills/skills

>- Generate deterministic MP4 videos from HTML, CSS, media, and seekable animations using HeyGen's HyperFrames framework. Use when someone asks to "render HTML to video", "make a video with HyperFrames", "create a programmatic video", "turn an animation into MP4", "build a launch/product video from HTML", "render GSAP/Lottie/Three.js to video", or set up an agent-driven video pipeline. Covers init/preview/render/add/lint/inspect commands, data-* timing attributes, animation adapters, and the component catalog.

TerminalSkills/skills

When the user wants to perform load testing, stress testing, or performance testing of APIs and websites using k6. Also use when the user mentions "k6," "load test," "performance test," "stress test," "spike test," "soak test," "thresholds," "virtual users," or "VUs." For browser-based testing, see selenium.

TerminalSkills/skills

>- Lovable (formerly GPT Engineer) is a browser-based AI app builder that turns a natural-language description into a working full-stack web app with a built-in backend, authentication, database and one-click publishing. Use when the user wants to prototype or ship a web app with Lovable, write effective Lovable prompts, connect Supabase or GitHub, review generated security rules, or move a Lovable project into their own editor.

相關技能