8000 Merge pull request #93 from tableau/development · irislips/server-client-python@e6262be · GitHub
[go: up one dir, main page]

Skip to content

Commit e6262be

Browse files
author
Russell Hay
authored
Merge pull request tableau#93 from tableau/development
Release v0.2
2 parents f140f8a + 79e9a2a commit e6262be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2137
-553
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ docs/_build/
6666
# PyBuilder
6767
target/
6868

69+
# PyCharm stuff
70+
.idea/
71+
6972
# IPython Notebook
7073
.ipynb_checkpoints
7174

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## 0.2 (02 November 2016)
2+
3+
* Added Initial Schedules Support (#48)
4+
* Added Initial Create Group endpoint (#69)
5+
* Added Connection Credentials for publishing datasources/workbooks (#80)
6+
* Added Pager object for handling pagination results and sample (#72, #90)
7+
* Added ServerInfo endpoint (#84)
8+
* Deprecated `site` as a parameter to `TableauAuth` in favor of `site_id`
9+
* Code Cleanup
10+
* Bugfixes
11+
12+
## 0.1 (12 September 2016)
13+
14+
* Initial Release to the world

CONTRIBUTORS.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This project wouldn't be possible without our amazing contributors.
2+
3+
The following people have contributed to this project to make it possible, and we thank them for their contributions!
4+
5+
## Contributors
6+
7+
* [geordielad](https://github.com/geordielad)
8+
* [kovner](https://github.com/kovner)
9+
10+
11+
## Core Team
12+
13+
* [shinchris](https://github.com/shinchris)
14+
* [lgraber](https://github.com/lgraber)
15+
* [t8y8](https://github.com/t8y8)
16+
* [RussTheAerialist](https://github.com/RussTheAerialist)

samples/create_group.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
####
2+
# This script demonstrates how to create groups using the Tableau
3+
# Server Client.
4+
#
5+
# To run the script, you must have installed Python 2.7.9 or later.
6+
####
7+
8+
9+
import argparse
10+
import getpass
11+
import logging
12+
13+
from datetime import time
14+
15+
import tableauserverclient as TSC
16+
17+
18+
def main():
19+
20+
parser = argparse.ArgumentParser(description='Creates sample schedules for each type of frequency.')
21+
parser.add_argument('--server', '-s', required=True, help='server address')
22+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
23+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
24+
help='desired logging level (set to error by default)')
25+
args = parser.parse_args()
26+
27+
password = getpass.getpass("Password: ")
28+
29+
# Set logging level based on user input, or error by default
30+
logging_level = getattr(logging, args.logging_level.upper())
31+
logging.basicConfig(level=logging_level)
32+
33+
tableau_auth = TSC.TableauAuth(args.username, password)
34+
server = TSC.Server(args.server)
35+
with server.auth.sign_in(tableau_auth):
36+
group = TSC.GroupItem('test')
37+
group = server.groups.create(group)
38+
print(group)
39+
40+
41+
if __name__ == '__main__':
42+
main()

samples/create_schedules.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
####
2+
# This script demonstrates how to create schedules using the Tableau
3+
# Server Client.
4+
#
5+
# To run the script, you must have installed Python 2.7.9 or later.
6+
####
7+
8+
9+
import argparse
10+
import getpass
11+
import logging
12+
13+
from datetime import time
14+
15+
import tableauserverclient as TSC
16+
17+
18+
def main():
19+
20+
parser = argparse.ArgumentParser(description='Creates sample schedules for each type of frequency.')
21+
parser.add_argument('--server', '-s', required=True, help='server address')
22+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
23+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
24+
help='desired logging level (set to error by default)')
25+
args = parser.parse_args()
26+
27+
password = getpass.getpass("Password: ")
28+
29+
# Set logging level based on user input, or error by default
30+
logging_level = getattr(logging, args.logging_level.upper())
31+
logging.basicConfig(level=logging_level)
32+
33+
tableau_auth = TSC.TableauAuth(args.username, password)
34+
server = TSC.Server(args.server)
35+
with server.auth.sign_in(tableau_auth):
36+
# Hourly Schedule
37+
# This schedule will run every 2 hours between 2:30AM and 11:00PM
38+
hourly_interval = TSC.HourlyInterval(start_time=time(2, 30),
39+
end_time=time(23, 0),
40+
interval_value=2)
41+
42+
hourly_schedule = TSC.ScheduleItem("Hourly-Schedule", 50, TSC.ScheduleItem.Type.Extract,
43+
TSC.ScheduleItem.ExecutionOrder.Parallel, hourly_interval)
44+
hourly_schedule = server.schedules.create(hourly_schedule)
45+
print("Hourly schedule created (ID: {}).".format(hourly_schedule.id))
46+
47+
# Daily Schedule
48+
# This schedule will run every day at 5AM
49+
daily_interval = TSC.DailyInterval(start_time=time(5))
50+
daily_schedule = TSC.ScheduleItem("Daily-Schedule", 60, TSC.ScheduleItem.Type.Subscription,
51+
TSC.ScheduleItem.ExecutionOrder.Serial, daily_interval)
52+
daily_schedule = server.schedules.create(daily_schedule)
53+
print("Daily schedule created (ID: {}).".format(daily_schedule.id))
54+
55+
# Weekly Schedule
56+
# This schedule will wun every Monday, Wednesday, and Friday at 7:15PM
57+
weekly_interval = TSC.WeeklyInterval(time(19, 15),
58+
TSC.IntervalItem.Day.Monday,
59+
TSC.IntervalItem.Day.Wednesday,
60+
TSC.IntervalItem.Day.Friday)
61+
weekly_schedule = TSC.ScheduleItem("Weekly-Schedule", 70, TSC.ScheduleItem.Type.Extract,
62+
TSC.ScheduleItem.ExecutionOrder.Serial, weekly_interval)
63+
weekly_schedule = server.schedules.create(weekly_schedule)
64+
print("Weekly schedule created (ID: {}).".format(weekly_schedule.id))
65+
66+
# Monthly Schedule
67+
# This schedule will run on the 15th of every month at 11:30PM
68+
monthly_interval = TSC.MonthlyInterval(start_time=time(23, 30),
69+
interval_value=15)
70+
monthly_schedule = TSC.ScheduleItem("Monthly-Schedule", 80, TSC.ScheduleItem.Type.Subscription,
71+
TSC.ScheduleItem.ExecutionOrder.Parallel, monthly_interval)
72+
monthly_schedule = server.schedules.create(monthly_schedule)
73+
print("Monthly schedule created (ID: {}).".format(monthly_schedule.id))
74+
75+
76+
if __name__ == '__main__':
77+
main()

samples/explore_datasource.py

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
####
2-
# This script demonstrates how to use the Tableau Server API
2+
# This script demonstrates how to use the Tableau Server Client
33
# to interact with datasources. It explores the different
44
# functions that the Server API supports on datasources.
55
#
@@ -9,56 +9,64 @@
99
# on top of the general operations.
1010
####
1111

12-
13-
import tableauserverclient as TSC
14-
import os.path
1512
import argparse
1613
import getpass
1714
import logging
1815

19-
parser = argparse.ArgumentParser(description='Explore datasource functions supported by the Server API.')
20-
parser.add_argument('--server', '-s', required=True, help='server address')
21-
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
22-
parser.add_argument('--publish', '-p', metavar='FILEPATH', help='path to datasource to publish')
23-
parser.add_argument('--download', '-d', metavar='FILEPATH', help='path to save downloaded datasource')
24-
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
25-
help='desired logging level (set to error by default)')
26-
args = parser.parse_args()
16+
import tableauserverclient as TSC
17+
18+
19+
def main():
20+
21+
parser = argparse.ArgumentParser(description='Explore datasource functions supported by the Server API.')
22+
parser.add_argument('--server', '-s', required=True, help='server address')
23+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
24+
parser.add_argument('--publish', '-p', metavar='FILEPATH', help='path to datasource to publish')
25+
parser.add_argument('--download', '-d', metavar='FILEPATH', help='path to save downloaded datasource')
26+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
27+
help='desired logging level (set to error by default)')
28+
29+
args = parser.parse_args()
30+
31+
password = getpass.getpass("Password: ")
32+
33+
# Set logging level based on user input, or error by default
34+
logging_level = getattr(logging, args.logging_level.upper())
35+
logging.basicConfig(level=logging_level)
2736

28-
password = getpass.getpass("Password: ")
37+
# SIGN IN
38+
tableau_auth = TSC.TableauAuth(args.username, password)
39+
server = TSC.Server(args.server)
40+
with server.auth.sign_in(tableau_auth):
41+
# Query projects for use when demonstrating publishing and updating
42+
all_projects, pagination_item = server.projects.get()
43+
default_project = next((project for project in all_projects if project.is_default()), None)
2944

30-
# Set logging level based on user input, or error by default
31-
logging_level = getattr(logging, args.logging_level.upper())
32-
logging.basicConfig(level=logging_level)
45+
# Publish datasource if publish flag is set (-publish, -p)
46+
if args.publish:
47+
if default_project is not None:
48+
new_datasource = TSC.DatasourceItem(default_project.id)
49+
new_datasource = server.datasources.publish(
50+
new_datasource, args.publish, TSC.Server.PublishMode.Overwrite)
51+
print("Datasource published. ID: {}".format(new_datasource.id))
52+
else:
53+
print("Publish failed. Could not find the default project.")
3354

34-
# SIGN IN
35-
tableau_auth = TSC.TableauAuth(args.username, password)
36-
server = TSC.Server(args.server)
37-
with server.auth.sign_in(tableau_auth):
38-
# Query projects for use when demonstrating publishing and updating
39-
all_projects, pagination_item = server.projects.get()
40-
default_project = next((project for project in all_projects if project.is_default()), None)
55+
# Gets all datasource items
56+
all_datasources, pagination_item = server.datasources.get()
57+
print("\nThere are {} datasources on site: ".format(pagination_item.total_available))
58+
print([datasource.name for datasource in all_datasources])
4159

42-
# Publish datasource if publish flag is set (-publish, -p)
43-
if args.publish:
44-
if default_project is not None:
45-
new_datasource = TSC.DatasourceItem(default_project.id)
46-
new_datasource = server.datasources.publish(new_datasource, args.publish, server.PublishMode.Overwrite)
47-
print("Datasource published. ID: {}".format(new_datasource.id))
48-
else:
49-
print("Publish failed. Could not find the default project.")
60+
if all_datasources:
61+
# Pick one datasource from the list
62+
sample_datasource = all_datasources[0]
5063

51-
# Gets all datasource items
52-
all_datasources, pagination_item = server.datasources.get()
53-
print("\nThere are {} datasources on site: ".format(pagination_item.total_available))
54-
print([datasource.name for datasource in all_datasources])
64+
# Populate connections
65+
server.datasources.populate_connections(sample_datasource)
66+
print("\nConnections for {}: ".format(sample_datasource.name))
67+
print(["{0}({1})".format(connection.id, connection.datasource_name)
68+
for connection in sample_datasource.connections])
5569

56-
if all_datasources:
57-
# Pick one datasource from the list
58-
sample_datasource = all_datasources[0]
5970

60-
# Populate connections
61-
server.datasources.populate_connections(sample_datasource)
62-
print("\nConnections for {}: ".format(sample_datasource.name))
63-
print(["{0}({1})".format(connection.id, connection.datasource_name)
64-
for connection in sample_datasource.connections])
71+
if __name__ == '__main__':
72+
main()

0 commit comments

Comments
 (0)
0