Lookup

class audfactory.Lookup(server, repository, group_id, *, name='lookup', version=None)[source]

Lookup table for managing artifact flavors on Artifactory.

It creates one row for every flavor, and assigns a unique ID to it. The columns are parameters associated with the flavor. The parameter names are stored as column headers. The column values can be of type bool, float, int, NoneType, str. You cannot use strings that would be converted to any of the other types like 'None', 'True', 'False', '4.0', and '4'.

The following code converts an audfactory.Lookup object into a pandas.DataFrame:

index, data = [], []
if len(lookup.table) > 1:
    index = [entry[0] for entry in lookup.table[1:]]
    data = [entry[1:] for entry in lookup.table[1:]]
df = pd.DataFrame(data=data, index=index, columns=lookup.columns)
Parameters
Raises

RuntimeError – if no lookup tables or no lookup table with the specified version can be found

Examples

>>> lookup = Lookup(
...     'https://artifactory.audeering.com/artifactory',
...     'models-public-local',
...     'com.audeering.models.gender.voxcnn',
...     version='0.2.0',
... )
>>> lookup
id                                    purpose  sampling_rate  train-db
3bb24968-759a-11ea-ab25-309c2364e602  prod     16000          voxceleb1
>>> lookup.table
[['id', 'purpose', 'sampling_rate', 'train-db'],
 ['3bb24968-759a-11ea-ab25-309c2364e602', 'prod', 16000, 'voxceleb1']]
>>> lookup['3bb24968-759a-11ea-ab25-309c2364e602']
{'purpose': 'prod', 'sampling_rate': 16000, 'train-db': 'voxceleb1'}

__getitem__()

Lookup.__getitem__(uid)[source]

Get lookup table entry by ID.

Parameters

uid (str) – ID of lookup table entry

Return type

Dict

Returns

lookup table entry

append()

Lookup.append(params)[source]

Append entry to lookup table.

The lookup table entry gets a unique ID from params, self.name, self.group_id, self.version, and self.repository.

Parameters

params (Dict[str, Any]) – lookup table entry in the form of {column: parameter}

Return type

str

Returns

ID of added lookup table entry

Raises
  • RuntimeError – if entry for given params exists already, or the columns params do not match the columns of the lookup

  • ValueError – if params contain unsupported data types

clear()

Lookup.clear()[source]

Clear lookup table.

Return type

None

columns

Lookup.columns

Lookup table column names.

contains()

Lookup.contains(params)[source]

Check if lookup table contains entry.

Parameters

params (Dict[str, Any]) – lookup table entry in the form of {column: parameter}

Return type

bool

Returns

True if lookup table contains entry

create()

static Lookup.create(server, repository, group_id, version, params=(), *, name='lookup', force=False)[source]

Create lookup table on server.

Parameters
  • server (str) – URL of Artifactory server, e.g. https://audeering.jfrog.io/artifactory

  • repository (str) – repository of lookup table

  • group_id (str) – group ID of lookup table

  • version (str) – version of lookup table

  • params (Sequence[str]) – lookup table column names

  • name (str) – name of lookup table

  • force (bool) – if True an existing lookup table is overwritten

Return type

str

Returns

URL of lookup table

Raises

RuntimeError – if lookup table exists already and force=False

delete()

static Lookup.delete(server, repository, group_id, version, *, name='lookup', force=True)[source]

Delete lookup table on server.

Parameters
  • server (str) – URL of Artifactory server, e.g. https://audeering.jfrog.io/artifactory

  • repository (str) – repository of lookup table

  • group_id (str) – group ID of lookup table

  • version (str) – version of lookup table

  • name (str) – name of lookup table

  • force (bool) – if True removes lookup table even if not empty

Raises

RuntimeError – if lookup table is not empty and force=False

Return type

None

exists()

static Lookup.exists(server, repository, group_id, version, *, name='lookup')[source]

Check if lookup table exists on server.

Parameters
Return type

bool

Returns

True if lookup table exists

Examples

>>> Lookup.exists(
...     'https://artifactory.audeering.com/artifactory',
...     'models-public-local',
...     'com.audeering.models.gender.voxcnn',
...     '0.1.0',
... )
True

extend()

Lookup.extend(params)[source]

Extend columns of lookup table.

If no parameter values are given for the new columns, they are set to None.

Parameters

params (Union[str, Sequence[str], Dict[str, Any]]) – lookup table entry in the form of {column: parameter} or [column] or column

Return type

List[List]

Returns

lookup table

Raises

ValueError – if params contain unsupported data types

find()

Lookup.find(params)[source]

Find entry in lookup table.

Parameters

params (Dict[str, Any]) – lookup table entry in the form of {column: parameter}

Return type

str

Returns

ID of lookup table entry

Raises

RuntimeError – if lookup table entry cannot be found

generate_uid()

static Lookup.generate_uid(*, params, name, group_id, version, repository)[source]

Generate unique ID.

It converts params to a string, and concatenates it with name, group_id, version, and repository. From that concatenated string a unique ID is derived.

Parameters
  • params (Dict[str, Any]) – params in the form of {column: parameter}

  • group_id (str) – group ID of lookup table

  • name (str) – name of lookup table

  • version (str) – version of lookup table

  • repository (str) – repository of lookup table

Return type

str

Returns

unique identifier of length 36

Examples

>>> Lookup.generate_uid(
...     params={0: None},
...     name='name',
...     group_id='group.id',
...     version='1.0.0',
...     repository='models-public-local',
... )
'afe694a5-8bad-4dbc-73ba-636f18340615'

group_id

Lookup.group_id

group ID of lookup table

ids

Lookup.ids

Lookup table ids.

latest_version()

static Lookup.latest_version(server, repository, group_id, *, params=None, name='lookup')[source]

Latest version of lookup table on server.

Parameters
Return type

Optional[str]

Returns

latest version of lookup table

Examples

>>> Lookup.latest_version(
...     'https://artifactory.audeering.com/artifactory',
...     'models-public-local',
...     'com.audeering.models.gender.voxcnn',
... )
'0.2.0'

name

Lookup.name

name of lookup table

remove()

Lookup.remove(params)[source]

Remove entry from lookup table.

Parameters

params (Dict[str, Any]) – lookup table entry in the form of {column: parameter}

Return type

str

Returns

ID of removed entry

repository

Lookup.repository

repository of lookup table

server

Lookup.server

server URL

table

Lookup.table

Lookup table.

url

Lookup.url

Artifactory URL of lookup table

version

Lookup.version

version of lookup table

versions()

static Lookup.versions(server, repository, group_id, params=None, *, name='lookup')[source]

Available versions of lookup table on server.

Parameters
Return type

list

Returns

available versions of lookup table

Examples

>>> Lookup.versions(
...     'https://artifactory.audeering.com/artifactory',
...     'models-public-local',
...     'com.audeering.models.gender.voxcnn',
... )
['0.1.0', '0.2.0']