Skip to main content

Unofficial Treasure Workflow API client

Project description

Unofficial Treasure Workflow API client.

Installation

pip install tdworkflow

If you want to use development version, run as follows:

pip install git+https://github.com/chezou/tdworkflow.git

Usage

import os

from tdworkflow.client import Client

apikey = os.getenv("TD_API_KEY")
client = Client(site="us", apikey=apikey)
# Or, write endpoint explicitly
# client = Client(endpoint="api-workflow.treasuredata.com", apikey=apikey)

projects = client.projects("pandas-df")

secrets = {"td.apikey": apikey, "td.apiserver": "https://api.treasuredata.com", "test": "secret-foo"}

client.set_secrets(projects[0], secrets)

client.secrets(projects[0])
# ['td.apikey', 'td.apiserver', "test"]
client.delete_secrets(projects[0], ["test", "td.apiserver"])

Uplaod Project from GitHub

Before executing example code, you have to install git-python

pip install gitpython

Clone example repository with git-python and upload a digdag project.

import tempfile
import os
import shutil

import tdworkflow

from git import Git

# Download example GitHub repositoory

tempdir = tempfile.gettempdir()

git_repo = "https://github.com/treasure-data/treasure-boxes/"

shutil.rmtree(os.path.join(tempdir, "treasure-boxes"))

try:
    Git(tempdir).clone(git_repo)
    print("Clone repository succeeded")
except Exception:
    print("Repository clone failed")
    raise

# Upload specific Workflow project

apikey = os.getenv("TD_API_KEY")
site = "us"

target_box = os.path.join("integration-box", "python")
target_path = os.path.join(tempdir, "treasure-boxes", target_box)

client = tdworkflow.client.Client(site=site, apikey=apikey)
project = client.create_project("my-project", target_path)

If you want to open Treasure Workflow console on your browser, you can get the workflow URL as the following:

CONSOLE_URL = {
    "us": "https://console.treasuredata.com/app/workflows",
    "eu01": "https://console.eu01.treasuredata.com/app/workflows",
    "jp": "https://console.treasuredata.co.jp/app/workflows",
}

workflows = client.project_workflows(project)
workflows = list(filter(lambda w: w.name != "test", workflows))
if workflows:
    print(f"Project created! Open {CONSOLE_URL[site]}/{workflows[0].id}/info on your browser and clieck 'New Run' button.")
else:
    print("Project creation failed.")

Start workflow session

You can start workflow session by using Client.start_attempt.

attempt = client.start_attempt(workflows[0])

# Wait attempt until finish. This may require few minutes.
attempt = client.wait_attempt(attempt)

Connect to open source digdag

Since Treasure Workflow is hosted digdag, tdworkflow is compatible with open source digdag.

Here is the example code to connect local digdag server.

>>> import tdworkflow
>>> import requests
>>> session = requests.Session()
>>> client = tdworkflow.client.Client(
... endpoint="localhost:65432", apikey="", _session=session, scheme="http")
>>> client.projects()
[Project(id=1, name='python-tdworkflow', revision='134fe2f9-ded3-4e7c-af8e-8a82d55d688b', archiveType='db', archiveMd5='5Lc6F6m3DtmBN4DA5MzK8A==', createdAt='2019-11-01T13:03:26Z', deletedAt=None, updatedAt='2019-11-01T13:03:26Z')]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tdworkflow-0.5.1.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

tdworkflow-0.5.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file tdworkflow-0.5.1.tar.gz.

File metadata

  • Download URL: tdworkflow-0.5.1.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for tdworkflow-0.5.1.tar.gz
Algorithm Hash digest
SHA256 aaac5e8694e84b649dc1bebf021a9126b361f9fe02bcf18f36088a92d0612e5e
MD5 87da9e2871312f3150ebac8ea7fef058
BLAKE2b-256 0362343434bbbf4a906a056d95864dff3c29eedd506ef9d71cd59970a55073f1

See more details on using hashes here.

File details

Details for the file tdworkflow-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: tdworkflow-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for tdworkflow-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 965f76ce9b41ca0096d61f462ead3e30a792d4047e68c19c06c7147410f34256
MD5 935a91835ea4c70d4005cad729b2687a
BLAKE2b-256 1e51afb2e8e426cd1d21b4917e7074cf1bbff069a171355cc252b3ffb914aae4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page