Skip to content

Commit 2dc5780

Browse files
docs: Add docstrings to Seam class (#115)
* docs: Add docstrings to Seam class * Document inherited routes * Update docstring format * Only lts_version should be a class instance, client and defaults are instance vars * Document only invalid options and token errors on the seam class
1 parent 3d9dc88 commit 2dc5780

File tree

2 files changed

+97
-22
lines changed

2 files changed

+97
-22
lines changed

seam/models.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Dict, List, Optional, Union
1+
from typing import Dict, List, Optional, Union
22
import niquests as requests
33
from typing_extensions import Self
44
import abc
@@ -26,7 +26,6 @@ def _handle_error_response(self, response: requests.Response):
2626

2727
class AbstractSeam(AbstractRoutes):
2828
lts_version: str
29-
defaults: Dict[str, Any]
3029

3130
@abc.abstractmethod
3231
def __init__(

seam/seam.py

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,27 @@
1010

1111

1212
class Seam(AbstractSeam):
13-
"""
14-
Initial Seam class used to interact with Seam API
13+
"""Main class for interacting with the Seam API.
14+
15+
This class provides methods to authenticate and interact with various
16+
Seam API endpoints,
17+
including devices, access codes, action_attempts, and more. It supports authentication via API key or personal access token.
18+
19+
:cvar lts_version: The long-term support (LTS) version of the Seam
20+
Python SDK
21+
:vartype lts_version: str
22+
:ivar defaults: Default settings for API requests
23+
:vartype defaults: Dict[str, Any]
24+
:ivar client: The HTTP client used for making API requests
25+
:vartype client: SeamHttpClient
26+
:ivar wait_for_action_attempt: Controls whether to wait for an action
27+
attempt to complete
28+
:vartype wait_for_action_attempt: Union[bool, Dict[str, float]]
29+
30+
For more information about the Seam API, visit https://docs.seam.co/
1531
"""
1632

1733
lts_version: str = LTS_VERSION
18-
defaults: Dict[str, Any]
1934

2035
def __init__(
2136
self,
@@ -27,21 +42,35 @@ def __init__(
2742
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
2843
retries: Optional[Retry] = None,
2944
):
30-
"""
31-
Parameters
32-
----------
33-
api_key : str, optional
34-
API key.
35-
personal_access_token : str, optional
36-
Personal access token.
37-
workspace_id : str, optional
38-
Workspace id.
39-
endpoint : str, optional
40-
The API endpoint to which the request should be sent.
41-
wait_for_action_attempt : bool or dict, optional
42-
Controls whether to wait for an action attempt to complete, either as a boolean or as a dictionary specifying `timeout` and `poll_interval`. Defaults to `False`.
43-
retries : urllib3.util.Retry, optional
44-
Configuration for retry behavior on failed requests.
45+
"""Initialize a Seam client instance.
46+
47+
This method sets up the Seam client with the provided authentication credentials and configuration options.
48+
It supports two authentication methods: API key or personal access token.
49+
50+
:param api_key: The API key for authenticating with Seam. Mutually
51+
exclusive with personal_access_token
52+
:type api_key: Optional[str]
53+
:param personal_access_token: A personal access token for
54+
authenticating with Seam. Mutually exclusive with api_key
55+
:type personal_access_token: Optional[str]
56+
:param workspace_id: The ID of the workspace to interact with.
57+
Required when using a personal access token
58+
:type workspace_id: Optional[str]
59+
:param endpoint: The custom API endpoint URL. If not provided, the
60+
default Seam API endpoint will be used
61+
:type endpoint: Optional[str]
62+
:param wait_for_action_attempt: Controls whether to wait for an
63+
action attempt to complete. Can be a boolean or a dictionary with
64+
'timeout' and 'poll_interval' keys
65+
:type wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]]
66+
:param retries: Configuration for retry behavior on failed requests
67+
:type retries: Optional[urllib3.util.Retry]
68+
69+
:raises SeamInvalidOptionsError: If neither api_key nor
70+
personal_access_token is provided, or if workspace_id is missing
71+
when using a personal access token
72+
:raises SeamInvalidTokenError: If the provided API key or personal
73+
access token format is invalid
4574
"""
4675

4776
self.lts_version = Seam.lts_version
@@ -52,13 +81,13 @@ def __init__(
5281
workspace_id=workspace_id,
5382
endpoint=endpoint,
5483
)
55-
defaults = {"wait_for_action_attempt": wait_for_action_attempt}
84+
self.defaults = {"wait_for_action_attempt": wait_for_action_attempt}
5685

5786
self.client = SeamHttpClient(
5887
base_url=endpoint, auth_headers=auth_headers, retries=retries
5988
)
6089

61-
Routes.__init__(self, client=self.client, defaults=defaults)
90+
Routes.__init__(self, client=self.client, defaults=self.defaults)
6291

6392
@classmethod
6493
def from_api_key(
@@ -69,6 +98,28 @@ def from_api_key(
6998
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
7099
retries: Optional[Retry] = None,
71100
) -> Self:
101+
"""Create a Seam instance using an API key.
102+
103+
This class method is a convenience constructor for creating a Seam instance authenticated with an API key.
104+
105+
:param api_key: The API key for authenticating with Seam. Mutually
106+
exclusive with personal_access_token
107+
:type api_key: str
108+
:param endpoint: The custom API endpoint URL. If not provided, the
109+
default Seam API endpoint will be used
110+
:type endpoint: Optional[str]
111+
:param wait_for_action_attempt: Controls whether to wait for an
112+
action attempt to complete. Can be a boolean or a dictionary with
113+
'timeout' and 'poll_interval' keys
114+
:type wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]]
115+
:return: A new instance of the Seam class authenticated with the
116+
provided API key
117+
:rtype: Self
118+
119+
:Example:
120+
121+
>>> seam = Seam.from_api_key("your-api-key-here")
122+
"""
72123
return cls(
73124
api_key,
74125
endpoint=endpoint,
@@ -86,6 +137,31 @@ def from_personal_access_token(
86137
wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]] = True,
87138
retries: Optional[Retry] = None,
88139
) -> Self:
140+
"""Create a Seam instance using a personal access token.
141+
142+
This class method is a convenience constructor for creating a Seam
143+
instance authenticated with a personal access token.
144+
145+
:param personal_access_token: The personal access token for
146+
authenticating with Seam
147+
:type personal_access_token: str
148+
:param workspace_id: The ID of the workspace to interact with
149+
:type workspace_id: str
150+
:param endpoint: The custom API endpoint URL. If not provided, the
151+
default Seam API endpoint will be used
152+
:type endpoint: Optional[str]
153+
:param wait_for_action_attempt: Controls whether to wait for an
154+
action attempt to complete. Can be a boolean or a dictionary with
155+
'timeout' and 'poll_interval' keys
156+
:type wait_for_action_attempt: Optional[Union[bool, Dict[str, float]]]
157+
:return: A new instance of the Seam class authenticated with the
158+
provided personal access token
159+
:rtype: Self
160+
161+
:Example:
162+
163+
>>> seam = Seam.from_personal_access_token("your-token-here", "workspace-id")
164+
"""
89165
return cls(
90166
personal_access_token=personal_access_token,
91167
workspace_id=workspace_id,

0 commit comments

Comments
 (0)