Skip to content

Commit 15086b8

Browse files
authored
Added 'getting started' samples (#1263)
* Added 'getting started' samples
1 parent 90cf332 commit 15086b8

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
# 1 - replace with your server domain: stop at the slash
16+
server_url = "https://10ax.online.tableau.com"
17+
18+
# 2 - optional - change to false **for testing only** if you get a certificate error
19+
use_ssl = True
20+
21+
server = TSC.Server(server_url, use_server_version=True, http_options={"verify": use_ssl})
22+
print("Connected to {}".format(server.server_info.baseurl))
23+
24+
# 3 - replace with your site name exactly as it looks in the url
25+
# e.g https://my-server/#/site/this-is-your-site-url-name/not-this-part
26+
site_url_name = "" # leave empty if there is no site name in the url (you are on the default site)
27+
28+
# 4 - replace with your username.
29+
# REMEMBER: if you are using Tableau Online, your username is the entire email address
30+
username = "your-username-here"
31+
password = getpass.getpass("Your password:") # so you don't save it in this file
32+
tableau_auth = TSC.TableauAuth(username, password, site_id=site_url_name)
33+
34+
# OR instead of username+password, uncomment this section to use a Personal Access Token
35+
# token_name = "your-token-name"
36+
# token_value = "your-token-value-long-random-string"
37+
# tableau_auth = TSC.PersonalAccessTokenAuth(token_name, token_value, site_id=site_url_name)
38+
39+
with server.auth.sign_in(tableau_auth):
40+
projects, pagination = server.projects.get()
41+
if projects:
42+
print("{} projects".format(pagination.total_available))
43+
project = projects[0]
44+
print(project.name)
45+
46+
print("Done")
47+
48+
49+
if __name__ == "__main__":
50+
main()
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
projects, pagination = server.projects.get()
38+
if projects:
39+
print("{} projects".format(pagination.total_available))
40+
for project in projects:
41+
print(project.name)
42+
43+
workbooks, pagination = server.datasources.get()
44+
if workbooks:
45+
print("{} workbooks".format(pagination.total_available))
46+
print(workbooks[0])
47+
48+
views, pagination = server.views.get()
49+
if views:
50+
print("{} views".format(pagination.total_available))
51+
print(views[0])
52+
53+
datasources, pagination = server.datasources.get()
54+
if datasources:
55+
print("{} datasources".format(pagination.total_available))
56+
print(datasources[0])
57+
58+
# I think all these other content types can go to a hello_universe script
59+
# data alert, dqw, flow, ... do any of these require any add-ons?
60+
jobs, pagination = server.jobs.get()
61+
if jobs:
62+
print("{} jobs".format(pagination.total_available))
63+
print(jobs[0])
64+
65+
metrics, pagination = server.metrics.get()
66+
if metrics:
67+
print("{} metrics".format(pagination.total_available))
68+
print(metrics[0])
69+
70+
schedules, pagination = server.schedules.get()
71+
if schedules:
72+
print("{} schedules".format(pagination.total_available))
73+
print(schedules[0])
74+
75+
tasks, pagination = server.tasks.get()
76+
if tasks:
77+
print("{} tasks".format(pagination.total_available))
78+
print(tasks[0])
79+
80+
webhooks, pagination = server.webhooks.get()
81+
if webhooks:
82+
print("{} webhooks".format(pagination.total_available))
83+
print(webhooks[0])
84+
85+
users, pagination = server.metrics.get()
86+
if users:
87+
print("{} users".format(pagination.total_available))
88+
print(users[0])
89+
90+
groups, pagination = server.groups.get()
91+
if groups:
92+
print("{} groups".format(pagination.total_available))
93+
print(groups[0])
94+
95+
if __name__ == "__main__":
96+
main()

0 commit comments

Comments
 (0)