Counting the # of shards is easy— you can list the bucket contents (see: https://cloud.google.com/storage/docs/listing-objects#storage-list-objects-python). The problem is limiting the output to 32 shards since BigQuery output files are limited to 1GB and your table might be larger. You might have to export to a BigQuery table, and launch a Dataflow job to convert that into < 32 shards.