Skip to content

Commit f84c894

Browse files
authored
Add metric details to docs (#1016)
* Add typing info to contributing guide * Add docs for metrics
1 parent 01d9f52 commit f84c894

2 files changed

Lines changed: 231 additions & 3 deletions

File tree

docs/api-ref.md

Lines changed: 224 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,229 @@ See the `metadata_query.py` sample in the Samples directory.
14991499
<br>
15001500
<br>
15011501

1502+
---
1503+
1504+
## Metrics
1505+
1506+
Using the TSC library, you can get information about all metrics on a site, update, or delete metrics.
1507+
1508+
<br>
1509+
1510+
### MetricItem class
1511+
1512+
```py
1513+
MetricItem(name: Optional[str]=None)
1514+
```
1515+
The metrics resources for Tableau are defined in the `MetricItem` class. The class corresponds to the metric resource you can access using the Tableau Server REST API.
1516+
1517+
**Attributes**
1518+
Name | Description
1519+
:--- | :---
1520+
`name` | Name of the metric
1521+
`id` | The REST API id for the metric
1522+
`description` | The description of the metric
1523+
`webpage_url` | The URL for the metric
1524+
`created_at` | The datetime object for when the metric was created
1525+
`updated_at` | The datetime object for when the metric was updated
1526+
`suspended` | Boolean for if the metric is in a suspended state
1527+
`project_id` | REST API id for the project containing the metric
1528+
`project_name` | The name of the project containing the metric
1529+
`owner_id` | REST API id for the user who owns the metric
1530+
`view_id` | REST API id for the view from which the metric was created
1531+
1532+
1533+
1534+
Source file: models/metric_item.py
1535+
1536+
<br>
1537+
<br>
1538+
1539+
### Metric methods
1540+
1541+
The metric methods are based upon the endpoints for metrics in the REST API and operate on the `MetricItem` class. The metrics endpoint also supports the django style filtering.
1542+
See [Filter and Sort](filter-sort) for more information.
1543+
1544+
Source files: server/endpoint/metrics_endpoint.py
1545+
1546+
<br>
1547+
<br>
1548+
1549+
#### metrics.delete
1550+
1551+
```py
1552+
metrics.delete(metric_id)
1553+
1554+
```
1555+
1556+
Deletes a metric item from a site.
1557+
1558+
1559+
To specify the site, create a `TableauAuth` instance using the content URL for the site (`site_id`), and sign in to that site. See the [TableauAuth class](#tableauauth-class).
1560+
1561+
REST API: [Delete Metric](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#delete_metric)
1562+
1563+
1564+
**Parameters**
1565+
1566+
Name | Description
1567+
:--- | :---
1568+
`metric_id` | The id of the metric to delete
1569+
1570+
1571+
1572+
**Returns**
1573+
1574+
None
1575+
1576+
1577+
1578+
**Example**
1579+
1580+
```py
1581+
# import tableauserverclient as TSC
1582+
# server = TSC.Server('https://MY-SERVER')
1583+
# sign in, etc
1584+
1585+
server.metrics.delete("6561daa3-20e8-407f-ba09-709b178c0b4a")
1586+
1587+
```
1588+
1589+
<br>
1590+
<br>
1591+
1592+
#### metrics.get
1593+
1594+
```py
1595+
metrics.get()
1596+
1597+
```
1598+
1599+
Return a list of metrics items for a site.
1600+
1601+
1602+
To specify the site, create a `TableauAuth` instance using the content URL for the site (`site_id`), and sign in to that site. See the [TableauAuth class](#tableauauth-class).
1603+
1604+
REST API: [List Metrics for Site](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#list_metrics_for_site)
1605+
1606+
1607+
**Parameters**
1608+
1609+
None.
1610+
1611+
**Returns**
1612+
1613+
Returns a Tuple containing a list of all `MetricItem` objects and a `PaginationItem`. Use these values to iterate through the results.
1614+
1615+
1616+
1617+
**Example**
1618+
1619+
```py
1620+
import tableauserverclient as TSC
1621+
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD', site_id='CONTENTURL')
1622+
server = TSC.Server('https://SERVER')
1623+
1624+
with server.auth.sign_in(tableau_auth):
1625+
# get all metrics on site
1626+
all_metric_items, pagination_item = server.metrics.get()
1627+
print([metric.name for metric in all_metric_items])
1628+
1629+
```
1630+
1631+
<br>
1632+
<br>
1633+
1634+
#### metrics.get_by_id
1635+
1636+
```py
1637+
metrics.get_by_id(metric_id)
1638+
1639+
```
1640+
1641+
Return a specific metric item from the site.
1642+
1643+
1644+
To specify the site, create a `TableauAuth` instance using the content URL for the site (`site_id`), and sign in to that site. See the [TableauAuth class](#tableauauth-class).
1645+
1646+
REST API: [Get Metric](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#get_metric)
1647+
1648+
1649+
**Parameters**
1650+
1651+
1652+
Name | Description
1653+
:--- | :---
1654+
`metric_id` | The id of the desired metric
1655+
1656+
1657+
1658+
**Returns**
1659+
1660+
Returns a `MetricItem` object corresponding to the ID requested.
1661+
1662+
1663+
1664+
**Example**
1665+
1666+
```py
1667+
# import tableauserverclient as TSC
1668+
# server = TSC.Server('https://MY-SERVER')
1669+
# sign in, etc
1670+
1671+
server.metrics.get_by_id("6561daa3-20e8-407f-ba09-709b178c0b4a")
1672+
1673+
```
1674+
1675+
<br>
1676+
<br>
1677+
1678+
#### metrics.update
1679+
1680+
```py
1681+
metrics.update(item)
1682+
1683+
```
1684+
1685+
Updates a metric item on the Tableau Server.
1686+
1687+
1688+
To specify the site, create a `TableauAuth` instance using the content URL for the site (`site_id`), and sign in to that site. See the [TableauAuth class](#tableauauth-class).
1689+
1690+
REST API: [Update Metric](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#update_metric)
1691+
1692+
1693+
**Parameters**
1694+
1695+
1696+
Name | Description
1697+
:--- | :---
1698+
`metric_item` | The altered `MetricItem` to be updated on the Tableau Server
1699+
1700+
1701+
**Returns**
1702+
1703+
Returns a `MetricItem` object reflecting the changes applied to Tableau Server.
1704+
1705+
1706+
1707+
**Example**
1708+
1709+
```py
1710+
# import tableauserverclient as TSC
1711+
# server = TSC.Server('https://MY-SERVER')
1712+
# sign in, etc
1713+
1714+
metric = server.metrics.get_by_id("6561daa3-20e8-407f-ba09-709b178c0b4a")
1715+
metric.owner_id = "1bbbc2b9-847d-443c-9a1f-dbcf112b8814"
1716+
server.metrics.update(metric)
1717+
```
1718+
1719+
<br>
1720+
<br>
1721+
1722+
1723+
1724+
15021725
---
15031726

15041727
## Projects
@@ -2838,7 +3061,7 @@ Attribute | Description
28383061
`name` | The name of the site. The name of the default site is "".
28393062
`content_url` | The path to the site.
28403063
`admin_mode` | (Optional) For Tableau Server only. Specify `ContentAndUsers` to allow site administrators to use the server interface and **tabcmd** commands to add and remove users. (Specifying this option does not give site administrators permissions to manage users using the REST API.) Specify `ContentOnly` to prevent site administrators from adding or removing users. (Server administrators can always add or remove users.)
2841-
`user_quota`| (Optional) Specifies the maximum number of users for the site. If you do not specify this value, the limit depends on the type of licensing configured for the server. For user-based license, the maximum number of users is set by the license. For core-based licensing, there is no limit to the number of users. If you specify a maximum value, only licensed users are counted and server administrators are excluded.
3064+
`user_quota`| (Optional) Specifies the maximum number of users for the site. If you do not specify this value, the limit depends on the type of licensing configured for the server. For user-based license, the maximum number of users is set by the license. For core-based licensing, there is no limit to the number of users. If you specify a maximum value, only licensed users are counted and server administrators are excluded. Mutually exclusive with tiered license level settings.
28423065
`storage_quota` | (Optional) Specifies the maximum amount of space for the new site, in megabytes. If you set a quota and the site exceeds it, publishers will be prevented from uploading new content until the site is under the limit again.
28433066
`disable_subscriptions` | (Optional) Specify `true` to prevent users from being able to subscribe to workbooks on the specified site. The default is `false`.
28443067
`subscribe_others_enabled` | (Optional) Specify `false` to prevent server administrators, site administrators, and project or content owners from being able to subscribe other users to workbooks on the specified site. The default is `true`.

docs/dev-guide.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ then
9797
# check for style conventions in all code dirs
9898
echo Running black format check
9999
black --check --line-length 120 tableauserverclient samples test
100+
echo Running mypy type checking
101+
mypy --show-error-codes --disable-error-code misc --disable-error-code import tableauserverclient test
100102
fi
101103
```
102104

@@ -128,11 +130,14 @@ depending on how and where git is installed on your system, for example:
128130
1. Add testing by getting real xml responses from the server, and asserting that
129131
all properties are parsed and set correctly.
130132

131-
1. Add a sample to show users how to use the new feature. Try to keep the command
133+
1. Add type hints to all new classes and functions added. Including type hinting
134+
on unit tests.
135+
136+
2. Add a sample to show users how to use the new feature. Try to keep the command
132137
line arguments of your sample consistent with the [Samples documentation page](samples)
133138
and with other samples.
134139

135-
1. Add documentation (most likely in api-ref.md) in a separate pull request
140+
3. Add documentation (most likely in api-ref.md) in a separate pull request
136141
(see more below).
137142

138143
### Add tests

0 commit comments

Comments
 (0)