viam.app.app_client
Attributes
Classes
A class that mirrors the RobotPart proto message. |
|
A class that mirrors the LogEntry proto message. |
|
A class that mirrors the Fragment proto message. |
|
A class that mirrors the FragmentHistoryEntry proto message. |
|
A class that mirrors the RobotPartHistoryEntry proto message. |
|
A class with the necessary authorization data for creating an API key. |
|
gRPC client for method calls to app. |
Module Contents
- viam.app.app_client.LOGGER
- class viam.app.app_client.RobotPart[source]
A class that mirrors the RobotPart proto message.
Use this class to make the attributes of a viam.proto.app.RobotPart more accessible and easier to read/interpret.
- classmethod from_proto(robot_part: viam.proto.app.RobotPart) typing_extensions.Self [source]
Create a RobotPart from the .proto defined RobotPart.
- Parameters:
robot_part (viam.proto.app.RobotPart) – The object to copy from.
- Returns:
The RobotPart.
- Return type:
- id: str
- name: str
- dns_name: str
- secret: str
- robot: str
- location_id: str
- robot_config: Mapping[str, Any] | None
- last_access: datetime.datetime | None
- user_supplied_info: Mapping[str, Any] | None
- main_part: bool
- fqdn: str
- local_fqdn: str
- created_on: datetime.datetime | None
- secrets: List[viam.proto.app.SharedSecret] | None
- property proto: viam.proto.app.RobotPart
- class viam.app.app_client.LogEntry[source]
A class that mirrors the LogEntry proto message.
Use this class to make the attributes of a viam.proto.app.LogEntry more accessible and easier to read/interpret.
- classmethod from_proto(log_entry: viam.proto.common.LogEntry) typing_extensions.Self [source]
Create a LogEntry from the .proto defined LogEntry.
- Parameters:
log_entry (viam.proto.app.LogEntry) – The object to copy from.
- Returns:
The LogEntry.
- Return type:
- host: str
- level: str
- time: datetime.datetime | None
- logger_name: str
- message: str
- caller: Mapping[str, Any] | None
- stack: str
- fields: List[Mapping[str, Any]] | None
- property proto: viam.proto.common.LogEntry
- class viam.app.app_client.Fragment[source]
A class that mirrors the Fragment proto message.
Use this class to make the attributes of a viam.proto.app.RobotPart more accessible and easier to read/interpret.
- class Visibility[source]
Bases:
str
,enum.Enum
FragmentVisibility specifies who is permitted to view the fragment.
- PRIVATE = 'private'
Only visible to members in the fragment’s organization.
- PUBLIC = 'public'
Visible to anyone and appears on the fragments page.
- PUBLIC_UNLISTED = 'public_unlisted'
Visible to anyone but does not appear on the fragments page.
- UNSPECIFIED = 'unspecified'
Uninitialized visibility.
- classmethod from_proto(fragment: viam.proto.app.Fragment) typing_extensions.Self [source]
Create a Fragment from the .proto defined Fragment.
- Parameters:
fragment (viam.proto.app.Fragment) – The object to copy from.
- Returns:
The Fragment.
- Return type:
- id: str
- name: str
- fragment: Mapping[str, Any] | None
- organization_owner: str
- public: bool
- created_on: datetime.datetime | None
- organization_name: str
- robot_part_count: int
- organization_count: int
- only_used_by_owner: bool
- visibility: Fragment.Visibility
- property proto: viam.proto.app.Fragment
- class viam.app.app_client.FragmentHistoryEntry[source]
A class that mirrors the FragmentHistoryEntry proto message.
Use this class to make the attributes of a viam.proto.app.FragmentHistoryEntry more accessible and easier to read/interpret.
- classmethod from_proto(fragment_history_entry: viam.proto.app.FragmentHistoryEntry) typing_extensions.Self [source]
Create a FragmentHistoryEntry from the .proto defined FragmentHistoryEntry.
- Parameters:
fragment_history_entry (viam.proto.app.FragmentHistoryEntry) – The object to copy from.
- Returns:
The FragmentHistoryEntry.
- Return type:
- fragment: str
- edited_on: datetime.datetime
- edited_by: viam.proto.app.AuthenticatorInfo
- property proto: viam.proto.app.FragmentHistoryEntry
- class viam.app.app_client.RobotPartHistoryEntry[source]
A class that mirrors the RobotPartHistoryEntry proto message.
Use this class to make the attributes of a viam.proto.app.RobotPartHistoryEntry more accessible and easier to read/interpret.
- classmethod from_proto(robot_part_history_entry: viam.proto.app.RobotPartHistoryEntry) typing_extensions.Self [source]
Create a RobotPartHistoryEntry from the .proto defined RobotPartHistoryEntry.
- Parameters:
robot_part_history_entry (viam.proto.app.RobotPartHistoryEntry) – The object to copy from.
- Returns:
The RobotPartHistoryEntry.
- Return type:
- part: str
- robot: str
- when: datetime.datetime | None
- property proto: viam.proto.app.RobotPartHistoryEntry
- class viam.app.app_client.APIKeyAuthorization(role: Literal['owner'] | Literal['operator'], resource_type: Literal['organization'] | Literal['location'] | Literal['robot'], resource_id: str)[source]
A class with the necessary authorization data for creating an API key.
Use this class when constructing API key authorizations to minimize the risk of malformed or missing data.
- class viam.app.app_client.AppClient(channel: grpclib.client.Channel, metadata: Mapping[str, str], location_id: str | None = None)[source]
gRPC client for method calls to app.
Constructor is used by ViamClient to instantiate relevant service stub. Calls to AppClient methods should be made through ViamClient.
Establish a Connection:
import asyncio from viam.rpc.dial import DialOptions, Credentials from viam.app.viam_client import ViamClient async def connect() -> ViamClient: # Replace "<API-KEY>" (including brackets) with your API key and "<API-KEY-ID>" with your API key ID dial_options = DialOptions.with_api_key("<API-KEY>", "<API-KEY-ID>") return await ViamClient.create_from_dial_options(dial_options) async def main(): # Make a ViamClient viam_client = await connect() # Instantiate an AppClient called "cloud" to run cloud app API methods on cloud = viam_client.app_client viam_client.close() if __name__ == '__main__': asyncio.run(main())
For more information, see Fleet Management API.
- async get_user_id_by_email(email: str) str [source]
Get the ID of a user by email.
id = await cloud.get_user_id_by_email("youremail@email.com")
- Parameters:
email (str) – The email of the user.
- Returns:
The ID of the user.
- Return type:
str
For more information, see Fleet Management API.
- async create_organization(name: str) viam.proto.app.Organization [source]
Create an organization.
organization = await cloud.create_organization("name")
- Parameters:
name (str) – The name of the organization.
- Returns:
The created organization.
- Return type:
For more information, see Fleet Management API.
- async list_organizations() List[viam.proto.app.Organization] [source]
List the organization(s) the user is an authorized owner of.
org_list = await cloud.list_organizations()
- Returns:
The list of organizations.
- Return type:
For more information, see Fleet Management API.
- async get_organizations_with_access_to_location(location_id: str) List[viam.proto.app.OrganizationIdentity] [source]
Get all organizations that have access to a location.
org_list = await cloud.get_organizations_with_access_to_location("location-id")
- Parameters:
location_id (str) – The ID of the location.
- Returns:
The list of organizations.
- Return type:
For more information, see Fleet Management API.
- async list_organizations_by_user(user_id: str) List[viam.proto.app.OrgDetails] [source]
List the organizations a user belongs to.
org_list = await cloud.list_organizations_by_user("<YOUR-USER-ID>")
- Parameters:
user_id (str) – The ID of the user. You can retrieve this with the get_user_id_by_email() method.
- Returns:
The list of organizations.
- Return type:
List[OrgDetails]
For more information, see Fleet Management API.
- async get_organization(org_id: str) viam.proto.app.Organization [source]
Retrieve the organization object for the requested organization containing the organization’s ID, name, public namespace, and more.
org = await cloud.get_organization("<YOUR-ORG-ID>")
- Parameters:
org_id (str) – The ID of the organization to query. You can retrieve this from the organization settings page.
- Raises:
GRPCError – If the provided org_id is invalid, or not currently authed to.
- Returns:
The requested organization.
- Return type:
For more information, see Fleet Management API.
- async get_organization_namespace_availability(public_namespace: str) bool [source]
Check the availability of an organization namespace.
available = await cloud.get_organization_namespace_availability( public_namespace="my-cool-organization")
- Parameters:
public_namespace (str) – Organization namespace to check. Namespaces can only contain lowercase alphanumeric and dash characters.
- Raises:
GRPCError – If an invalid namespace (for example, “”) is provided.
- Returns:
True if the provided namespace is available.
- Return type:
bool
For more information, see Fleet Management API.
- async update_organization(org_id: str, name: str | None = None, public_namespace: str | None = None, region: str | None = None, cid: str | None = None) viam.proto.app.Organization [source]
Updates organization details.
organization = await cloud.update_organization( org_id="<YOUR-ORG-ID>", name="Artoo's Org", public_namespace="artoo" )
- Parameters:
org_id (str) – The ID of the organization to update.
name (Optional[str]) – If provided, updates the org’s name.
public_namespace (Optional[str]) – If provided, sets the org’s namespace if it hasn’t already been set.
region (Optional[str]) – If provided, updates the org’s region.
cid (Optional[str]) – If provided, update’s the org’s CRM ID.
- Raises:
GRPCError – If the org’s namespace has already been set, or if the provided namespace is already taken.
- Returns:
The updated organization.
- Return type:
For more information, see Fleet Management API.
- async delete_organization(org_id: str) None [source]
Delete an organization
await cloud.delete_organization("<YOUR-ORG-ID>")
- Parameters:
org_id (str) – The ID of the organization. You can obtain your organization ID from the Viam app’s organization settings page.
For more information, see Fleet Management API.
- async list_organization_members(org_id: str) Tuple[List[viam.proto.app.OrganizationMember], List[viam.proto.app.OrganizationInvite]] [source]
List the members and invites of the currently authed-to organization.
member_list, invite_list = await cloud.list_organization_members("<YOUR-ORG-ID>")
- Parameters:
org_id (str) – The ID of the organization to list members of. You can obtain your organization ID from the Viam app’s organization settings page.
- Returns:
A tuple containing two lists; the first [0] of organization members, and the second [1] of organization invites.
- Return type:
Tuple[List[viam.proto.app.OrganizationMember], List[viam.proto.app.OrganizationInvite]]
For more information, see Fleet Management API.
- async create_organization_invite(org_id: str, email: str, authorizations: List[viam.proto.app.Authorization] | None = None, send_email_invite: bool = True) viam.proto.app.OrganizationInvite [source]
Creates an organization invite and sends it via email.
await cloud.create_organization_invite("<YOUR-ORG-ID>", "youremail@email.com")
- Parameters:
org_id (str) – The ID of the organization to create an invite for. You can obtain your organization ID from the Viam app’s organization settings page.
email (str) – The email address to send the invite to.
authorizations (Optional[List[viam.proto.app.Authorization]]) – Specifications of the authorizations to include in the invite. If not provided, full owner permissions will be granted.
send_email_invite (Optional[bool]) – Whether or not an email should be sent to the recipient of an invite. The user must accept the email to be added to the associated authorizations. When set to false, the user automatically receives the associated authorization on the next login of the user with the associated email address.
- Raises:
GRPCError – if an invalid email is provided, or if the user is already a member of the org.
- Returns:
The organization invite.
- Return type:
For more information, see Fleet Management API.
- async update_organization_invite_authorizations(org_id: str, email: str, add_authorizations: List[viam.proto.app.Authorization] | None = None, remove_authorizations: List[viam.proto.app.Authorization] | None = None) viam.proto.app.OrganizationInvite [source]
Update the authorizations attached to an organization invite that has already been created.
Note that an invite can only have one authorization at each resource (for example, organization, location, robot, etc.) level and must have at least one authorization overall.
from viam.proto.app import Authorization auth = Authorization( authorization_type="role", authorization_id="location_owner", resource_type="location", # "robot", "location", or "organization" resource_id="012456lni0", # machine id, location id or org id identity_id="", organization_id="<YOUR-ORG-ID>", identity_type="" ) update_invite = await cloud.update_organization_invite_authorizations( org_id="<YOUR-ORG-ID>", email="notarealemail@viam.com", add_authorizations=[auth] )
- Parameters:
org_id (str) – The ID of the organization that the invite is for. You can obtain your organization ID from the Viam app’s organization settings page.
email (str) – Email of the user the invite was sent to.
add_authorizations (Optional[List[viam.proto.app.Authorization]]) – Optional list of authorizations to add to the invite.
remove_authorizations (Optional[List[viam.proto.app.Authorization]]) – Optional list of authorizations to remove from the invite.
- Raises:
GRPCError – If no authorizations are passed or if an invalid combination of authorizations is passed (for example an authorization to remove when the invite only contains one authorization).
- Returns:
The updated invite.
- Return type:
For more information, see Fleet Management API.
- async delete_organization_member(org_id: str, user_id: str) None [source]
Remove a member from the organization.
member_list, invite_list = await cloud.list_organization_members(org_id="<YOUR-ORG-ID>") first_user_id = member_list[0].user_id await cloud.delete_organization_member(org_id="org_id", user_id=first_user_id)
- Parameters:
org_id (str) – The ID of the org to remove the user from. You can obtain your organization ID from the Viam app’s organization settings page.
user_id (str) – The ID of the user to remove.
For more information, see Fleet Management API.
- async delete_organization_invite(org_id: str, email: str) None [source]
Deletes a pending organization invite.
await cloud.delete_organization_invite("<YOUR-ORG-ID>", "youremail@email.com")
- Parameters:
org_id (str) – The ID of the organization that the invite to delete was for. You can obtain your organization ID from the Viam app’s organization settings page.
email (str) – The email address the pending invite was sent to.
- Raises:
GRPCError – If no pending invite is associated with the provided email address.
For more information, see Fleet Management API.
- async resend_organization_invite(org_id: str, email: str) viam.proto.app.OrganizationInvite [source]
Re-sends a pending organization invite email.
org_invite = await cloud.resend_organization_invite("<YOUR-ORG-ID>", "youremail@email.com")
- Parameters:
org_id (str) – The ID of the organization that the invite to resend was for. You can obtain your organization ID from the Viam app’s organization settings page.
email (str) – The email address associated with the invite.
- Raises:
GRPCError – If no pending invite is associated with the provided email address.
- Returns:
The organization invite sent.
- Return type:
For more information, see Fleet Management API.
- async create_location(org_id: str, name: str, parent_location_id: str | None = None) viam.proto.app.Location [source]
Create and name a location under the currently authed-to organization and the specified parent location.
my_new_location = await cloud.create_location(org_id="<YOUR-ORG-ID>", name="Robotville", parent_location_id="111ab12345")
- Parameters:
org_id (str) – The ID of the organization to create the location under. You can obtain your organization ID from the Viam app’s organization settings page.
name (str) – Name of the location.
parent_location_id (Optional[str]) – Optional parent location to put the location under. Defaults to a root-level location if no location ID is provided.
- Raises:
GRPCError – If either an invalid name (for example, “”), or parent location ID (for example, a nonexistent ID) is passed.
- Returns:
The newly created location.
- Return type:
For more information, see Fleet Management API.
- async get_location(location_id: str | None = None) viam.proto.app.Location [source]
Get a location.
location = await cloud.get_location(location_id="123ab12345")
- Parameters:
location_id (Optional[str]) – ID of the location to get. Defaults to the location ID provided at AppClient instantiation.
- Raises:
GRPCError – If an invalid location ID is passed or if one isn’t passed and there was no location ID provided at AppClient instantiation.
- Returns:
The location.
- Return type:
For more information, see Fleet Management API.
- async update_location(location_id: str, name: str | None = None, parent_location_id: str | None = None) viam.proto.app.Location [source]
Change the name of a location and/or assign it a new parent location.
# The following line takes the location with ID "abc12abcde" and moves it to be a # sub-location of the location with ID "xyz34xxxxx" my_updated_location = await cloud.update_location( location_id="abc12abcde", name="", parent_location_id="xyz34xxxxx", ) # The following line changes the name of the location without changing its parent location my_updated_location = await cloud.update_location( location_id="abc12abcde", name="Land Before Robots" ) # The following line moves the location back up to be a top level location without changing its name my_updated_location = await cloud.update_location( location_id="abc12abcde", name="", parent_location_id="" )
- Parameters:
location_id (str) – ID of the location to update. Must be specified.
name (Optional[str]) – Optional new name to be updated on the location. Defaults to the empty string “” (that is, the name doesn’t change).
parent_location_id (Optional[str]) – Optional ID of new parent location to move the location under. Defaults to the empty string “” (that is, no new parent location is assigned).
- Raises:
GRPCError – If either an invalid location ID, name, or parent location ID is passed.
- Returns:
The newly updated location.
- Return type:
For more information, see Fleet Management API.
- async delete_location(location_id: str) None [source]
Delete a location.
await cloud.delete_location(location_id="abc12abcde")
- Parameters:
location_id (str) – ID of the location to delete. Must be specified.
- Raises:
GRPCError – If an invalid location ID is passed.
For more information, see Fleet Management API.
- async list_locations(org_id: str) List[viam.proto.app.Location] [source]
Get a list of all locations under the currently authed-to organization.
locations = await cloud.list_locations("<YOUR-ORG-ID>")
- Parameters:
org_id (str) – The ID of the org to list locations for. You can obtain your organization ID from the Viam app’s organization settings page.
- Returns:
The list of locations.
- Return type:
List[viam.proto.app.Location]
For more information, see Fleet Management API.
Share a location with an organization.
await cloud.share_location("<YOUR-ORG-ID>", "<YOUR-LOCATION-ID>")
- Parameters:
organization_id (str) – The ID of the organization.
location_id (str) – The ID of the location.
For more information, see Fleet Management API.
Stop sharing a location with an organization.
await cloud.unshare_location("<YOUR-ORG-ID>", "<YOUR-LOCATION-ID>")
- Parameters:
organization_id (str) – The ID of the organization.
location_id (str) – The ID of the location.
For more information, see Fleet Management API.
- async location_auth(location_id: str | None = None) viam.proto.app.LocationAuth [source]
Get a location’s LocationAuth (location secret(s)).
loc_auth = await cloud.location_auth(location_id="123xy12345")
- Parameters:
location_id (str) – ID of the location to retrieve LocationAuth from. Defaults to the location ID provided at AppClient instantiation.
- Raises:
GRPCError – If an invalid location ID is passed or if one isn’t passed and there was no location ID provided at AppClient instantiation.
- Returns:
The LocationAuth containing location secrets.
- Return type:
For more information, see Fleet Management API.
- async create_location_secret(location_id: str | None = None) viam.proto.app.LocationAuth [source]
Create a new location secret.
new_loc_auth = await cloud.create_location_secret(location_id="123xy12345")
- Parameters:
location_id (Optional[str]) – ID of the location to generate a new secret for. Defaults to the location ID provided at AppClient instantiation.
- Raises:
GRPCError – If an invalid location ID is passed or one isn’t passed and there was no location ID provided at AppClient instantiation.
- Returns:
The specified location’s LocationAuth containing the newly created secret.
- Return type:
For more information, see Fleet Management API.
- async delete_location_secret(secret_id: str, location_id: str | None = None) None [source]
Delete a location secret.
await cloud.delete_location_secret( secret_id="abcd123-456-7890ab-cxyz98-989898xyzxyz", location_id="123xy12345" )
- Parameters:
location_id (str) – ID of the location to delete secret from. Defaults to the location ID provided at AppClient instantiation.
secret_id (str) – ID of the secret to delete.
- Raises:
GRPCError – If either an invalid location ID or secret ID is passed or a location ID isn’t passed and there was no location ID provided at AppClient instantiation.
For more information, see Fleet Management API.
- async get_robot(robot_id: str) viam.proto.app.Robot [source]
Get a machine.
machine = await cloud.get_robot(robot_id="1a123456-x1yz-0ab0-a12xyzabc")
- Parameters:
robot_id (str) – ID of the machine to get. You can copy this value from the URL of the machine’s page.
- Raises:
GRPCError – If an invalid machine ID is passed.
- Returns:
The machine.
- Return type:
For more information, see Fleet Management API.
- async get_rover_rental_robots(org_id: str) List[viam.proto.app.RoverRentalRobot] [source]
Returns a list of rover rental robots within an org.
rental_robots = await cloud.get_rover_rental_robots()
- Parameters:
org_id (str) – The ID of the organization to list rover rental robots for. You can obtain your organization ID from the Viam app’s organization settings page.
- Returns:
The list of rover rental robots.
- Return type:
For more information, see Fleet Management API.
- async get_robot_parts(robot_id: str) List[RobotPart] [source]
Get a list of all the parts under a specific machine.
list_of_parts = await cloud.get_robot_parts( robot_id="1a123456-x1yz-0ab0-a12xyzabc" )
- Parameters:
robot_id (str) – ID of the machine to get parts from.
- Raises:
GRPCError – If an invalid machine ID is passed.
- Returns:
The list of machine parts.
- Return type:
For more information, see Fleet Management API.
- async get_robot_part(robot_part_id: str, dest: str | None = None, indent: int = 4) RobotPart [source]
Get a machine part.
my_robot_part = await cloud.get_robot_part( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22" )
- Parameters:
robot_part_id (str) – ID of the machine part to get. You can retrieve this value by navigating to the machine’s page, clicking on the part status dropdown, and clicking the copy icon next to Part ID.
dest (Optional[str]) – Optional filepath to write the machine part’s config file in JSON format to.
indent (int) – Size (in number of spaces) of indent when writing config to dest. Defaults to 4.
- Raises:
GRPCError – If an invalid machine part ID is passed.
- Returns:
The machine part.
- Return type:
For more information, see Fleet Management API.
- async get_robot_part_logs(robot_part_id: str, filter: str | None = None, dest: str | None = None, log_levels: List[str] = [], num_log_entries: int = 100) List[LogEntry] [source]
Get the logs associated with a robot part.
part_logs = await cloud.get_robot_part_logs( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22", num_log_entries=20 )
- Parameters:
robot_part_id (str) – ID of the machine part to get logs from.
filter (Optional[str]) – Only include logs with messages that contain the string filter. Defaults to empty string “” (that is, no filter).
dest (Optional[str]) – Optional filepath to write the log entries to.
log_levels (List[str]) – List of log levels for which entries should be returned. Defaults to empty list, which returns all logs.
num_log_entries (int) – Number of log entries to return. Passing 0 returns all logs. Defaults to 100. All logs or the first num_log_entries logs will be returned, whichever comes first.
- Raises:
GRPCError – If an invalid robot part ID is passed.
- Returns:
The list of log entries.
- Return type:
For more information, see Fleet Management API.
- async tail_robot_part_logs(robot_part_id: str, errors_only: bool = True, filter: str | None = None) viam.app._logs._LogsStream[List[LogEntry]] [source]
Get an asynchronous iterator that receives live machine part logs.
logs_stream = await cloud.tail_robot_part_logs( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22" )
- Parameters:
robot_part_id (str) – ID of the machine part to retrieve logs from.
errors_only (bool) – Boolean specifying whether or not to only include error logs. Defaults to True.
filter (Optional[str]) – Only include logs with messages that contain the string filter. Defaults to empty string “” (that is, no filter).
- Returns:
The asynchronous iterator receiving live machine part logs.
- Return type:
_LogsStream[List[LogEntry]]
- async get_robot_part_history(robot_part_id: str) List[RobotPartHistoryEntry] [source]
Get a list containing the history of a machine part.
part_history = await cloud.get_robot_part_history( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22" )
- Parameters:
robot_part_id (str) – ID of the machine part to retrieve history from.
- Raises:
GRPCError – If an invalid machine part ID is provided.
- Returns:
The list of the machine part’s history.
- Return type:
For more information, see Fleet Management API.
- async update_robot_part(robot_part_id: str, name: str, robot_config: Mapping[str, Any] | None = None) RobotPart [source]
Change the name and assign an optional new configuration to a machine part.
my_machine_part = await cloud.update_robot_part( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22" )
- Parameters:
robot_part_id (str) – ID of the robot part to update.
name (str) – New name to be updated on the robot part.
robot_config (Mapping[str, Any]) – Optional new config represented as a dictionary to be updated on the machine part. The machine part’s config will remain as is (no change) if one isn’t passed.
- Raises:
GRPCError – If either an invalid machine part ID, name, or config is passed.
- Returns:
The newly updated robot part.
- Return type:
For more information, see Fleet Management API.
- async new_robot_part(robot_id: str, part_name: str) str [source]
Create a new machine part.
new_part_id = await cloud.new_robot_part( robot_id="1a123456-x1yz-0ab0-a12xyzabc", part_name="myNewSubPart" )
- Parameters:
robot_id (str) – ID of the machine to create a new part for.
part_name (str) – Name of the new part.
- Raises:
GRPCError – If either an invalid machine ID or name is passed.
- Returns:
The new machine part’s ID.
- Return type:
str
For more information, see Fleet Management API.
- async delete_robot_part(robot_part_id: str) None [source]
Delete the specified machine part.
await cloud.delete_robot_part( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22" )
- Parameters:
robot_part_id (str) – ID of the machine part to delete. Must be specified.
- Raises:
GRPCError – If an invalid machine part ID is passed.
For more information, see Fleet Management API.
- async get_robot_api_keys(robot_id: str) List[viam.proto.app.APIKeyWithAuthorizations] [source]
Gets the API Keys for the machine.
api_keys = await cloud.get_robot_api_keys(robot_id="robot-id")
- Parameters:
robot_id (str) – The ID of the machine.
- Returns:
The list of API keys.
- Return type:
List[APIKeyWithAuthorizations]
For more information, see Fleet Management API.
- async mark_part_as_main(robot_part_id: str) None [source]
Mark a machine part as the main part of a machine.
await cloud.mark_part_as_main( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22")
- Parameters:
robot_part_id (str) – ID of the machine part to mark as main.
- Raises:
GRPCError – If an invalid machine part ID is passed.
For more information, see Fleet Management API.
- async mark_part_for_restart(robot_part_id: str) None [source]
Mark the specified machine part for restart.
await cloud.mark_part_for_restart( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22")
- Parameters:
robot_part_id (str) – ID of the machine part to mark for restart.
- Raises:
GRPCError – If an invalid machine part ID is passed.
For more information, see Fleet Management API.
- async create_robot_part_secret(robot_part_id: str) RobotPart [source]
Create a machine part secret.
part_with_new_secret = await cloud.create_robot_part_secret( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22")
- Parameters:
robot_part_id (str) – ID of the machine part to create a secret for.
- Raises:
GRPCError – If an invalid machine part ID is passed.
- Returns:
The machine part the new secret was generated for.
- Return type:
For more information, see Fleet Management API.
- async delete_robot_part_secret(robot_part_id: str, secret_id: str) None [source]
Delete a machine part secret.
await cloud.delete_robot_part_secret( robot_part_id="abc12345-1a23-1234-ab12-a22a22a2aa22", secret_id="123xyz12-abcd-4321-12ab-12xy1xyz12xy")
- Parameters:
robot_part_id (str) – ID of the machine part to delete the secret from.
secret_id (str) – ID of the secret to delete.
- Raises:
GRPCError – If an invalid machine part ID or secret ID is passed.
For more information, see Fleet Management API.
- async list_robots(location_id: str | None = None) List[viam.proto.app.Robot] [source]
Get a list of all machines under the specified location.
list_of_machines = await cloud.list_robots(location_id="123ab12345")
- Parameters:
location_id (Optional[str]) – ID of the location to retrieve the machines from. Defaults to the location ID provided at AppClient instantiation.
- Raises:
GRPCError – If an invalid location ID is passed or one isn’t passed and there was no location ID provided at AppClient instantiation.
- Returns:
The list of robots.
- Return type:
List[viam.proto.app.Robot]
For more information, see Fleet Management API.
- async new_robot(name: str, location_id: str | None = None) str [source]
Create a new machine.
new_machine_id = await cloud.new_robot(name="beepboop", location_id="my-location-id")
- Parameters:
name (str) – Name of the new machine.
location_id (Optional[str]) – ID of the location under which to create the machine. Defaults to the current authorized location.
- Raises:
GRPCError – If an invalid location ID is passed or one isn’t passed and there was no location ID provided at AppClient instantiation.
- Returns:
The new robot’s ID.
- Return type:
str
For more information, see Fleet Management API.
- async update_robot(robot_id: str, name: str, location_id: str | None = None) viam.proto.app.Robot [source]
Change the name of an existing machine.
updated_robot = await cloud.update_robot( robot_id="1a123456-x1yz-0ab0-a12xyzabc", name="Orange-Robot", location_id="23ab12345" )
- Parameters:
robot_id (str) – ID of the machine to update.
name (str) – New name to be updated on the machine.
location_id (Optional[str]) – ID of the location under which the machine exists. Defaults to the location ID provided at AppClient instantiation
- Raises:
GRPCError – If either an invalid machine ID, name, or location ID is passed or a location ID isn’t passed and there was no location ID provided at AppClient instantiation.
- Returns:
The newly updated machine.
- Return type:
For more information, see Fleet Management API.
- async delete_robot(robot_id: str) None [source]
Delete the specified machine.
await cloud.delete_robot(robot_id="1a123456-x1yz-0ab0-a12xyzabc")
- Parameters:
robot_id (str) – ID of the machine to delete.
- Raises:
GRPCError – If an invalid machine ID is passed.
For more information, see Fleet Management API.
- async list_fragments(org_id: str, show_public: bool = True, visibilities: List[Fragment] | None = None) List[Fragment] [source]
Get a list of fragments under the currently authed-to organization.
fragments_list = await cloud.list_fragments(org_id="org-id", visibilities=[])
- Parameters:
org_id (str) – The ID of the organization to list fragments for. You can obtain your organization ID from the Viam app’s organization settings page.
show_public (bool) –
Optional boolean specifying whether or not to only show public fragments. If True, only public fragments will return. If False, only private fragments will return. Defaults to True.
Deprecated since version 0.25.0: Use
visibilities
instead.visibilities (Optional[List[Fragment.Visibility]]) – List of FragmentVisibilities specifying which types of fragments to include in the results. If empty, by default only public fragments will be returned.
- Returns:
The list of fragments.
- Return type:
For more information, see Fleet Management API.
- async get_fragment(fragment_id: str) Fragment [source]
Get a fragment.
# Get a fragment and print its name and when it was created. the_fragment = await cloud.get_fragment( fragment_id="12a12ab1-1234-5678-abcd-abcd01234567") print("Name: ", the_fragment.name, "\nCreated on: ", the_fragment.created_on)
- Parameters:
fragment_id (str) – ID of the fragment to get.
- Raises:
GRPCError – If an invalid fragment ID is passed.
- Returns:
The fragment.
- Return type:
For more information, see Fleet Management API.
- async create_fragment(org_id: str, name: str, config: Mapping[str, Any] | None = None) Fragment [source]
Create a new private fragment.
new_fragment = await cloud.create_fragment(org_id="org-id", name="cool_smart_machine_to_configure_several_of")
- Parameters:
org_id (str) – The ID of the organization to create the fragment within. You can obtain your organization ID from the Viam app’s organization settings page.
name (str) – Name of the fragment.
config (Optional[Mapping[str, Any]]) – Optional Dictionary representation of new config to assign to specified fragment. Can be assigned by updating the fragment.
- Raises:
GRPCError – If an invalid name is passed.
- Returns:
The newly created fragment.
- Return type:
For more information, see Fleet Management API.
- async update_fragment(fragment_id: str, name: str, config: Mapping[str, Any] | None = None, public: bool | None = None, visibility: Fragment | None = None) Fragment [source]
Update a fragment name AND its config and/or visibility.
updated_fragment = await cloud.update_fragment( fragment_id="12a12ab1-1234-5678-abcd-abcd01234567", name="better_name")
- Parameters:
fragment_id (str) – ID of the fragment to update.
name (str) – New name to associate with the fragment.
config (Optional[Mapping[str, Any]]) – Optional Dictionary representation of new config to assign to specified fragment. Not passing this parameter will leave the fragment’s config unchanged.
public (bool) –
Boolean specifying whether the fragment is public. Not passing this parameter will leave the fragment’s visibility unchanged. A fragment is private by default when created.
Deprecated since version 0.25.0: Use
visibility
instead.visibility (Optional[FragmentVisibility]) – Optional FragmentVisibility list specifying who should be allowed to view the fragment. Not passing this parameter will leave the fragment’s visibility unchanged. A fragment is private by default when created.
- Raises:
GRPCError – if an invalid ID, name, or config is passed.
- Returns:
The newly updated fragment.
- Return type:
For more information, see Fleet Management API.
- async delete_fragment(fragment_id: str) None [source]
Delete a fragment.
await cloud.delete_fragment( fragment_id="12a12ab1-1234-5678-abcd-abcd01234567")
- Parameters:
fragment_id (str) – ID of the fragment to delete.
- Raises:
GRPCError – If an invalid fragment ID is passed.
For more information, see Fleet Management API.
- async get_fragment_history(id: str, page_token: str | None = '', page_limit: int | None = 10) List[FragmentHistoryEntry] [source]
Get fragment history.
fragment_history = await cloud.get_fragment_history( id = "12a12ab1-1234-5678-abcd-abcd01234567", page_token = "pg-token", page_limit = 10 )
- Parameters:
id (str) – ID of the fragment to fetch history for.
page_token (Optional[str]) – the page token for the fragment history collection
page_limit (Optional[int]) – the number of fragment history documents to return in the result. The default page limit is 10.
- Raises:
GRPCError – if an invalid fragment id, page token or page limit is passed.
- Returns:
A list of documents with the fragment history.
- Return type:
viam.app.app_client.FragmentHistoryResponse
For more information, see Fleet Management API.
- async add_role(org_id: str, identity_id: str, role: Literal['owner'] | Literal['operator'], resource_type: Literal['organization'] | Literal['location'] | Literal['robot'], resource_id: str) None [source]
Add a role under the currently authed-to organization.
await cloud.add_role( org_id="<YOUR-ORG-ID>", identity_id="abc01234-0123-4567-ab12-a11a00a2aa22", role="owner", resource_type="location", resource_id="111ab12345" )
- Parameters:
org_id (str) – The ID of the organization to create the role in. You can obtain your organization ID from the Viam app’s organization settings page.
identity_id (str) – ID of the entity the role belongs to (for example, a user ID).
role (Union[Literal["owner"], Literal["operator"]]) – The role to add.
resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]) – Type of the resource to add role to. Must match resource_id.
resource_id (str) – ID of the resource the role applies to (that is, either an organization, location, or robot ID).
- Raises:
GRPCError – If either an invalid identity ID, role ID, resource type, or resource ID is passed.
For more information, see Fleet Management API.
- async remove_role(org_id: str, identity_id: str, role: Literal['owner'] | Literal['operator'], resource_type: Literal['organization'] | Literal['location'] | Literal['robot'], resource_id: str) None [source]
Remove a role under the currently authed-to organization.
await cloud.remove_role( org_id="<YOUR-ORG-ID>", identity_id="abc01234-0123-4567-ab12-a11a00a2aa22", role="owner", resource_type="location", resource_id="111ab12345" )
- Parameters:
org_id (str) – The ID of the organization the role exists in. You can obtain your organization ID from the Viam app’s organization settings page.
identity_id (str) – ID of the entity the role belongs to (for example, a user ID).
role (Union[Literal["owner"], Literal["operator"]]) – The role to remove.
resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]) – Type of the resource the role is being removed from. Must match resource_id.
resource_id (str) – ID of the resource the role applies to (that is, either an organization, location, or robot ID).
- Raises:
GRPCError – If either an invalid identity ID, role ID, resource type, or resource ID or is passed.
For more information, see Fleet Management API.
- async change_role(organization_id: str, old_identity_id: str, old_role: Literal['owner'] | Literal['operator'], old_resource_type: Literal['organization'] | Literal['location'] | Literal['robot'], old_resource_id: str, new_identity_id: str, new_role: Literal['owner'] | Literal['operator'], new_resource_type: Literal['organization'] | Literal['location'] | Literal['robot'], new_resource_id: str) None [source]
Changes a role to a new role.
await cloud.change_role( organization_id="<YOUR-ORG-ID>", old_identity_id="abc01234-0123-4567-ab12-a11a00a2aa22", old_role="operator", old_resource_type="location", old_resource_id="111ab12345", new_identity_id="abc01234-0123-4567-ab12-a11a00a2aa22", new_role="owner", new_resource_type="organization", new_resource_id="abc12345" )
- Parameters:
organization_id (str) – ID of the organization
old_identity_id (str) – ID of the entity the role belongs to (for example, a user ID).
old_role (Union[Literal["owner"], Literal["operator"]]) – The role to be changed.
old_resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]) – Type of the resource the role is added to. Must match old_resource_id.
old_resource_id (str) – ID of the resource the role applies to (that is, either an organization, location, or robot ID).
new_identity_id (str) – New ID of the entity the role belongs to (for example, a user ID).
new_role (Union[Literal["owner"], Literal["operator"]]) – The new role.
new_resource_type (Union[Literal["organization"], Literal["location"], Literal["robot"]]) – Type of the resource to add role to. Must match new_resource_id.
new_resource_id (str) – New ID of the resource the role applies to (that is, either an organization, location, or robot ID).
For more information, see Fleet Management API.
- async list_authorizations(org_id: str, resource_ids: List[str] | None = None) List[viam.proto.app.Authorization] [source]
List all authorizations under a specific resource (or resources) within the currently authed-to organization. If no resource IDs are provided, all resource authorizations within the organizations are returned.
list_of_auths = await cloud.list_authorizations( org_id="<YOUR-ORG-ID>", resource_ids=["1a123456-x1yz-0ab0-a12xyzabc"])
- Parameters:
org_id – The ID of the organization to list authorizations for.
resource_ids (Optional[List[str]]) – IDs of the resources to retrieve authorizations from. If None, defaults to all resources.
- Raises:
GRPCError – If an invalid resource ID is passed.
- Returns:
The list of authorizations.
- Return type:
For more information, see Fleet Management API.
- async check_permissions(permissions: List[viam.proto.app.AuthorizedPermissions]) List[viam.proto.app.AuthorizedPermissions] [source]
Checks validity of a list of permissions.
from viam.proto.app import AuthorizedPermissions # Check whether the entity you're currently authenticated to has permission to control and/or # read logs from robots in the "organization-identifier123" org permissions = [AuthorizedPermissions(resource_type="organization", resource_id="<YOUR-ORG-ID>", permissions=["control_robot", "read_robot_logs"])] filtered_permissions = await cloud.check_permissions(permissions)
- Parameters:
permissions (List[viam.proto.app.AuthorizedPermissions]) – the permissions to validate (for example, “read_organization”, “control_robot”)
- Raises:
GRPCError – If the list of permissions to validate is empty.
- Returns:
The permissions argument, with invalid permissions filtered out.
- Return type:
For more information, see Fleet Management API.
- async get_registry_item(item_id: str) viam.proto.app.RegistryItem [source]
Get registry item by ID.
item = await cloud.get_registry_item("item-id")
- Parameters:
item_id (str) – The ID of the registry item. This is the namespace and name of the item in the form namespace:name. For example, Viam’s csi-cam-pi module’s item ID would be viam:csi-cam-pi. You can also use org-id:name. For example, abc01234-0123-4567-ab12-a11a00a2aa22:training-script.
- Returns:
The registry item.
- Return type:
For more information, see Fleet Management API.
- async create_registry_item(organization_id: str, name: str, type: viam.proto.app.packages.PackageType.ValueType) None [source]
Create a registry item
from viam.proto.app.packages import PackageType await cloud.create_registry_item("<YOUR-ORG-ID>", "name", PackageType.PACKAGE_TYPE_ML_MODEL)
- Parameters:
organization_id (str) – The organization to create the registry item under.
name (str) – The name of the registry item, which must be unique within your org.
type (PackageType.ValueType) – The type of the item in the registry.
For more information, see Fleet Management API.
- async update_registry_item(item_id: str, type: viam.proto.app.packages.PackageType.ValueType, description: str, visibility: viam.proto.app.Visibility.ValueType) None [source]
Update a registry item.
from viam.proto.app.packages import PackageType from viam.proto.app import Visibility await cloud.update_registry_item( "your-namespace:your-name", PackageType.PACKAGE_TYPE_ML_TRAINING, "description", Visibility.VISIBILITY_PUBLIC )
- Parameters:
item_id (str) – The ID of the registry item, containing either the namespace and module name (for example, my-org:my-module) or organization ID and module name (org-id:my-module).
type (PackageType.ValueType) – The type of the item in the registry.
description (str) – The description of the registry item.
visibility (Visibility.ValueType) – The visibility of the registry item.
- async list_registry_items(organization_id: str, types: List[viam.proto.app.packages.PackageType.ValueType], visibilities: List[viam.proto.app.Visibility.ValueType], platforms: List[str], statuses: List[viam.proto.app.RegistryItemStatus.ValueType], search_term: str | None = None, page_token: str | None = None) List[viam.proto.app.RegistryItem] [source]
List the registry items in an organization.
from viam.proto.app.packages import PackageType from viam.proto.app import Visibility, RegistryItemStatus # List private, published ml training scripts in your organization registry_items = await cloud.list_registry_items( organization_id="<YOUR-ORG-ID>", types=[PackageType.PACKAGE_TYPE_ML_TRAINING], visibilities=[Visibility.VISIBILITY_PRIVATE], platforms=[""], statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED] ) # List public, published linux modules in all organizations registry_items = await cloud.list_registry_items( organization_id="", types=[PackageType.PACKAGE_TYPE_MODULE], visibilities=[Visibility.VISIBILITY_PUBLIC], platforms=["linux/any"], statuses=[RegistryItemStatus.REGISTRY_ITEM_STATUS_PUBLISHED] )
- Parameters:
organization_id (str) – The ID of the organization to return registry items for.
types (List[PackageType.ValueType]) – The types of registry items.
visibilities (List[Visibility.ValueType]) – The visibilities of registry items.
platforms (List[str]) – The platforms of registry items.
statuses (List[RegistryItemStatus.ValueType]) – The types of the items in the registry.
search_term (Optional[str]) – The search term of the registry items.
page_token (Optional[str]) – The page token of the registry items.
- Returns:
The list of registry items.
- Return type:
List[RegistryItem]
For more information, see Fleet Management API.
- async delete_registry_item(item_id: str) None [source]
Delete a registry item
await cloud.delete_registry_item("your-namespace:your-name")
- Parameters:
item_id (str) – The ID of the deleted registry item, containing either the namespace and module name (for example, my-org:my-module) or organization ID and module name (org-id:my-module).
For more information, see Fleet Management API.
- async create_module(org_id: str, name: str) Tuple[str, str] [source]
Create a module under the currently authed-to organization.
new_module = await cloud.create_module(org_id="org-id", name="cool_new_hoverboard_module") print("Module ID:", new_module[0])
- Parameters:
org_id (str) – The ID of the organization to create the module under. You can obtain your organization ID from the Viam app’s organization settings page.
name (str) – The name of the module. Must be unique within your organization.
- Raises:
GRPCError – If an invalid name (for example, “”) is passed.
- Returns:
A tuple containing the ID [0] of the new module and its URL [1].
- Return type:
Tuple[str, str]
For more information, see Fleet Management API.
- async update_module(module_id: str, url: str, description: str, models: List[viam.proto.app.Model] | None, entrypoint: str, public: bool = False) str [source]
Update the documentation URL, description, models, entrypoint, and/or the visibility of a module.
from viam.proto.app import Model model = Model( api="rdk:component:base", model="my-group:cool_new_hoverboard_module:wheeled" ) url_of_my_module = await cloud.update_module( module_id="my-group:cool_new_hoverboard_module", url="https://docsformymodule.viam.com", models=[model], description="A base to support hoverboards.", entrypoint="exec" )
- Parameters:
module_id (str) – ID of the module being updated, containing either the namespace and module name (for example, my-org:my-module) or organization ID and module name (org-id:my-module).
url (str) – The url to reference for documentation and code (NOT the url of the module itself).
description (str) – A short description of the module that explains its purpose.
models (List[viam.proto.app.Model]) – list of models that are available in the module.
entrypoint (str) – The executable to run to start the module program.
public (bool) – The visibility that should be set for the module. Defaults to False (private).
- Raises:
GRPCError – If either an invalid module ID, URL, list of models, or organization ID is passed.
- Returns:
The URL of the newly updated module.
- Return type:
str
For more information, see Fleet Management API.
- async upload_module_file(module_file_info: viam.proto.app.ModuleFileInfo | None, file: bytes) str [source]
Upload a module file
from viam.proto.app import ModuleFileInfo module_file_info = ModuleFileInfo( module_id = "sierra:cool_new_hoverboard_module", version = "1.0.0", platform = "darwin/arm64" ) file_id = await cloud.upload_module_file( module_file_info=module_file_info, file=b"<file>" )
- Parameters:
module_file_info (Optional[viam.proto.app.ModuleFileInfo]) – Relevant metadata.
file (bytes) – Bytes of file to upload.
- Returns:
URL of uploaded file.
- Return type:
str
For more information, see Fleet Management API.
- async get_module(module_id: str) viam.proto.app.Module [source]
Get a module.
the_module = await cloud.get_module(module_id="my-group:my-cool-modular-base")
- Parameters:
module_id (str) – ID of the module being retrieved, containing either the namespace and module name (for example, my-org:my-module) or organization ID and module name (org-id:my-module).
- Raises:
GRPCError – If an invalid module ID is passed.
- Returns:
The module.
- Return type:
For more information, see Fleet Management API.
- async list_modules(org_id: str) List[viam.proto.app.Module] [source]
List the modules under the currently authed-to organization.
modules_list = await cloud.list_modules("<YOUR-ORG-ID>")
- Parameters:
org_id (str) – The ID of the organization to list modules for. You can obtain your organization ID from the Viam app’s organization settings page.
- Returns:
The list of modules.
- Return type:
List[viam.proto.app.Module]
For more information, see Fleet Management API.
- async create_key(org_id: str, authorizations: List[APIKeyAuthorization], name: str | None = None) Tuple[str, str] [source]
Creates a new API key.
from viam.app.app_client import APIKeyAuthorization auth = APIKeyAuthorization( role="owner", resource_type="robot", resource_id="your-machine-id123" ) api_key, api_key_id = cloud.create_key( org_id="<YOUR-ORG-ID>", authorizations=[auth], name="my_key" )
- Parameters:
org_id (str) – The ID of the organization to create the key for. You can obtain your organization ID from the Viam app’s organization settings page.
authorizations (List[viam.proto.app.Authorization]) – A list of authorizations to associate with the key.
name (Optional[str]) – A name for the key. If None, defaults to the current timestamp.
- Raises:
GRPCError – If the authorizations list is empty.
- Returns:
The api key and api key ID.
- Return type:
Tuple[str, str]
For more information, see Fleet Management API.
- async delete_key(id: str) None [source]
Delete a API key.
await cloud.delete_key("key-id")
- Parameters:
id (str) – The ID of the API key.
For more information, see Fleet Management API.
- async create_key_from_existing_key_authorizations(id: str) Tuple[str, str] [source]
Creates a new API key with an existing key’s authorizations
api_key, api_key_id = await cloud.create_key_from_existing_key_authorizations( id="INSERT YOUR API KEY ID")
- Parameters:
id (str) – the ID of the API key to duplication authorizations from
- Returns:
The API key and API key id
- Return type:
Tuple[str, str]
For more information, see Fleet Management API.
- async list_keys(org_id: str) List[viam.proto.app.APIKeyWithAuthorizations] [source]
Lists all keys for the currently-authed-to org.
keys = await cloud.list_keys(org_id="<YOUR-ORG-ID>")
- Parameters:
org_id (str) – The ID of the organization to list API keys for. You can obtain your organization ID from the Viam app’s organization settings page.
- Returns:
The existing API keys and authorizations.
- Return type:
- async rotate_key(id: str) Tuple[str, str] [source]
Rotate an API key.
id, key = await cloud.rotate_key("key-id")
- Parameters:
id (str) – The ID of the key to be rotated.
- Returns:
The API key and API key id
- Return type:
Tuple[str, str]
For more information, see Fleet Management API.