Skip to content

Add option to return bytes stream to workbooks.download() method #811

Closed

Description

@YevhenKv

Hi,

It would be nice if workbooks.download() method could also return bytes stream for downloaded object. For example, add argument stream=True/False to download function that would define whether object should be downloaded into specified path or returned as a byte stream.
https://github.com/tableau/server-client-python/blob/master/tableauserverclient/server/endpoint/workbooks_endpoint.py#L134
In this case byte stream can be handled outside of library, for example it can be used to write data in AWS S3 bucket, GCS bucket or Azure Blob storage instead of local storage.

Example:
def download(self, workbook_id, filepath=None, include_extract=True, no_extract=None, stream=False):
if not workbook_id:
error = "Workbook ID undefined."
raise ValueError(error)
url = "{0}/{1}/content".format(self.baseurl, workbook_id)

if no_extract is False or no_extract is True:
    import warnings
    warnings.warn('no_extract is deprecated, use include_extract instead.', DeprecationWarning)
    include_extract = not no_extract

if not include_extract:
    url += "?includeExtract=False"

with closing(self.get_request(url, parameters={"stream": True})) as server_response:
    _, params = cgi.parse_header(server_response.headers['Content-Disposition'])
    filename = to_filename(os.path.basename(params['filename']))
    if filepath:
        download_path = make_download_path(filepath, filename)

        with open(download_path, 'wb') as f:
            for chunk in server_response.iter_content(1024):  # 1KB
                f.write(chunk)
        logger.info('Downloaded workbook to {0} (ID: {1})'.format(download_path, workbook_id))
        return os.path.abspath(download_path)
    if stream:
        return server_response.content

Activity

  1. SandervandenOord commented on May 22, 2022

    @SandervandenOord

    Agree, now I first have to write to disk and then write to a cloud storage bucket

  2. github-actions commented on Aug 6, 2026

    @github-actions

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. If this is still relevant, please comment to keep it open.

  3. github-actions commented on Aug 21, 2026

    @github-actions

    Closing due to inactivity. If this is still relevant, please reopen or file a new issue.

  4. jacalata commented on Aug 21, 2026

    @jacalata
    Contributor

    workbooks.download() and download_revision() accept a file-like object as filepath. Pass io.BytesIO() and the bytes stream is populated in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions