Skip to content

Commit 1eeaca8

Browse files
authored
Prepare release 0.19 (#1049)
* Add new samples and delete redundant ones * Clean up hidden_views by making it an attribute of WorkbookItem * Add type hints for workbook and data source revisions, data alerts, Favorites, Flows, groups, permissions, projects, flow runs, site, subscriptions, Users, webhooks * add get_by_id method and test for schedules * Allow null value for user quota tiers * fix workbook.delete_extract * add publish to pypi action fix xml generation for items * Add Status, ParentProjectId and StartedAt filters for jobs endpoint * make project_id nullable to support "Personal Space" for workbooks * create single Credentials class * Reassign content on user removal * add redaction method to remove passwords when logging requests and responses, which can contain embedded credentials. * remove support for python 3.6 (add python version enforcement in setup.py) * Extract refreshable item IDs from job XML response * Do not eagerly fetch content when a stream was requested * Fix QuerySet slicing logic * add CRUD methods for default permissions * refactor Resource Types and add sample code
1 parent b9a10fd commit 1eeaca8

Some content is hidden

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

74 files changed

+789
-418
lines changed

.github/workflows/run-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
fail-fast: false
99
matrix:
1010
os: [ubuntu-latest, macos-latest, windows-latest]
11-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
11+
python-version: ['3.7', '3.8', '3.9', '3.10']
1212

1313
runs-on: ${{ matrix.os }}
1414

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ target/
7878

7979
# poetry
8080
poetry.lock
81-
pyproject.toml
8281

8382
# celery beat schedule file
8483
celerybeat-schedule

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Use the Tableau Server Client (TSC) library to increase your productivity as you
88
* Create users and groups.
99
* Query projects, sites, and more.
1010

11-
This repository contains Python source code for the library and sample files showing how to use it. Python versions 3.6 and up are supported.
11+
This repository contains Python source code for the library and sample files showing how to use it. As of May 2022, Python versions 3.7 and up are supported.
1212

1313
To see sample code that works directly with the REST API (in Java, Python, or Postman), visit the [REST API Samples](https://github.com/tableau/rest-api-samples) repo.
1414

publish.sh

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env bash
22

3+
# tag the release version and confirm a clean version number
4+
git tag vxxxx
5+
git describe --tag --dirty --always
6+
37
set -e
48

59
rm -rf dist
6-
python3 setup.py sdist
7-
python3 setup.py bdist_wheel
10+
python setup.py sdist bdist_wheel
811
twine upload dist/*

pyproject.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build-system]
2+
requires = ["setuptools>=45.0", "versioneer-518", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.black]
6+
line-length = 120
7+
target-version = ['py37', 'py38', 'py39', 'py310']
8+
9+
[tool.mypy]
10+
disable_error_code = [
11+
'misc',
12+
'import'
13+
]
14+
files = [
15+
"tableauserverclient",
16+
"test"
17+
]
18+
show_error_codes = true

samples/add_default_permission.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
####
22
# This script demonstrates how to add default permissions using TSC
3-
# To run the script, you must have installed Python 3.6 or later.
3+
# To run the script, you must have installed Python 3.7 or later.
44
#
55
# In order to demonstrate adding a new default permission, this sample will create
66
# a new project and add a new capability to the new project, for the default "All users" group.

samples/create_group.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This script demonstrates how to create a group using the Tableau
33
# Server Client.
44
#
5-
# To run the script, you must have installed Python 3.6 or later.
5+
# To run the script, you must have installed Python 3.7 or later.
66
####
77

88

samples/create_project.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# parent_id.
55
#
66
#
7-
# To run the script, you must have installed Python 3.6 or later.
7+
# To run the script, you must have installed Python 3.7 or later.
88
####
99

1010
import argparse
@@ -21,7 +21,8 @@ def create_project(server, project_item, samples=False):
2121
return project_item
2222
except TSC.ServerResponseError:
2323
print("We have already created this project: %s" % project_item.name)
24-
sys.exit(1)
24+
project_items = server.projects.filter(name=project_item.name)
25+
return project_items[0]
2526

2627

2728
def main():
@@ -52,7 +53,8 @@ def main():
5253
logging.basicConfig(level=logging_level)
5354

5455
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
55-
server = TSC.Server(args.server)
56+
server = TSC.Server(args.server, http_options={"verify": False})
57+
5658
server.use_server_version()
5759
with server.auth.sign_in(tableau_auth):
5860
# Use highest Server REST API version available
@@ -73,6 +75,21 @@ def main():
7375
# Projects can be updated
7476
changed_project = server.projects.update(grand_child_project, samples=True)
7577

78+
server.projects.populate_workbook_default_permissions(changed_project),
79+
server.projects.populate_flow_default_permissions(changed_project),
80+
server.projects.populate_lens_default_permissions(changed_project), # uses same as workbook
81+
server.projects.populate_datasource_default_permissions(changed_project),
82+
server.projects.populate_permissions(changed_project)
83+
# Projects have default permissions set for the object types they contain
84+
print("Permissions from project {}:".format(changed_project.id))
85+
print(changed_project.permissions)
86+
print(
87+
changed_project.default_workbook_permissions,
88+
changed_project.default_datasource_permissions,
89+
changed_project.default_lens_permissions,
90+
changed_project.default_flow_permissions,
91+
)
92+
7693

7794
if __name__ == "__main__":
7895
main()

samples/create_schedules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This script demonstrates how to create schedules using the Tableau
33
# Server Client.
44
#
5-
# To run the script, you must have installed Python 3.6 or later.
5+
# To run the script, you must have installed Python 3.7 or later.
66
####
77

88

samples/download_view_image.py

-77
This file was deleted.

samples/export.py

+23-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This script demonstrates how to export a view using the Tableau
33
# Server Client.
44
#
5-
# To run the script, you must have installed Python 3.6 or later.
5+
# To run the script, you must have installed Python 3.7 or later.
66
####
77

88
import argparse
@@ -40,10 +40,13 @@ def main():
4040
group.add_argument(
4141
"--csv", dest="type", action="store_const", const=("populate_csv", "CSVRequestOptions", "csv", "csv")
4242
)
43+
# other options shown in explore_workbooks: workbook.download, workbook.preview_image
44+
45+
parser.add_argument("--workbook", action="store_true")
4346

4447
parser.add_argument("--file", "-f", help="filename to store the exported data")
4548
parser.add_argument("--filter", "-vf", metavar="COLUMN:VALUE", help="View filter to apply to the view")
46-
parser.add_argument("resource_id", help="LUID for the view")
49+
parser.add_argument("resource_id", help="LUID for the view or workbook")
4750

4851
args = parser.parse_args()
4952

@@ -52,34 +55,46 @@ def main():
5255
logging.basicConfig(level=logging_level)
5356

5457
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
55-
server = TSC.Server(args.server, use_server_version=True)
58+
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False})
5659
with server.auth.sign_in(tableau_auth):
57-
views = filter(lambda x: x.id == args.resource_id or x.name == args.resource_id, TSC.Pager(server.views.get))
58-
view = list(views).pop() # in python 3 filter() returns a filter object
60+
print("Connected")
61+
if args.workbook:
62+
item = server.workbooks.get_by_id(args.resource_id)
63+
else:
64+
item = server.views.get_by_id(args.resource_id)
65+
66+
if not item:
67+
print("No item found for id {}".format(args.resource_id))
68+
exit(1)
5969

70+
print("Item found: {}".format(item.name))
6071
# We have a number of different types and functions for each different export type.
6172
# We encode that information above in the const=(...) parameter to the add_argument function to make
6273
# the code automatically adapt for the type of export the user is doing.
6374
# We unroll that information into methods we can call, or objects we can create by using getattr()
6475
(populate_func_name, option_factory_name, member_name, extension) = args.type
6576
populate = getattr(server.views, populate_func_name)
77+
if args.workbook:
78+
populate = getattr(server.workbooks, populate_func_name)
79+
6680
option_factory = getattr(TSC, option_factory_name)
6781

6882
if args.filter:
6983
options = option_factory().vf(*args.filter.split(":"))
7084
else:
7185
options = None
86+
7287
if args.file:
7388
filename = args.file
7489
else:
7590
filename = "out.{}".format(extension)
7691

77-
populate(view, options)
92+
populate(item, options)
7893
with open(filename, "wb") as f:
7994
if member_name == "csv":
80-
f.writelines(getattr(view, member_name))
95+
f.writelines(getattr(item, member_name))
8196
else:
82-
f.write(getattr(view, member_name))
97+
f.write(getattr(item, member_name))
8398
print("saved to " + filename)
8499

85100

samples/export_wb.py

-101
This file was deleted.

0 commit comments

Comments
 (0)