Data2 CLI for TSV Export

Jump to solution
canninga
Community Explorer

We are trying to use the CLI to run snapshot queries that result in a download of TSV files to a local server. We are not looking to have the files go straight to a database at this time. We tried the sample code below but are getting a syntax error. Does anyone have any advice? I apologize for my ignorance. Neither I nor the one working with the code is familiar with Python.

CLI Snapshot Code.png

 

Labels (3)
0 Likes
1 Solution
jwals
Community Participant

Hi @canninga, yes unfortunately the examples that Instructure provides are non-working code. Python's asyncio library requires that things look like my code below. However, you can also use the dap CLI utility directly from a command line and then you don't have to work with Python at all -- just run a command like dap snapshot --namespace canvas --table access_tokens --format tsv. Hope that helps!

import asyncio
import os
from dap.api import DAPClient
from dap.dap_types import Format, SnapshotQuery

async def download_files():
    output_directory = os.getcwd()
    async with DAPClient() as session:
        query = SnapshotQuery(format=Format.JSONL, filter=None)
        await session.download_table_data("canvas", "access_tokens", query, output_directory)

if __name__ == "__main__":
    asyncio.run(download_files())

 

View solution in original post