pytd

Query Treasure Data via Presto or Hive and load pandas DataFrames.

21|24|Updated Oct 21, 2025
One-click install
npx skills add https://github.com/treasure-data/td-skills --skill pytd
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytd
Source: https://github.com/treasure-data/td-skills/tree/main/sdk-skills/python
Command: npx skills add https://github.com/treasure-data/td-skills --skill pytd

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytd, pandas.

What problem does it solve?

This Skill provides expert assistance for using pytd (Python SDK) to query and import data with Treasure Data, streamlining Python-based data analysis, ETL pipelines, and integration with data science workflows. It helps users efficiently move data between pandas DataFrames and TD, reducing manual effort and potential errors.

Core Features & Use Cases

  • Query & Load: Seamlessly query TD data into pandas DataFrames and load DataFrames back to TD tables using various writer types (bulk_import, insert_into, spark).
  • Large Result Handling: Guides on using the DB-API for iterative retrieval of large result sets, preventing memory issues and timeouts in Python when processing massive datasets.
  • ETL Pipeline Patterns: Provides common patterns for building complete ETL workflows, including incremental loading and multi-database operations, ensuring robust and scalable data pipelines.
  • Use Case: A data scientist needs to pull a large dataset from TD, perform complex feature engineering using pandas, and then upload the transformed data back to TD for model training. This skill helps them use pytd for efficient data transfer, iterative processing, and robust error handling within their Python environment.

Quick Start

Install pytd

pip install pytd

Query data into a pandas DataFrame

import pytd import pandas as pd client = pytd.Client(database='sample_datasets') result = client.query('SELECT * FROM nasdaq LIMIT 100') df = pd.DataFrame(result['data'], columns=result['columns']) print(df.head())

Frequently Asked Questions about pytd

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I query data from Treasure Data into a pandas DataFrame?

Query data from Treasure Data into pandas using pytd's Client to execute SQL against Presto or Hive, then convert results into a DataFrame. Install pytd, configure a Client with your database and API credentials, call client.query() with your SQL, and construct a DataFrame from the returned columns and data.

Can I upload a pandas DataFrame back to Treasure Data?

Yes, pytd supports loading pandas DataFrames to TD tables using multiple writer types: bulk_import for high-volume data, insert_into for smaller batches, and spark for distributed processing. Choose the writer based on your data size and performance requirements.

How do I handle large result sets from Treasure Data without running out of memory?

Use pytd's DB-API for iterative retrieval of large datasets instead of loading everything at once. This prevents memory exhaustion and timeouts when processing massive result sets in Python, allowing you to fetch and process data in manageable chunks.

What Python and dependency versions does pytd require?

pytd requires Python 3.9 or later and pandas 2.0 or later. Ensure both are installed before using pytd for data querying and loading operations with Treasure Data.

Can I build ETL pipelines with pytd for incremental data loading?

Yes, pytd supports building complete ETL workflows including incremental loading and multi-database operations. Common patterns guide you through robust and scalable data pipeline design for moving and transforming data between pandas and Treasure Data.

What authentication does pytd need to connect to Treasure Data?

pytd requires a valid Treasure Data API key and server endpoint to establish connections. Configure these credentials when initializing the pytd Client along with your target database to execute queries and load data.