Skip to content

Commit

Permalink
Merge pull request #456 from skalish/examples
Browse files Browse the repository at this point in the history
Exploratory tutorial conversion to use example directory
  • Loading branch information
pcattori committed Sep 15, 2020
2 parents 0d94457 + c76ec25 commit 4297599
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- Added function for deleting all records in a dataset via `tc.record.delete_all`
- Added functions for getting all datasets and projects in a Tamr instance via `get_all` functions in `tc.dataset` and `tc.project`
- [#454](https://github.com/Datatamer/tamr-client/pull/454) Added first `tamr_client` tutorial "Get Tamr version"

- [#456](https://github.com/Datatamer/tamr-client/pull/456) Added first example `tamr_client` script `examples/get_tamr_version.py`

**NEW FEATURES**
- [#383](https://github.com/Datatamer/tamr-client/issues/383) Now able to create an Operation from Job resource id
Expand Down
51 changes: 16 additions & 35 deletions docs/beta/tutorial/get_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,36 @@ A `Session` carries authentication credentials derived from a username and passw

- Use your username and password to create an instance of `tamr_client.UsernamePasswordAuth`.
- Use the function `tamr_client.session.from.auth` to create a `Session`.
```python
from getpass import getpass
import tamr_client as tc

username = input("Tamr Username:")
password = getpass("Tamr Password:")

auth = tc.UsernamePasswordAuth(username, password)
session = tc.session.from_auth(auth)
```eval_rst
.. literalinclude:: ../../../examples/get_tamr_version.py
:language: python
:lines: 1-9
```
### The Instance
An `Instance` models the installation or instance of Tamr with which a user interacts via the Python client.

- Create an `Instance` using the `protocol`, `host`, and `port` of your Tamr instance.
```python
protocol = "http"
host = "localhost"
port = 9100

instance = tc.Instance(protocol=protocol, host=host, port=port)
```eval_rst
.. literalinclude:: ../../../examples/get_tamr_version.py
:language: python
:lines: 11-15
```
### Getting the version of Tamr
With the `Session` and `Instance` defined, you can now interact with the API of the Tamr instance. One simple example is fetching the version of the Tamr software running on the server.

- Use the function `tc.version` and print the returned value.
- Use the function `tc.instance.version` and print the returned value.

```python
print(tc.version(session, instance))
```eval_rst
.. literalinclude:: ../../../examples/get_tamr_version.py
:language: python
:lines: 17
```

All of the above steps can be combined into the following script `get_tamr_version.py`:

```python
from getpass import getpass
import tamr_client as tc

username = input("Tamr Username:")
password = getpass("Tamr Password:")

auth = tc.UsernamePasswordAuth(username, password)
session = tc.session.from_auth(auth)

protocol = "http"
host = "localhost"
port = 9100

instance = tc.Instance(protocol=protocol, host=host, port=port)

print(tc.version(session, instance))
```eval_rst
.. literalinclude:: ../../../examples/get_tamr_version.py
:language: python
```
To run the script via command line:
```bash
Expand Down
17 changes: 17 additions & 0 deletions examples/get_tamr_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from getpass import getpass

import tamr_client as tc

username = input("Tamr Username:")
password = getpass("Tamr Password:")

auth = tc.UsernamePasswordAuth(username, password)
session = tc.session.from_auth(auth)

protocol = "http"
host = "localhost"
port = 9100

instance = tc.Instance(protocol=protocol, host=host, port=port)

print(tc.instance.version(session, instance))
3 changes: 3 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def typecheck(session):
tc = repo / "tamr_client"
session.run("mypy", "--package", str(tc))

tc_examples = [str(x) for x in (repo / "examples").glob("**/*.py")]
session.run("mypy", *tc_examples)

tc_tests = [str(x) for x in (repo / "tests" / "tamr_client").glob("**/*.py")]
session.run("mypy", *tc_tests)

Expand Down

0 comments on commit 4297599

Please sign in to comment.