Treasure Data API Library for Python

1.7.0 · active · verified Wed Apr 15

The `td-client` Python library provides a wrapper for the Treasure Data API (REST API), allowing users to programmatically interact with Treasure Data services. It enables tasks such as managing databases and tables, issuing queries (including asynchronous execution), and performing bulk data imports. The library is currently at version 1.7.0 and is actively maintained with consistent updates.

Warnings

Install

Imports

Quickstart

This quickstart initializes the `td-client` with an API key (preferably from an environment variable) and then lists the 20 most recent jobs in your Treasure Data account. It demonstrates basic client setup and interaction.

import os
import tdclient

# Ensure TD_API_KEY environment variable is set with your Treasure Data API key.
# Optionally, set TD_API_SERVER to override the default endpoint (https://api.treasuredata.com).
# Example: export TD_API_KEY="YOUR_TREASURE_DATA_API_KEY"
# Example: export TD_API_SERVER="https://api.us01.treasuredata.com"

api_key = os.environ.get("TD_API_KEY", "")
api_server = os.environ.get("TD_API_SERVER", "https://api.treasuredata.com")

if not api_key:
    raise ValueError("TD_API_KEY environment variable not set. Please set it to your Treasure Data API key.")

try:
    with tdclient.Client(apikey=api_key, endpoint=api_server) as client:
        print("Listing recent jobs:")
        # Retrieve and print details of the 20 most recent jobs
        for job in client.jobs():
            print(f"  Job ID: {job.job_id}, Type: {job.type}, Status: {job.status}, Created At: {job.created_at}")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →