Example usage¶
To use aiod
in a project:
In [1]:
Copied!
import aiod
import aiod
In [2]:
Copied!
aiod.config.api_base_url = "http://localhost/"
aiod.config.auth_server_url = "http://localhost/aiod-auth/"
aiod.config.api_base_url = "http://localhost/"
aiod.config.auth_server_url = "http://localhost/aiod-auth/"
In [3]:
Copied!
aiod_counts = aiod.counts()
aiod_counts[["datasets", "ml_models"]]
aiod_counts = aiod.counts()
aiod_counts[["datasets", "ml_models"]]
Out[3]:
datasets | ml_models | |
---|---|---|
bonseyes | NaN | 12.0 |
example | NaN | 1.0 |
huggingface | 122252.0 | 1.0 |
openml | 5569.0 | 15767.0 |
stairwai | 1.0 | NaN |
zenodo | 305140.0 | NaN |
aida_cms | NaN | NaN |
aiod | NaN | NaN |
robotics4eu | NaN | NaN |
In [3]:
Copied!
help(aiod.datasets)
help(aiod.datasets)
Help on module aiod_sdk.resources.datasets in aiod_sdk.resources: NAME aiod_sdk.resources.datasets DATA counts = functools.partial(<function counts at 0x1062d54e0>, asset_typ... Retrieve the number of datasets assets in the metadata catalogue. Parameters (keywords required): version (str | None): The version of the endpoint (default is None). per_platform (bool): Whether to list counts per platform (default is False). Returns: int | dict[str, int]: The number datasets assets in the metadata catalogue. If the parameter per_platform is True, it returns a dict[str, int]. get_asset = functools.partial(<function get_asset at 0x1185527a0>, ass... Retrieve metadata for a specific datasets. Parameters (keywords required): identifier (int): The identifier of the datasets to retrieve. version (str | None): The version of the endpoint (default is None). data_format (Literal["pandas", "json"]): The desired format for the response (default is "pandas"). For "json" formats, the returned type is a json decoded type, in this case a dict. Returns: pd.Series | dict: The retrieved metadata for the specified datasets. get_assets_async = functools.partial(<function get_assets_async at 0x1... Asynchronously retrieve metadata for a list of datasets identifiers. Parameters (keywords required): identifiers (list[int]): The list of identifiers of the datasets to retrieve. version (str | None): The version of the endpoint (default is None). data_format (Literal["pandas", "json"]): The desired format for the response (default is "pandas"). For "json" formats, the returned type is a json decoded type, in this case a list of dict's. Returns: pd.DataFrame | list[dict]: The retrieved metadata for the specified datasets. get_list = functools.partial(<function get_list at 0x1060365c0>, asset... Retrieve a list of datasets from the catalogue. Parameters (keywords required): offset (int): The offset for pagination (default is 0). limit (int): The maximum number of items to retrieve (default is 10). version (str | None): The version of the endpoint (default is None). data_format (Literal["pandas", "json"]): The desired format for the response (default is "pandas"). For "json" formats, the returned type is a json decoded type, i.e. in this case a list of dict's. Returns: pd.DataFrame | list[dict]: The retrieved metadata in the specified format. get_list_async = functools.partial(<function get_list_async at 0x11855... Asynchronously retrieve a list of datasets from the catalogue in batches. Parameters (keywords required): offset (int): The offset for pagination (default is 0). limit (int): The maximum number of items to retrieve (default is 10). batch_size (int): The number of items in a a batch. version (str | None): The version of the endpoint (default is None). data_format (Literal["pandas", "json"]): The desired format for the response (default is "pandas"). For "json" formats, the returned type is a json decoded type, in this case a list of dict's. Returns: pd.DataFrame | list[dict]: The retrieved metadata in the specified format. FILE /Users/jmatias/Documents/develop/aiod-py-sdk/src/aiod_sdk/resources/datasets.py
In [4]:
Copied!
aiod.datasets.counts()
aiod.datasets.counts()
Out[4]:
41114
In [5]:
Copied!
datasets = aiod.datasets.get_list(offset=300, limit=2)
datasets[["platform", "platform_resource_identifier", "name", "date_published"]]
datasets = aiod.datasets.get_list(offset=300, limit=2)
datasets[["platform", "platform_resource_identifier", "name", "date_published"]]
Out[5]:
platform | platform_resource_identifier | name | date_published | |
---|---|---|---|---|
0 | openml | 436 | rosowky | 2014-09-28T23:37:11 |
1 | openml | 437 | garrat | 2014-09-28T23:37:13 |
In [6]:
Copied!
metadata_dataset302 = aiod.datasets.get_asset(identifier=302)
metadata_dataset302
metadata_dataset302 = aiod.datasets.get_asset(identifier=302)
metadata_dataset302
Out[6]:
platform openml platform_resource_identifier 437 name garrat date_published 2014-09-28T23:37:13 same_as https://www.openml.org/api/v1/json/data/437 is_accessible_for_free True version 1 ai_asset_identifier 307 ai_resource_identifier 317 aiod_entry {'editor': [], 'status': 'published', 'date_mo... alternate_name [] application_area [] citation [] contact [] creator [] description {'plain': '**Author**: **Source**: Unknown ... distribution [{'content_url': 'https://api.openml.org/data/... funder [] has_part [] industrial_sector [] is_part_of [] keyword [machine learning, mathematics] license public media [] note [] relevant_link [] relevant_resource [] relevant_to [] research_area [] scientific_domain [] size {'unit': 'instances', 'value': 10} identifier 302 dtype: object
Async methods¶
In [7]:
Copied!
data = await aiod.datasets.get_list_async(offset=300, limit=5, batch_size=3)
data[["platform", "name", "identifier", "is_accessible_for_free"]]
data = await aiod.datasets.get_list_async(offset=300, limit=5, batch_size=3)
data[["platform", "name", "identifier", "is_accessible_for_free"]]
Out[7]:
platform | name | identifier | is_accessible_for_free | |
---|---|---|---|---|
0 | openml | rosowky | 301 | True |
1 | openml | garrat | 302 | True |
2 | openml | doherty | 303 | True |
3 | openml | chang | 304 | True |
4 | openml | qsabr2 | 305 | True |
Authentication¶
In [11]:
Copied!
aiod.config.api_base_url = "https://aiod-dev.i3a.es/"
aiod.config.auth_server_url = "https://aiod-dev.i3a.es/aiod-auth/"
aiod.config.api_base_url = "https://aiod-dev.i3a.es/"
aiod.config.auth_server_url = "https://aiod-dev.i3a.es/aiod-auth/"
In [9]:
Copied!
aiod.login(username="USERNAME", password="PASSWORD")
# aiod.get_current_user()
aiod.login(username="USERNAME", password="PASSWORD")
# aiod.get_current_user()
In [9]:
Copied!
aiod.logout()
aiod.logout()
In [12]:
Copied!
aiod.get_current_user()
aiod.get_current_user()
Out[12]:
User(name='jsmatias', roles=('offline_access', 'uma_authorization', 'default-roles-aiod'))
In [ ]:
Copied!