ayon_api.utils module

class RepresentationHierarchy(project, folder, task, product, version, representation)

Bases: tuple

folder

Alias for field number 1

product

Alias for field number 3

project

Alias for field number 0

representation

Alias for field number 5

task

Alias for field number 2

version

Alias for field number 4

class RepresentationParents(version, product, folder, project)

Bases: tuple

folder

Alias for field number 2

product

Alias for field number 1

project

Alias for field number 3

version

Alias for field number 0

class ThumbnailContent(project_name, thumbnail_id, content, content_type)[source]

Bases: object

Wrapper for thumbnail content.

Parameters:
  • project_name (str) – Project name.

  • thumbnail_id (Union[str, None]) – Thumbnail id.

  • content_type (Union[str, None]) – Content type e.g. ‘image/png’.

  • content (Union[bytes, None]) – Thumbnail content.

property id

Wrapper for thumbnail id.

property is_valid

Content of thumbnail is valid.

Returns:

Content is valid and can be used.

Return type:

bool

class TransferProgress[source]

Bases: object

Object to store progress of download/upload from/to server.

add_transferred_chunk(chunk_size)[source]

Add transferred chunk size in bytes.

Parameters:

chunk_size (int) – Add transferred chunk size in bytes.

property content_size

Content size in bytes.

Returns:

Content size in bytes or None

if is unknown.

Return type:

Union[int, None]

property destination_url

Destination url where transfer happens.

Note

Consider this as title. Must be set using

‘set_source_url’ or ‘N/A’ will be returned.

Returns:

Destination url where transfer happens.

Return type:

str

property fail_reason

Get reason why transfer failed.

Returns:

Reason why transfer

failed or None.

Return type:

Union[str, None]

property failed

Transfer failed.

Returns:

True if transfer failed.

Return type:

bool

get_content_size()[source]

Content size in bytes.

Returns:

Content size in bytes or None

if is unknown.

Return type:

Union[int, None]

get_destination_url()[source]

Destination url where transfer happens.

Note

Consider this as title. Must be set using

‘set_source_url’ or ‘N/A’ will be returned.

Returns:

Destination url where transfer happens.

Return type:

str

get_fail_reason()[source]

Get reason why transfer failed.

Returns:

Reason why transfer

failed or None.

Return type:

Union[str, None]

get_failed()[source]

Transfer failed.

Returns:

True if transfer failed.

Return type:

bool

get_source_url()[source]

Source url from where transfer happens.

Note

Consider this as title. Must be set using

‘set_source_url’ or ‘N/A’ will be returned.

Returns:

Source url from where transfer happens.

Return type:

str

get_started()[source]

Transfer was started.

Returns:

True if transfer started.

Return type:

bool

get_transfer_done()[source]

Transfer finished.

Returns:

Transfer finished.

Return type:

bool

get_transferred_size()[source]

Already transferred size in bytes.

Returns:

Already transferred size in bytes.

Return type:

int

property is_running

Check if transfer is running.

Returns:

True if transfer is running.

Return type:

bool

set_content_size(content_size)[source]

Set content size in bytes.

Parameters:

content_size (int) – Content size in bytes.

Raises:

ValueError – If content size was already set.

set_destination_url(url)[source]

Set destination url where transfer happens.

Parameters:

url (str) – Destination url where transfer happens.

set_failed(reason)[source]

Mark progress as failed.

Parameters:

reason (str) – Reason why transfer failed.

set_source_url(url)[source]

Set source url from where transfer happens.

Parameters:

url (str) – Source url from where transfer happens.

set_started()[source]

Mark that transfer started.

Raises:

ValueError – If transfer was already started.

set_transfer_done()[source]

Mark progress as transfer finished.

Raises:

ValueError – If progress was already marked as done or wasn’t started yet.

set_transferred_size(transferred)[source]

Set already transferred size in bytes.

Parameters:

transferred (int) – Already transferred size in bytes.

property source_url

Source url from where transfer happens.

Note

Consider this as title. Must be set using

‘set_source_url’ or ‘N/A’ will be returned.

Returns:

Source url from where transfer happens.

Return type:

str

property started

Transfer was started.

Returns:

True if transfer started.

Return type:

bool

property transfer_done

Transfer finished.

Returns:

Transfer finished.

Return type:

bool

property transfer_progress

Get transfer progress in percents.

Returns:

Transfer progress in percents or ‘None’

if content size is unknown.

Return type:

Union[float, None]

property transferred_size

Already transferred size in bytes.

Returns:

Already transferred size in bytes.

Return type:

int

abort_web_action_event(server_url: str, action_token: str, reason: str)[source]

Abort web action event using action token.

A web action event could not be processed for some reason.

Parameters:
  • server_url (str) – AYON server url.

  • action_token (str) – Action token.

  • reason (str) – Reason why webaction event was aborted.

Returns:

Response from server.

Return type:

