Skip to content

Read a DataSet's schema

The goal: print every column of one DataSet with its type.

The schema is the list of columns in a DataSet, each with a name and a type such as STRING or LONG.

Before you start

  • crew-dcs is installed, and your .env file holds DOMO_INSTANCE and DOMO_ACCESS_TOKEN (how).
  • Add one more line to your .env file: DOMO_DATASET_ID=<a DataSet id from your Domo>. The id is the long code in the DataSet's address, https://your-instance.domo.com/datasources/<id>/details/overview.

Read the schema

Reading changes nothing. Save this as read_schema.py next to your .env file:

import asyncio
import os

from dotenv import load_dotenv

from crew_dcs.auth import DomoTokenAuth
from crew_dcs.routes import dataset as dataset_routes

load_dotenv()  # copies the lines in .env into environment variables


async def main():
    async with DomoTokenAuth(
        domo_instance=os.environ["DOMO_INSTANCE"],
        domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
    ) as auth:
        dataset_id = os.environ["DOMO_DATASET_ID"]

        res = await dataset_routes.get_schema(dataset_id=dataset_id, auth=auth)

        # The columns are in the first table of the answer.
        columns = res.response["tables"][0]["columns"]
        print(len(columns), "columns")
        for column in columns:
            print(" ", column["name"], "-", column["type"])


asyncio.run(main())

Run it with uv run python read_schema.py from the project folder where you installed crew-dcs. (In a virtual environment, activate it and run python read_schema.py.)

What you should see

3 columns
  region - STRING
  sales - DOUBLE
  order_date - DATE

What the script does

get_schema takes the dataset_id and auth. It returns a response object. Its res.response is a dictionary, and the columns are a list under ["tables"][0]["columns"]. Each column is a dictionary with at least name, id and type. Domo may add more fields.

The route does not list columns that are hidden in Domo.

The class version

The class version is shorter if you want column objects instead of dictionaries:

from crew_dcs.classes.DomoDataset import DomoDataset

dataset = await DomoDataset.get_by_id(auth=auth, dataset_id=dataset_id)
columns = await dataset.Schema.get()
for column in columns:
    print(column.name, "-", column.type)

This goes inside the same async with block as the script above. Schema.get() calls the get_schema route for you and returns a list of column objects.

Changing the schema

This recipe only reads. The library has routes that write to a schema (alter_schema and alter_schema_descriptions), but neither has been checked against a live Domo instance, and both send back a whole column list. A wrong list can change other columns or drop columns that are hidden in Domo, and you cannot read back every field you would need to put it right. Change a schema in Domo itself, not with these two routes.

Check it in Domo

Open the DataSet in Data Center and go to its Schema tab. The column names and types should match what the script printed. (Tab names differ by Domo version.)

Errors you might hit

Each one is a kind of DomoError. The Errors page shows how to catch them. All of them are importable from crew_dcs.routes.dataset.

Error Likely cause
Dataset_GET_Error Domo refused the schema read. The id may be wrong, or the token's user may not be allowed to see the DataSet. A wrong or expired token also lands here, with "Authentication required (HTTP 401)" in the message.

Unlike get_dataset_by_id, get_schema raises Dataset_GET_Error for every failure, including a missing DataSet. It does not raise DatasetNotFoundError.

Python can also stop the script before Domo is involved. KeyError: 'DOMO_DATASET_ID' means the line is missing from .env. That is a Python error, not a Domo one. To test a token on its own, use who_am_i() from Authenticating to Domo.

Next