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 like get_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 or keyring credentials. Defaults to None.

  • password (Optional[str]) – Password for authentication. If None, uses AMS_PASSWORD or keyring 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]

__init__(url: str, username: str | None = None, password: str | None = None)[source]#

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 when cache=True in _fetch(), improving performance for repeated calls.

See Also#