requests.Response

convert_entity_id(entity_id)[source]
convert_or_create_entity_id(entity_id=None)[source]
create_dependency_package_basename(platform_name=None)[source]

Create basename for dependency package file.

Parameters:

platform_name (Optional[str]) – Name of platform for which the bundle is targeted. Default value is current platform.

Returns:

Dependency package name with timestamp and platform.

Return type:

str

create_entity_id()[source]
entity_data_json_default(value)[source]
failed_json_default(value)[source]
get_default_settings_variant()[source]

Default settings variant.

Returns:

Settings variant from environment variable or ‘production’.

Return type:

str

get_default_site_id()[source]

Site id used for server connection.

Returns:

Site id from environment variable or None.

Return type:

Union[str, None]

get_default_timeout()[source]

Default value for requests timeout.

First looks for environment variable SERVER_TIMEOUT_ENV_KEY which can affect timeout value. If not available then use 10.0 s.

Returns:

Timeout value in seconds.

Return type:

float

get_media_mime_type(filepath: str) Optional[str][source]

Determine Mime-Type of a file.

Parameters:

filepath (str) – Path to file.

Returns:

Mime type or None if is unknown mime type.

Return type:

Optional[str]

get_media_mime_type_for_content(content: bytes) Optional[str][source]
get_user_by_token(url, token, timeout=None)[source]

Get user information by url and token.

Parameters:
  • url (str) – Server url.

  • token (str) – User’s token.

  • timeout (Optional[float]) – Timeout for request. Value from ‘get_default_timeout’ is used if not specified.

Returns:

User information if url and token are valid.

Return type:

Optional[Dict[str, Any]]

is_token_valid(url, token, timeout=None)[source]

Check if token is valid.

Token can be a user token or service api key.

Parameters:
  • url (str) – Server url.

  • token (str) – User’s token.

  • timeout (Optional[float]) – Timeout for request. Value from ‘get_default_timeout’ is used if not specified.

Returns:

True if token is valid.

Return type:

bool

login_to_server(url, username, password, timeout=None)[source]

Use login to the server to receive token.

Parameters:
  • url (str) – Server url.

  • username (str) – User’s username.

  • password (str) – User’s password.

  • timeout (Optional[float]) – Timeout for request. Value from ‘get_default_timeout’ is used if not specified.

Returns:

User’s token if login was successfull.

Otherwise ‘None’.

Return type:

Union[str, None]

logout_from_server(url, token, timeout=None)[source]

Logout from server and throw token away.

Parameters:
  • url (str) – Url from which should be logged out.

  • token (str) – Token which should be used to log out.

  • timeout (Optional[float]) – Timeout for request. Value from ‘get_default_timeout’ is used if not specified.

prepare_attribute_changes(old_entity, new_entity, replace=False)[source]
prepare_entity_changes(old_entity, new_entity, replace=False)[source]

Prepare changes of entities.

prepare_query_string(key_values)[source]

Prepare data to query string.

If there are any values a query starting with ‘?’ is returned otherwise an empty string.

Parameters:
  • dict[str – Query values.

  • Any] – Query values.

Returns:

Query string.

Return type:

str

slugify_string(input_string, separator='_', slug_whitelist='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', split_chars=' ,./\\;:!|*^#@~+-_=', min_length=1, lower=False, make_set=False)[source]

Slugify a text string.

This function removes transliterates input string to ASCII, removes special characters and use join resulting elements using specified separator.

Parameters:
  • input_string (str) – Input string to slugify

  • separator (str) – A string used to separate returned elements (default: “_”)

  • slug_whitelist (str) – Characters allowed in the output (default: ascii letters, digits and the separator)

  • split_chars (str) – Set of characters used for word splitting (there is a sane default)

  • lower (bool) – Convert to lower-case (default: False)

  • make_set (bool) – Return “set” object instead of string.

  • min_length (int) – Minimal length of an element (word).

Returns:

Based on ‘make_set’ value returns slugified

string.

Return type:

Union[str, Set[str]]

take_web_action_event(server_url: str, action_token: str) Dict[str, Any][source]

Take web action event using action token.

Action token is generated by AYON server and passed to AYON launcher.

Parameters:
  • server_url (str) – AYON server url.

  • action_token (str) – Action token.

Returns:

Web action event.

Return type:

Dict[str, Any]

validate_url(url, timeout=None)[source]

Validate url if is valid and server is available.

Validation checks if can be parsed as url and contains scheme.

Function will try to autofix url thus will return modified url when connection to server works.

my_url = "my.server.url"
try:
    # Store new url
    validated_url = validate_url(my_url)

except UrlError:
    # Handle invalid url
    ...
Parameters:
  • url (str) – Server url.

  • timeout (Optional[int]) – Timeout in seconds for connection to server.

Returns:

Url which was used to connect to server.

Raises:

UrlError – Error with short description and hints for user.