Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add subscriptions sample #1487

Open
wants to merge 24 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4a3d9a9
add subscriptions sample
jacalata Oct 4, 2024
b49eac5
feat(exceptions): separate failed signin error (#1478)
jorwoods Oct 10, 2024
9495fe8
docs: add docstrings to auth objects and endpoints (#1484)
jorwoods Oct 10, 2024
0af5512
Set FILESIZE_LIMIT_MB via environment variables (#1466)
Der-Henning Oct 10, 2024
c6dabdd
added PulseMetricDefine cap (#1490)
AlbertWangXu Oct 10, 2024
0efd735
Adding project permissions handling for databases, tables and virtual…
TrimPeachu Oct 10, 2024
f8728b2
docs: docstrings for Server and ServerInfo (#1494)
jorwoods Oct 11, 2024
89e1ddf
refactor request_options, add language param (#1481)
jacalata Oct 11, 2024
1b64987
docs: docstrings for user item and endpoint (#1485)
jorwoods Oct 11, 2024
9b1b940
ci: build on python 3.13 (#1492)
jorwoods Oct 14, 2024
d880d52
docs: workbook docstrings (#1488)
jorwoods Oct 15, 2024
9f59af1
chore: type hint default permissions endpoints (#1493)
jorwoods Oct 15, 2024
2ff9697
fix: handle 0 item response in querysets (#1501)
jorwoods Oct 17, 2024
e623511
ci: cache dependencies for faster builds (#1497)
jorwoods Oct 17, 2024
c361f8f
Feature: export custom views #999 (#1506)
renoyjohnm Oct 22, 2024
607fa8b
chore: remove py2 holdover code (#1496)
jorwoods Oct 22, 2024
60dfd4d
Update samples for Python 3.x compatibility (#1479)
bcantoni Oct 22, 2024
63ece82
chore: support VizqlDataApiAccess capability (#1504)
jorwoods Oct 22, 2024
b65d8d4
Remove sample code showing group name encoding (#1486)
jacalata Oct 23, 2024
3e38372
Update requests library for CVE CVE-2024-35195 (#1507)
jacalata Oct 23, 2024
878d593
docs: docstrings for site item and endpoint (#1495)
jorwoods Oct 23, 2024
c3ea910
Bring development and master into sync (#1509)
jacalata Oct 23, 2024
7195902
add subscriptions sample
jacalata Oct 4, 2024
7a36873
Merge branch 'jac/subscription-sample' of github.com:tableau/server-c…
jacalata Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/meta-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Get pip cache dir
id: pip-cache
shell: bash
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT

- name: cache
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-pip-

- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13-dev']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']

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

steps:
- name: Get pip cache dir
id: pip-cache
shell: bash
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT

- name: cache
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.python-version }}-pip-

- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
dependencies = [
'defusedxml>=0.7.1', # latest as at 7/31/23
'packaging>=23.1', # latest as at 7/31/23
'requests>=2.31', # latest as at 7/31/23
'requests>=2.32', # latest as at 7/31/23
'urllib3>=2.2.2,<3',
'typing_extensions>=4.0.1',
]
Expand Down Expand Up @@ -43,13 +43,13 @@ target-version = ['py39', 'py310', 'py311', 'py312', 'py313']
check_untyped_defs = false
disable_error_code = [
'misc',
# tableauserverclient\server\endpoint\datasources_endpoint.py:48: error: Cannot assign multiple types to name "FilePath" without an explicit "Type[...]" annotation [misc]
'annotation-unchecked' # can be removed when check_untyped_defs = true
]
files = ["tableauserverclient", "test", "samples"]
show_error_codes = true
ignore_missing_imports = true # defusedxml library has no types
no_implicit_reexport = true
implicit_optional = true

[tool.pytest.ini_options]
testpaths = ["test"]
Expand Down
19 changes: 14 additions & 5 deletions samples/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ def main():
"--csv", dest="type", action="store_const", const=("populate_csv", "CSVRequestOptions", "csv", "csv")
)
# other options shown in explore_workbooks: workbook.download, workbook.preview_image

parser.add_argument(
"--language", help="Text such as 'Average' will appear in this language. Use values like fr, de, es, en"
)
parser.add_argument("--workbook", action="store_true")
parser.add_argument("--custom_view", action="store_true")

parser.add_argument("--file", "-f", help="filename to store the exported data")
parser.add_argument("--filter", "-vf", metavar="COLUMN:VALUE", help="View filter to apply to the view")
Expand All @@ -56,6 +59,8 @@ def main():
print("Connected")
if args.workbook:
item = server.workbooks.get_by_id(args.resource_id)
elif args.custom_view:
item = server.custom_views.get_by_id(args.resource_id)
else:
item = server.views.get_by_id(args.resource_id)

Expand All @@ -72,18 +77,22 @@ def main():
populate = getattr(server.views, populate_func_name)
if args.workbook:
populate = getattr(server.workbooks, populate_func_name)
elif args.custom_view:
populate = getattr(server.custom_views, populate_func_name)

option_factory = getattr(TSC, option_factory_name)
options: TSC.PDFRequestOptions = option_factory()

if args.filter:
options = option_factory().vf(*args.filter.split(":"))
else:
options = None
options = options.vf(*args.filter.split(":"))

if args.language:
options.language = args.language

if args.file:
filename = args.file
else:
filename = f"out.{extension}"
filename = f"out-{options.language}.{extension}"

populate(item, options)
with open(filename, "wb") as f:
Expand Down
12 changes: 3 additions & 9 deletions samples/extracts.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
####
# This script demonstrates how to use the Tableau Server Client
# to interact with workbooks. It explores the different
# functions that the Server API supports on workbooks.
#
# With no flags set, this sample will query all workbooks,
# pick one workbook and populate its connections/views, and update
# the workbook. Adding flags will demonstrate the specific feature
# on top of the general operations.
####
# This script demonstrates how to use the Tableau Server Client to interact with extracts.
# It explores the different functions that the REST API supports on extracts.
#####

import argparse
import logging
Expand Down
44 changes: 25 additions & 19 deletions samples/filter_sort_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def main():
logging.basicConfig(level=logging_level)

tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False})
with server.auth.sign_in(tableau_auth):
group_name = "SALES NORTHWEST"
# Try to create a group named "SALES NORTHWEST"
Expand All @@ -57,37 +57,36 @@ def main():
# Try to create a group named "SALES ROMANIA"
create_example_group(group_name, server)

# URL Encode the name of the group that we want to filter on
# i.e. turn spaces into plus signs
filter_group_name = urllib.parse.quote_plus(group_name)
# we no longer need to encode the space
options = TSC.RequestOptions()
options.filter.add(
TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, filter_group_name)
)
options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name, TSC.RequestOptions.Operator.Equals, group_name))

filtered_groups, _ = server.groups.get(req_options=options)
# Result can either be a matching group or an empty list
if filtered_groups:
group_name = filtered_groups.pop().name
print(group_name)
group = filtered_groups.pop()
print(group)
else:
error = f"No project named '{filter_group_name}' found"
error = f"No group named '{group_name}' found"
print(error)

print("---")

# Or, try the above with the django style filtering
try:
group = server.groups.filter(name=filter_group_name)[0]
group = server.groups.filter(name=group_name)[0]
print(group)
except IndexError:
print(f"No project named '{filter_group_name}' found")
else:
print(group.name)
print(f"No group named '{group_name}' found")

print("====")

options = TSC.RequestOptions()
options.filter.add(
TSC.Filter(
TSC.RequestOptions.Field.Name,
TSC.RequestOptions.Operator.In,
["SALES+NORTHWEST", "SALES+ROMANIA", "this_group"],
["SALES NORTHWEST", "SALES ROMANIA", "this_group"],
)
)

Expand All @@ -98,13 +97,20 @@ def main():
for group in matching_groups:
print(group.name)

print("----")
# or, try the above with the django style filtering.

groups = ["SALES NORTHWEST", "SALES ROMANIA", "this_group"]
groups = [urllib.parse.quote_plus(group) for group in groups]
for group in server.groups.filter(name__in=groups).sort("-name"):
all_g = server.groups.all()
print(f"Searching locally among {all_g.total_available} groups")
for a in all_g:
print(a)
groups = [urllib.parse.quote_plus(group) for group in ["SALES NORTHWEST", "SALES ROMANIA", "this_group"]]
print(groups)

for group in server.groups.filter(name__in=groups).order_by("-name"):
print(group.name)

print("done")


if __name__ == "__main__":
main()
21 changes: 12 additions & 9 deletions samples/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
import argparse
import getpass
import logging
import os

import tableauserverclient as TSC
import env


def get_env(key):
if key in os.environ:
return os.environ[key]
return None


# If a sample has additional arguments, then it should copy this code and insert them after the call to
Expand All @@ -20,13 +26,13 @@ def set_up_and_log_in():
sample_define_common_options(parser)
args = parser.parse_args()
if not args.server:
args.server = env.server
args.server = get_env("SERVER")
if not args.site:
args.site = env.site
args.site = get_env("SITE")
if not args.token_name:
args.token_name = env.token_name
args.token_name = get_env("TOKEN_NAME")
if not args.token_value:
args.token_value = env.token_value
args.token_value = get_env("TOKEN_VALUE")
args.logging_level = "debug"

server = sample_connect_to_server(args)
Expand Down Expand Up @@ -79,10 +85,7 @@ def sample_connect_to_server(args):
# Make sure we use an updated version of the rest apis, and pass in our cert handling choice
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": check_ssl_certificate})
server.auth.sign_in(tableau_auth)
server.version = "2.6"
new_site: TSC.SiteItem = TSC.SiteItem("cdnear", content_url=env.site)
server.auth.switch_site(new_site)
print("Logged in successfully")
server.version = "3.19"

return server

Expand Down
23 changes: 15 additions & 8 deletions samples/publish_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@
import argparse
import logging

import os
import tableauserverclient as TSC

import env
import tableauserverclient.datetime_helpers


def get_env(key):
if key in os.environ:
return os.environ[key]
return None


def main():
parser = argparse.ArgumentParser(description="Publish a datasource to server.")
# Common options; please keep those in sync across all samples
Expand All @@ -52,13 +57,13 @@ def main():

args = parser.parse_args()
if not args.server:
args.server = env.server
args.server = get_env("SERVER")
if not args.site:
args.site = env.site
args.site = get_env("SITE")
if not args.token_name:
args.token_name = env.token_name
args.token_name = get_env("TOKEN_NAME")
if not args.token_value:
args.token_value = env.token_value
args.token_value = get_env("TOKEN_VALUE")
args.logging = "debug"
args.file = "C:/dev/tab-samples/5M.tdsx"
args.async_ = True
Expand Down Expand Up @@ -118,8 +123,10 @@ def main():
new_datasource, args.file, publish_mode, connection_credentials=new_conn_creds
)
print(
"{}Datasource published. Datasource ID: {}".format(
new_datasource.id, tableauserverclient.datetime_helpers.timestamp()
(
"{}Datasource published. Datasource ID: {}".format(
new_datasource.id, tableauserverclient.datetime_helpers.timestamp()
)
)
)
print("\t\tClosing connection")
Expand Down
2 changes: 1 addition & 1 deletion samples/set_refresh_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def usage(args):

def make_filter(**kwargs):
options = TSC.RequestOptions()
for item, value in kwargs.items():
for item, value in list(kwargs.items()):
name = getattr(TSC.RequestOptions.Field, item)
options.filter.add(TSC.Filter(name, TSC.RequestOptions.Operator.Equals, value))
return options
Expand Down
Loading
Loading