Skip to content

entity_uri

construct_ayon_entity_uri(project_name, folder_path, product, version, representation_name)

Construct AYON entity URI from its components

Returns:

Name Type Description
str str

AYON Entity URI to query entity path.

Source code in client/ayon_core/pipeline/entity_uri.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
def construct_ayon_entity_uri(
        project_name: str,
        folder_path: str,
        product: str,
        version: Union[int, str],
        representation_name: str
) -> str:
    """Construct AYON entity URI from its components

    Returns:
        str: AYON Entity URI to query entity path.
    """
    if isinstance(version, int) and version < 0:
        version = "hero"
    if not (isinstance(version, int) or version in {"latest", "hero"}):
        raise ValueError(
            "Version must either be integer, 'latest' or 'hero'. "
            "Got: {}".format(version)
        )
    return (
        "ayon://{project}/{folder_path}?product={product}&version={version}"
        "&representation={representation}".format(
            project=project_name,
            folder_path=folder_path,
            product=product,
            version=version,
            representation=representation_name
        )
    )

parse_ayon_entity_uri(uri)

Parse AYON entity URI into individual components.

URI specification

ayon+entity://{project}/{folder}?product={product} &version={version} &representation={representation}

URI example: ayon+entity://test/hero?product=modelMain&version=2&representation=usd

However - if the netloc is ayon:// it will by default also resolve as ayon+entity:// on AYON server, thus we need to support both. The shorter ayon:// is preferred for user readability.

Example:

parse_ayon_entity_uri( "ayon://test/char/villain?product=modelMain&version=2&representation=usd" ) {'project': 'test', 'folderPath': '/char/villain', 'product': 'modelMain', 'version': 1, 'representation': 'usd'} parse_ayon_entity_uri( "ayon+entity://project/folder?product=renderMain&version=3&representation=exr" ) {'project': 'project', 'folderPath': '/folder', 'product': 'renderMain', 'version': 3, 'representation': 'exr'}

Returns:

Type Description
Optional[dict]

dict[str, Union[str, int]]: The individual key with their values as found in the ayon entity URI.

Source code in client/ayon_core/pipeline/entity_uri.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def parse_ayon_entity_uri(uri: str) -> Optional[dict]:
    """Parse AYON entity URI into individual components.

    URI specification:
        ayon+entity://{project}/{folder}?product={product}
            &version={version}
            &representation={representation}
    URI example:
        ayon+entity://test/hero?product=modelMain&version=2&representation=usd

    However - if the netloc is `ayon://` it will by default also resolve as
    `ayon+entity://` on AYON server, thus we need to support both. The shorter
    `ayon://` is preferred for user readability.

    Example:
    >>> parse_ayon_entity_uri(
    >>>     "ayon://test/char/villain?product=modelMain&version=2&representation=usd"
    >>> )
    {'project': 'test', 'folderPath': '/char/villain',
     'product': 'modelMain', 'version': 1,
     'representation': 'usd'}
    >>> parse_ayon_entity_uri(
    >>>     "ayon+entity://project/folder?product=renderMain&version=3&representation=exr"
    >>> )
    {'project': 'project', 'folderPath': '/folder',
     'product': 'renderMain', 'version': 3,
     'representation': 'exr'}

    Returns:
        dict[str, Union[str, int]]: The individual key with their values as
            found in the ayon entity URI.

    """  # noqa: E501

    if not (uri.startswith("ayon+entity://") or uri.startswith("ayon://")):
        return {}

    parsed = urlparse(uri)
    if parsed.scheme not in {"ayon+entity", "ayon"}:
        return {}

    result = {
        "project": parsed.netloc,
        "folderPath": "/" + parsed.path.strip("/")
    }
    query = parse_qs(parsed.query)
    for key in ["product", "version", "representation"]:
        if key in query:
            result[key] = query[key][0]

    # Convert version to integer if it is a digit
    version = result.get("version")
    if version is not None and version.isdigit():
        result["version"] = int(version)

    return result