How to use the tableauserverclient.Server function in tableauserverclient

To help you get started, we’ve selected a few tableauserverclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tableau / server-client-python / test / test_metadata.py View on Github external
def setUp(self):
        self.server = TSC.Server('http://test')
        self.baseurl = self.server.metadata.baseurl
        self.server.version = "3.2"

        self.server._site_id = 'dad65087-b08b-4603-af4e-2887b8aafc67'
        self.server._auth_token = 'j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM'
github tableau / server-client-python / test / test_view.py View on Github external
def setUp(self):
        self.server = TSC.Server('http://test')
        self.server.version = '2.7'

        # Fake sign in
        self.server._site_id = 'dad65087-b08b-4603-af4e-2887b8aafc67'
        self.server._auth_token = 'j80k54ll2lfMZ0tv97mlPvvSCRyD0DOM'

        self.baseurl = self.server.views.baseurl
        self.siteurl = self.server.views.siteurl
github tableau / server-client-python / test / test_server_info.py View on Github external
def setUp(self):
        self.server = TSC.Server('http://test')
        self.baseurl = self.server.server_info.baseurl
        self.server.version = "2.4"
github tableau / server-client-python / samples / materialize_workbooks.py View on Github external
def update_project_by_path(args, materialized_views_config, password, site_content_url):
    if args.project_path is None:
        print("Use --project_path  to specify the path of the project")
        return False
    tableau_auth = TSC.TableauAuth(args.username, password, site_content_url)
    server = TSC.Server(args.server, use_server_version=True)
    project_name = args.project_path.split('/')[-1]
    with server.auth.sign_in(tableau_auth):
        if not assert_site_enabled_for_materialized_views(server, site_content_url):
            return False
        projects = [project for project in TSC.Pager(server.projects) if project.name == project_name]
        if not assert_project_valid(args.project_path, projects):
            return False

        possible_paths = get_project_paths(server, projects)
        update_project(possible_paths[args.project_path], server, materialized_views_config)
    return True
github tableau / server-client-python / samples / download_view_image.py View on Github external
help='desired logging level (set to error by default)')

    args = parser.parse_args()

    password = getpass.getpass("Password: ")

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # Step 1: Sign in to server.
    site_id = args.site_id
    if not site_id:
        site_id = ""
    tableau_auth = TSC.TableauAuth(args.username, password, site_id=site_id)
    server = TSC.Server(args.server)
    # The new endpoint was introduced in Version 2.5
    server.version = "2.5"

    with server.auth.sign_in(tableau_auth):
        # Step 2: Query for the view that we want an image of
        req_option = TSC.RequestOptions()
        req_option.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
                                         TSC.RequestOptions.Operator.Equals, args.view_name))
        all_views, pagination_item = server.views.get(req_option)
        if not all_views:
            raise LookupError("View with the specified name was not found.")
        view_item = all_views[0]

        # Step 3: Query the image endpoint and save the image to the specified location
        image_req_option = TSC.ImageRequestOptions(imageresolution=TSC.ImageRequestOptions.Resolution.High)
        server.views.populate_image(view_item, image_req_option)
github tableau / server-client-python / samples / tabcmd.py View on Github external
def set_server_from_session_file(self, site_id=None):
        udd = user_data_dir('Tabcmd', 'Tableau')

        with open(os.path.join(udd, "tabcmd-session.json"), 'r') as json_data:
            f = json.load(json_data)

            server = TSC.Server(f["base-url"])

            if not site_id is None:
                server._set_auth(site_id, f["user-id"], f["authenticity-token"])
            else:
                server._set_auth(f["site-id"], f["user-id"], f["authenticity-token"])
        
        return server
github tableau / server-client-python / samples / tabcmd.py View on Github external
## Replace
            if args.replace:
                publish_mode = TSC.Server.PublishMode.Overwrite
                
            extract_item = TSC.DatasourceItem(target_project.id, name)

            server.datasources.publish(extract_item, our_file, publish_mode)
        
        ##### Workbook
        elif our_file_type == self.TableauFileType.Workbook:
            print('Processing a workbook...')

            workbook_item = TSC.WorkbookItem(target_project.id, name, tabbed)

            if publish_mode == TSC.Server.PublishMode.Overwrite:
                # Use a filter to get the existing workbook
                request_options = TSC.RequestOptions()
                request_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, name))

                all_workbooks = list(TSC.Pager(server.workbooks, request_options))
                workbook_item = all_workbooks[0]
                workbook_item.show_tabs = tabbed

            server.workbooks.publish(workbook_item, our_file, publish_mode, connection_credentials)

        else:
            print('Invalid file type. Must be one of [".tde", ".tds(x)", ".twb(x)"]')
github tableau / server-client-python / samples / explore_workbook.py View on Github external
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')

    args = parser.parse_args()

    password = getpass.getpass("Password: ")

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    # SIGN IN
    tableau_auth = TSC.TableauAuth(args.username, password)
    server = TSC.Server(args.server)

    overwrite_true = TSC.Server.PublishMode.Overwrite

    with server.auth.sign_in(tableau_auth):

        # Publish workbook if publish flag is set (-publish, -p)
        if args.publish:
            all_projects, pagination_item = server.projects.get()
            default_project = next((project for project in all_projects if project.is_default()), None)

            if default_project is not None:
                new_workbook = TSC.WorkbookItem(default_project.id)
                new_workbook = server.workbooks.publish(new_workbook, args.publish, overwrite_true)
                print("Workbook published. ID: {}".format(new_workbook.id))
            else:
                print('Publish failed. Could not find the default project.')

        # Gets all workbook items
github tableau / server-client-python / samples / create_project.py View on Github external
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')

    args = parser.parse_args()

    if args.p is None:
        password = getpass.getpass("Password: ")
    else:
        password = args.p

    # Set logging level based on user input, or error by default
    logging_level = getattr(logging, args.logging_level.upper())
    logging.basicConfig(level=logging_level)

    tableau_auth = TSC.TableauAuth(args.username, password)
    server = TSC.Server(args.server)

    with server.auth.sign_in(tableau_auth):
        # Use highest Server REST API version available
        server.use_server_version()

        # Without parent_id specified, projects are created at the top level.
        top_level_project = TSC.ProjectItem(name='Top Level Project')
        top_level_project = create_project(server, top_level_project)

        # Specifying parent_id creates a nested projects.
        child_project = TSC.ProjectItem(name='Child Project', parent_id=top_level_project.id)
        child_project = create_project(server, child_project)

        # Projects can be nested at any level.
        grand_child_project = TSC.ProjectItem(name='Grand Child Project', parent_id=child_project.id)
        grand_child_project = create_project(server, grand_child_project)
github dataiku / dataiku-contrib / tableau-hyper-export / python-exporters / tableau-hyper_upload / exporter.py View on Github external
def close(self):
        """
        Perform any necessary cleanup
        """
        self.e.close()
        tableau_auth = TSC.TableauAuth(self.username, self.password, site_id=self.site_id)
        server = TSC.Server(self.server_url, use_server_version=True)
        
        server.auth.sign_in(tableau_auth)
        
        try:
            if self.datasource:
                server.datasources.publish(self.datasource, self.output_file, 'Overwrite', connection_credentials=None)
            else:
                new_datasource = TSC.DatasourceItem(self.project.id, name=self.output_table)
                new_datasource = server.datasources.publish(new_datasource, self.output_file, 'CreateNew')
        except:
            raise
        finally:
            server.auth.sign_out()
            os.remove(self.output_file)