Find distinct values (Python)

Finds the distinct values of a column for rows in a table.

This method finds all rows that match the filter, or all rows if no filter is applied. There can be performance, latency, and billing implications if there are many matching rows.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Returns a list of the distinct values of the specified key.

Parameters

Use the distinct method, which belongs to the astrapy.Table class.

Method signature
distinct(
  key: str,
  *,
  filter: Dict[str, Any],
  general_method_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> list[Any]
Name Type Summary

key

str

The key for which to find values. This can be:

  • A column name

  • An entry in a map column, such as metadata.language

  • An index in a list column, such as genres.2

See the examples for usage.

filter

dict

Optional. An object that defines filter criteria using the Data API filter syntax. Only rows that match this filter criteria will be inspected.

For a list of available filter operators and more examples, see Filter operators for tables (Python).

Default: No filter

general_method_timeout_ms

int

Optional. The maximum time, in milliseconds, that the whole operation, which might involve multiple HTTP requests, can take.

This parameter is aliased as timeout_ms.

Default: The default value for the table. This default is 30 seconds unless you specified a different default when you initialized the Table or DataAPIClient object. For more information, see Timeout options.

request_timeout_ms

int

Optional. The maximum time, in milliseconds, that the client should wait for each underlying HTTP request.

Default: The default value for the table. This default is 30 seconds unless you specified a different default when you initialized the Table or DataAPIClient object. For more information, see Timeout options.

Examples

The following examples demonstrate how to find distinct values of a column for rows in a table.

Find distinct values of a column for rows that match a filter

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient()
database = client.get_database(
    "API_ENDPOINT", token="APPLICATION_TOKEN"
)
table = database.get_table("TABLE_NAME")

# Find distinct values
result = table.distinct(
    "publication_year",
    filter={
        "$and": [
            {"is_checked_out": False},
            {"number_of_pages": {"$lt": 300}},
        ]
    },
)

print(result)

Find distinct values of a column for all rows

To find the distinct values of a column for all rows in the table, use an empty filter.

You should avoid this if you have a large number of rows.

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient()
database = client.get_database(
    "API_ENDPOINT", token="APPLICATION_TOKEN"
)
table = database.get_table("TABLE_NAME")

# Find distinct values
result = table.distinct("publication_year", filter={})

print(result)

Find distinct values of an entry in a map column

To find distinct values for an entry in a map column, use dot notation.

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient()
database = client.get_database(
    "API_ENDPOINT", token="APPLICATION_TOKEN"
)
table = database.get_table("TABLE_NAME")

# Find distinct values
result = table.distinct(
    "metadata.language",
    filter={
        "$and": [
            {"is_checked_out": False},
            {"number_of_pages": {"$lt": 300}},
        ]
    },
)

print(result)

Find distinct values of an index in a list column

To find distinct values for an index in a list column, use dot notation with the desired index.

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient()
database = client.get_database(
    "API_ENDPOINT", token="APPLICATION_TOKEN"
)
table = database.get_table("TABLE_NAME")

# Find distinct values
result = table.distinct(
    "topics.2",
    filter={
        "$and": [
            {"is_checked_out": False},
            {"number_of_pages": {"$lt": 300}},
        ]
    },
)

print(result)

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM