Dataset

a class based approach for interacting with Domo Datasets
token_auth = dmda.DomoTokenAuth(
    domo_instance=os.environ["DOMO_INSTANCE"],
    domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
)

await token_auth.who_am_i()

datasets = (
    await datacenter_routes.search_datacenter(
        auth=token_auth,
        entity_type=Datacenter_Enum.DATASET.value,
        additional_filters_ls=[
            {"filterType": "term", "field": "owned_by_id", "value": token_auth.user_id}
        ],
        # maximum = 25
    )
).response

dataset = next(
    (
        dataset
        for dataset in datasets
        if dataset["rowCount"] != 0 and str(dataset["ownedById"]) == str(token_auth.user_id)
    )
)
dataset
dataset_id = dataset["databaseId"]
dataset_id
'6bbff3ee-351c-467b-bf9b-d121af70dfb8'

MAIN - Domo Dataset


source

DomoDataset

 DomoDataset (auth:domolibrary.client.DomoAuth.DomoAuth, id:str='',
              display_type:str='', data_provider_type:str='', name:str='',
              description:str='', row_count:int=None,
              column_count:int=None, stream_id:int=None,
              owner:dict=<factory>, formula:dict=<factory>, Schema:domolib
              rary.classes.DomoDataset_Schema.DomoDataset_Schema=None, Str
              eam:domolibrary.classes.DomoDataset_Stream.DomoStream=None,
              Tags:domolibrary.classes.DomoTag.DomoTags=None,
              PDP:domolibrary.classes.DomoPDP.Dataset_PDP_Policies=None, C
              ertification:domolibrary.classes.DomoCertification.DomoCerti
              fication=None,
              Lineage:domolibrary.classes.DomoLineage.DomoLineage=None)

interacts with domo datasets

sample class-based implementation of get schema.

# this sample returns raw response from the api


ds = DomoDataset(auth=token_auth, id=dataset_id)

res = await ds.Schema.get(return_raw=True)

pd.DataFrame(res.get("tables")[0].get("columns"))[0:5]
name id type visible order
0 id id STRING True 0
1 group group LONG True 0
# this sample returns class-based response from the api

(await ds.Schema.get())[0:5]
[DomoDataset_Schema_Column(name='id', id='id', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='group', id='group', type='LONG', order=0, visible=True, upsert_key=False)]
# ds.stream_id
try:
    await ds.Stream.get()

except dmde.ClassError as e:
    print(e)
🛑  Dataset_Stream_GET_Error 🛑 - function: 🛑 DomoStream 🛑 None || dataset DomoDataset(id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', display_type='', data_provider_type='', name='', description='', row_count=None, column_count=None, stream_id=None, owner={}, formula={}, Schema=DomoDataset_Schema(dataset_id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', columns=[DomoDataset_Schema_Column(name='id', id='id', type='STRING', order=0, visible=True, upsert_key=False), DomoDataset_Schema_Column(name='group', id='group', type='LONG', order=0, visible=True, upsert_key=False)]), Stream=DomoStream(id=None, dataset_id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', transport_description=None, transport_version=None, update_method=None, data_provider_name=None, data_provider_key=None, account_id=None, account_display_name=None, account_userid=None, has_mapping=False, configuration=[], configuration_tables=[], configuration_query=None), Tags=DomoTags(tag_ls=[]), PDP=<domolibrary.classes.DomoPDP.Dataset_PDP_Policies object at 0x7ce1a5293b60>, Certification=None) has no stream_id || error
await ds.Tags.get()
[]

source

DomoDataset.get_by_id

 DomoDataset.get_by_id (dataset_id:str,
                        auth:domolibrary.client.DomoAuth.DomoAuth,
                        debug_api:bool=False, return_raw:bool=False,
                        session:httpx.AsyncClient=None,
                        debug_num_stacks_to_drop=2, parent_class:str=None)

retrieves dataset metadata

sample implementation of get_by_id

try:
    await DomoDataset.get_by_id(auth=token_auth, dataset_id="123")
except dmde.DomoError as e:
    print(e)
🛑  DatasetNotFoundError 🛑 - function: DomoDataset.get_traceback || 123 || status 404 || dataset - 123 not found at domo-community
domo_ds = await DomoDataset.get_by_id(auth=token_auth, dataset_id=dataset_id)

await domo_ds.Tags.get()

domo_ds
DomoDataset(id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', display_type='webform', data_provider_type='webform', name='LesMisNodes', description=None, row_count=77, column_count=2, stream_id=1041, owner={'id': '1893952720', 'name': 'Jae Wilson1', 'type': 'USER', 'group': False}, formula={}, Schema=DomoDataset_Schema(dataset_id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', columns=[]), Stream=DomoStream(id=1041, dataset_id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', transport_description=None, transport_version=None, update_method=None, data_provider_name=None, data_provider_key=None, account_id=None, account_display_name=None, account_userid=None, has_mapping=False, configuration=[], configuration_tables=[], configuration_query=None), Tags=DomoTags(tag_ls=[]), PDP=<domolibrary.classes.DomoPDP.Dataset_PDP_Policies object at 0x7ce1a5c65ac0>, Certification=None)

Query Dataset


source

DomoDataset.query_dataset_private

 DomoDataset.query_dataset_private
                                    (auth:domolibrary.client.DomoAuth.Domo
                                    Auth, dataset_id:str, sql:str, session
                                    :Optional[httpx.AsyncClient]=None, fil
                                    ter_pdp_policy_id_ls:List[int]=None,
                                    loop_until_end:bool=False, limit=100,
                                    skip=0, maximum=100,
                                    debug_api:bool=False,
                                    debug_loop:bool=False,
                                    debug_num_stacks_to_drop:int=2,
                                    timeout=10, maximum_retry:int=5,
                                    parent_class:str=None,
                                    is_return_dataframe:bool=True)
Type Default Details
auth DomoAuth
dataset_id str
sql str
session Optional None
filter_pdp_policy_id_ls List None filter by pdp policy
loop_until_end bool False retrieve all available rows
limit int 100 maximum rows to return per request. refers to PAGINATION
skip int 0
maximum int 100 equivalent to the LIMIT or TOP clause in SQL, the number of rows to return total
debug_api bool False
debug_loop bool False
debug_num_stacks_to_drop int 2
timeout int 10 larger API requests may require a longer response time
maximum_retry int 5
parent_class str None
is_return_dataframe bool True
Returns DataFrame
res = await DomoDataset.query_dataset_private(
    dataset_id=dataset_id,
    auth=token_auth,
    loop_until_end=True,
    sql="select * from table",
    limit=100,
    # filter_pdp_policy_id_ls=[1225, 1226],
    debug_api=False,
    debug_loop=False,
)

res

# print(len(res))
# res[0:5]
id group
0 Myriel 1
1 Napoleon 1
2 Mlle.Baptistine 1
3 Mme.Magloire 1
4 CountessdeLo 1
... ... ...
72 Toussaint 5
73 Child1 10
74 Child2 10
75 Brujon 4
76 Mme.Hucheloup 8

77 rows × 2 columns


source

DomoDataset.delete

 DomoDataset.delete (dataset_id=None,
                     auth:domolibrary.client.DomoAuth.DomoAuth=None,
                     debug_api:bool=False, session:httpx.AsyncClient=None)
user_id = (await token_auth.who_am_i()).response['id']
domo_user = await dmdu.DomoUser.get_by_id(user_id=user_id, auth=token_auth)

domo_dataset = await DomoDataset.get_by_id(dataset_id=dataset_id, auth=token_auth)


await domo_dataset.share(member=domo_user, is_send_email=False, debug_api=False)
ResponseGetData(status=200, response='updated access list USER - 1893952720 added to 6bbff3ee-351c-467b-bf9b-d121af70dfb8', is_success=True, parent_class=None)
#     @classmethod
#     async def query_dataset(cls,
#                             sql: str,
#                             dataset_id: str,
#                             dev_auth: DomoDeveloperAuth,
#                             debug_api: bool = False,
#                             session: httpx.AsyncClient = None) -> pd.DataFrame:

#         if debug_api:
#             print("query dataset class method")
#             print({'dataset_id': dataset_id,
#                    'dev_auth': dev_auth})

#         res = await dataset_routes.query_dataset_public(dev_auth=dev_auth, id=dataset_id, sql=sql, session=session,
#                                                         debug=debug)

#         if debug_api:
#             print(res.response)

#         if res.status == 200:
#             df = pd.DataFrame(data=res.response.get('rows'),
#                               columns=res.response.get('columns'))
#             return df
#         return None

Upload Data


source

DomoDataset.index_dataset

 DomoDataset.index_dataset
                            (auth:domolibrary.client.DomoAuth.DomoAuth=Non
                            e, dataset_id:str=None, debug_api:bool=False,
                            session:httpx.AsyncClient=None)

source

DomoDataset.upload_data

 DomoDataset.upload_data (upload_df:pandas.core.frame.DataFrame=None,
                          upload_df_ls:list[pandas.core.frame.DataFrame]=N
                          one, upload_file:_io.TextIOWrapper=None,
                          upload_method:str='REPLACE',
                          partition_key:str=None, is_index:bool=True,
                          dataset_upload_id=None,
                          session:httpx.AsyncClient=None,
                          debug_api:bool=False, debug_prn:bool=False)
Type Default Details
upload_df DataFrame None
upload_df_ls list None
upload_file TextIOWrapper None
upload_method str REPLACE APPEND or REPLACE
partition_key str None
is_index bool True
dataset_upload_id NoneType None
session AsyncClient None
debug_api bool False
debug_prn bool False

Partitions


source

DomoDataset.list_partitions

 DomoDataset.list_partitions
                              (auth:domolibrary.client.DomoAuth.DomoAuth=N
                              one, dataset_id:str=None,
                              debug_api:bool=False,
                              session:httpx.AsyncClient=None)

sample implementation list_partitions

ds = await DomoDataset.get_by_id(auth=token_auth, dataset_id=dataset_id)
ds_partition_ls = await ds.list_partitions()

pd.DataFrame(ds_partition_ls[0:5])

source

DomoDataset.create

 DomoDataset.create (dataset_name:str, dataset_type='api', schema=None,
                     auth:domolibrary.client.DomoAuth.DomoAuth=None,
                     debug_api:bool=False, session:httpx.AsyncClient=None,
                     return_raw:bool=False)

sample implementation of create dataset

# await DomoDataset.create( dataset_name= 'Hello world_v2', dataset_type='API', auth = token_auth, debug_api = False)

source

DomoDataset.delete_partition

 DomoDataset.delete_partition (dataset_partition_id:str,
                               dataset_id:str=None,
                               empty_df:pandas.core.frame.DataFrame=None, 
                               auth:domolibrary.client.DomoAuth.DomoAuth=N
                               one, is_index:bool=True,
                               debug_api:bool=False, debug_prn:bool=False,
                               return_raw:bool=False)

sample data delete_partition

try:

    dataset = await DomoDataset.get_by_id(auth=token_auth, dataset_id=dataset_id)

    ds_partition_ls = await dataset.list_partitions()
    print(ds_partition_ls)

    ds = await dataset.delete_partition(
        dataset_partition_id="2023-04-27",
        auth=token_auth,
        dataset_id=dataset_id,
        debug_api=False,
        debug_prn=True,
    )

    print(await dataset.list_partitions())

except dmde.DomoError as e:
    print(e)
[]


🎭 starting Stage 1


🎭 Stage 1 response -- 200
ResponseGetData(status=200, response='', is_success=True, parent_class=None)
starting Stage 2


🎭 Stage 2 response -- 200
starting Stage 3


🎭 Stage 3 response -- 200
[]
await dataset.Lineage.get(debug_api = False, return_raw = False)
[DomoDataset(id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', display_type='webform', data_provider_type='webform', name='LesMisNodes', description=None, row_count=77, column_count=2, stream_id=1041, owner={'id': '1893952720', 'name': 'Jae Wilson1', 'type': 'USER', 'group': False}, formula={}, Schema=DomoDataset_Schema(dataset_id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', columns=[]), Stream=DomoStream(id=1041, dataset_id='6bbff3ee-351c-467b-bf9b-d121af70dfb8', transport_description=None, transport_version=None, update_method=None, data_provider_name=None, data_provider_key=None, account_id=None, account_display_name=None, account_userid=None, has_mapping=False, configuration=[], configuration_tables=[], configuration_query=None), Tags=DomoTags(tag_ls=[]), PDP=<domolibrary.classes.DomoPDP.Dataset_PDP_Policies object at 0x7ce1a51d86b0>, Certification=None)]