AMSClient#
- class teamworksams.utils.AMSClient(url: str, username: str | None = None, password: str | None = None)[source]#
Bases:
object
A client for interacting with the AMS API.
Handles authentication, API requests, and caching for AMS operations. Created by
get_client()
and used internally by functions likeget_user()
. Supports direct use for custom API calls with methods like_fetch()
. Uses stateless connections for each request to ensure reliability. See Managing Credentials, Authentication, and Caching for setup.- Parameters:
url (str) – The AMS instance URL (e.g., ‘https://example.smartabase.com/site’). Must include a valid site name.
username (Optional[str]) – Username for authentication. If None, uses
AMS_USERNAME
orkeyring
credentials. Defaults to None.password (Optional[str]) – Password for authentication. If None, uses
AMS_PASSWORD
orkeyring
credentials. Defaults to None.
- url#
The validated AMS instance URL.
- Type:
str
- app_name#
The site name extracted from the URL.
- Type:
str
- headers#
HTTP headers for API requests.
- Type:
Dict[str, str]
- username#
The username used for authentication.
- Type:
str
- password#
The password used for authentication.
- Type:
str
- authenticated#
Whether the client is authenticated.
- Type:
bool
- session#
Legacy session object (maintained for compatibility).
- Type:
requests.Session
- login_data#
The response data from the login API call.
- Type:
Dict
- _cache#
Cache for API responses.
- Type:
Dict[str, Dict]
Additional Notes#
Typically created via get_client() rather than directly, ensuring proper authentication.
The
_fetch
method is used internally for API requests but can be called for custom endpoints (e.g., ‘usersearch’).The
_cache
attribute stores API responses whencache=True
in_fetch()
, improving performance for repeated calls.
See Also#
get_client(): Recommended way to create an
AMSClient
.AMSError(): Exception raised for API errors.
Managing Credentials, Authentication, and Caching: Client setup guide.