Skip to content

Commit a82b555

Browse files
committed
Added 'getting started' samples
1 parent 66064c5 commit a82b555

File tree

3 files changed

+169
-0
lines changed

3 files changed

+169
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
####
2+
# Getting started Part One of Three
3+
# This script demonstrates how to use the Tableau Server Client to connect to a server
4+
# You don't need to have a site or any experience with Tableau to run it
5+
#
6+
####
7+
8+
import tableauserverclient as TSC
9+
10+
11+
def main():
12+
# This is the domain for Tableau's Developer Program
13+
server_url = "https://10ax.online.tableau.com"
14+
server = TSC.Server(server_url)
15+
print("Connected to {}".format(server.server_info.baseurl))
16+
print("Server information: {}".format(server.server_info))
17+
print("Sign up for a test site at https://www.tableau.com/developer")
18+
19+
20+
if __name__ == "__main__":
21+
main()
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
####
2+
# Getting started Part Two of Three
3+
# This script demonstrates how to use the Tableau Server Client to
4+
# view the content on an existing site on Tableau Server/Online
5+
# It assumes that you have already got a site and can visit it in a browser
6+
#
7+
####
8+
9+
import getpass
10+
import tableauserverclient as TSC
11+
12+
13+
# 0 - launch your Tableau site in a web browser and look at the url to set the values below
14+
def main():
15+
16+
# 1 - replace with your server domain: stop at the slash
17+
server_url = "https://10ax.online.tableau.com"
18+
19+
# 2 - optional - change to false **for testing only** if you get a certificate error
20+
use_ssl = True
21+
22+
server = TSC.Server(server_url, use_server_version=True, http_options={"verify": use_ssl})
23+
print("Connected to {}".format(server.server_info.baseurl))
24+
25+
# 3 - replace with your site name exactly as it looks in the url
26+
# e.g https://my-server/#/site/this-is-your-site-url-name/not-this-part
27+
site_url_name = "" # leave empty if there is no site name in the url (you are on the default site)
28+
29+
# 4 - replace with your username.
30+
# REMEMBER: if you are using Tableau Online, your username is the entire email address
31+
username = "your-username-here"
32+
password = getpass.getpass("Your password:") # so you don't save it in this file
33+
tableau_auth = TSC.TableauAuth(username, password, site_id=site_url_name)
34+
35+
# OR instead of username+password, uncomment this section to use a Personal Access Token
36+
# token_name = "your-token-name"
37+
# token_value = "your-token-value-long-random-string"
38+
# tableau_auth = TSC.PersonalAccessTokenAuth(token_name, token_value, site_id=site_url_name)
39+
40+
with server.auth.sign_in(tableau_auth):
41+
42+
projects, pagination = server.projects.get()
43+
if projects:
44+
print("{} projects".format(pagination.total_available))
45+
project = projects[0]
46+
print(project.name)
47+
48+
print("Done")
49+
50+
if __name__ == "__main__":
51+
main()
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
####
2+
# Getting Started Part Three of Three
3+
# This script demonstrates all the different types of 'content' a server contains
4+
#
5+
# To make it easy to run, it doesn't take any arguments - you need to edit the code with your info
6+
####
7+
8+
import getpass
9+
import tableauserverclient as TSC
10+
11+
12+
def main():
13+
# 1 - replace with your server url
14+
server_url = "https://10ax.online.tableau.com"
15+
16+
# 2 - change to false **for testing only** if you get a certificate error
17+
use_ssl = True
18+
server = TSC.Server(server_url, use_server_version=True, http_options={"verify": use_ssl})
19+
20+
print("Connected to {}".format(server.server_info.baseurl))
21+
22+
# 3 - replace with your site name exactly as it looks in a url
23+
# e.g https://my-server/#/this-is-your-site-url-name/
24+
site_url_name = "" # leave empty if there is no site name in the url (you are on the default site)
25+
26+
# 4
27+
username = "your-username-here"
28+
password = getpass.getpass("Your password:") # so you don't save it in this file
29+
tableau_auth = TSC.TableauAuth(username, password, site_id=site_url_name)
30+
31+
# OR instead of username+password, use a Personal Access Token (PAT) (required by Tableau Cloud)
32+
# token_name = "your-token-name"
33+
# token_value = "your-token-value-long-random-string"
34+
# tableau_auth = TSC.PersonalAccessTokenAuth(token_name, token_value, site_id=site_url_name)
35+
36+
with server.auth.sign_in(tableau_auth):
37+
38+
projects, pagination = server.projects.get()
39+
if projects:
40+
print("{} projects".format(pagination.total_available))
41+
for project in projects:
42+
print(project.name)
43+
44+
workbooks, pagination = server.datasources.get()
45+
if workbooks:
46+
print("{} workbooks".format(pagination.total_available))
47+
print(workbooks[0])
48+
49+
views, pagination = server.views.get()
50+
if views:
51+
print("{} views".format(pagination.total_available))
52+
print(views[0])
53+
54+
datasources, pagination = server.datasources.get()
55+
if datasources:
56+
print("{} datasources".format(pagination.total_available))
57+
print(datasources[0])
58+
59+
# I think all these other content types can go to a hello_universe script
60+
# data alert, dqw, flow, ... do any of these require any add-ons?
61+
jobs, pagination = server.jobs.get()
62+
if jobs:
63+
print("{} jobs".format(pagination.total_available))
64+
print(jobs[0])
65+
66+
metrics, pagination = server.metrics.get()
67+
if metrics:
68+
print("{} metrics".format(pagination.total_available))
69+
print(metrics[0])
70+
71+
schedules, pagination = server.schedules.get()
72+
if schedules:
73+
print("{} schedules".format(pagination.total_available))
74+
print(schedules[0])
75+
76+
tasks, pagination = server.tasks.get()
77+
if tasks:
78+
print("{} tasks".format(pagination.total_available))
79+
print(tasks[0])
80+
81+
webhooks, pagination = server.webhooks.get()
82+
if webhooks:
83+
print("{} webhooks".format(pagination.total_available))
84+
print(webhooks[0])
85+
86+
users, pagination = server.metrics.get()
87+
if users:
88+
print("{} users".format(pagination.total_available))
89+
print(users[0])
90+
91+
groups, pagination = server.groups.get()
92+
if groups:
93+
print("{} groups".format(pagination.total_available))
94+
print(groups[0])
95+
96+
if __name__ == "__main__":
97+
main()

0 commit comments

Comments
 (0)