Skip to content

Commit 4d6e484

Browse files
Document SDK description and usage (#26)
* Document SDK description and usage * Fix title level inconsistency * Fix duplicate explicit target names * Style note using bold and italics * Format codeblocks * Codeblock fix: safely access index in a list * Replace console.log with print * Catch custom exception * feat: Bump SDK generator to 1.9.0 to add custom action attempt polling errors (#35) * Bump sdk generator to 1.9.0 to add custom action attempt polling errors * ci: Generate code --------- Co-authored-by: Seam Bot <devops@getseam.com> * 0.6.0 --------- Co-authored-by: Seam Bot <devops@getseam.com>
1 parent 8fad3b4 commit 4d6e484

File tree

1 file changed

+143
-4
lines changed

1 file changed

+143
-4
lines changed

README.rst

Lines changed: 143 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,162 @@ SDK for the Seam API written in Python.
1515
Description
1616
-----------
1717

18-
TODO
18+
`Seam <seam_home_>`_ makes it easy to integrate IoT devices with your applications.
19+
This is an official SDK for the Seam API.
20+
Please refer to the official `Seam Docs <https://docs.seam.co/latest/>`_ to get started.
21+
22+
Parts of this SDK are generated from always up-to-date type information
23+
provided by `@seamapi/types <https://github.com/seamapi/types/>`_ node package.
24+
This ensures all API methods, request shapes, and response shapes are
25+
accurate and fully typed.
26+
27+
.. _seam_home: https://www.seam.co
1928

2029
Installation
2130
------------
2231

2332
This package is registered on the `Python Package Index (PyPI)`_
2433
as seam_.
2534

26-
Install it with
27-
28-
::
35+
Install it with::
2936

3037
$ pip install seam
3138

3239
.. _seam: https://pypi.python.org/pypi/seam
3340
.. _Python Package Index (PyPI): https://pypi.python.org/
3441

42+
Usage
43+
-----
44+
45+
Examples
46+
~~~~~~~~
47+
48+
**Note:** *These examples assume `SEAM_API_KEY` is set in your environment.*
49+
50+
List devices
51+
^^^^^^^^^^^^
52+
53+
.. code-block:: python
54+
55+
from seam import Seam
56+
57+
seam = Seam()
58+
devices = seam.devices.list()
59+
60+
Unlock a door
61+
^^^^^^^^^^^^^
62+
63+
.. code-block:: python
64+
65+
from seam import Seam
66+
67+
seam = Seam()
68+
lock = seam.locks.get(name="Front Door")
69+
seam.locks.unlock_door(device_id="lock.device_id")
70+
71+
Authentication Method
72+
~~~~~~~~~~~~~~~~~~~~~
73+
74+
The SDK supports API key authentication mechanism.
75+
76+
An API key is scoped to a single workspace and should only be used on the server.
77+
Obtain one from the Seam Console.
78+
79+
.. code-block:: python
80+
81+
# Set the `SEAM_API_KEY` environment variable
82+
seam = Seam()
83+
84+
# Pass as the first argument to the constructor
85+
seam = Seam("your-api-key")
86+
87+
# Pass as a keyword argument to the constructor
88+
seam = Seam(api_key="your-api-key")
89+
90+
Action Attempts
91+
~~~~~~~~~~~~~~~
92+
93+
Some asynchronous operations, e.g., unlocking a door, return an `action attempt <https://docs.seam.co/latest/core-concepts/action-attempts>`_.
94+
Seam tracks the progress of requested operation and updates the action attempt.
95+
96+
To make working with action attempts more convenient for applications,
97+
this library provides the `wait_for_action_attempt` option.
98+
99+
Pass the option per-request,
100+
101+
.. code-block:: python
102+
103+
seam.locks.unlock_door(
104+
device_id=device_id,
105+
wait_for_action_attempt=True,
106+
)
107+
108+
or set the default option for the client:
109+
110+
.. code-block:: python
111+
112+
seam = Seam(
113+
api_key="your-api-key",
114+
wait_for_action_attempt=True,
115+
)
116+
117+
seam.locks.unlock_door(device_id=device_id)
118+
119+
If you already have an action attempt id
120+
and want to wait for it to resolve, simply use
121+
122+
.. code-block:: python
123+
124+
seam.action_attempts.get(
125+
action_attempt_id=action_attempt_id,
126+
wait_for_action_attempt=True,
127+
)
128+
129+
Using the `wait_for_action_attempt` option:
130+
131+
- Polls the action attempt up to the `timeout`
132+
at the `polling_interval` (both in seconds).
133+
- Resolves with a fresh copy of the successful action attempt.
134+
- Raises an exception if the action attempt is unsuccessful.
135+
- Raises an exception if the action attempt is still pending when the `timeout` is reached.
136+
137+
.. code-block:: python
138+
139+
seam = Seam("your-api-key")
140+
141+
lock = seam.locks.list()[0]
142+
143+
if len(locks) == 0:
144+
raise Exception("No locks in this workspace")
145+
146+
lock = locks[0]
147+
148+
try:
149+
seam.locks.unlock_door(
150+
device_id=lock.device_id,
151+
wait_for_action_attempt={
152+
"timeout": 5.0,
153+
"polling_interval": 1.0,
154+
},
155+
)
156+
157+
print("Door unlocked")
158+
except SeamActionAttemptFailedError as e:
159+
print("Could not unlock the door")
160+
except SeamActionAttemptTimeoutError as e:
161+
print("Door took too long to unlock")
162+
163+
Advanced Usage
164+
~~~~~~~~~~~~~~
165+
166+
Setting the endpoint
167+
^^^^^^^^^^^^^^^^^^^^
168+
169+
Some contexts may need to override the API endpoint,
170+
e.g., testing or proxy setups.
171+
172+
Either pass the `api_url` option to the constructor, or set the `SEAM_ENDPOINT` environment variable.
173+
35174
Development and Testing
36175
-----------------------
37176

0 commit comments

Comments
 (0)