I faced this issue recently, and the solution I came up with was to write a custom query using the ADQL documentation and then use astroquery
to process the query.
import astroquery.gaia
num_stars = 10
query = f"""SELECT TOP {num_stars} dr3.ra, dr3.dec, dr3.phot_g_mean_mag, dr3.distance_gspphot
FROM gaiadr3.gaia_source as dr3
ORDER BY dr3.distance_gspphot ASC
"""
job = astroquery.gaia.Gaia.launch_job(query)
table = job.get_results()
print(table)
which outputs
ra dec phot_g_mean_mag distance_gspphot
deg deg mag pc
------------------ ------------------ --------------- ----------------
217.39232147200883 -62.67607511676666 8.984749 1.3011
269.44850252543836 4.739420051112412 8.1939745 1.8275
165.83095967577933 35.948653032660104 6.551172 2.5453
282.4587890175222 -23.83709744872712 9.126414 2.9762
53.22829341517546 -9.458168216292322 3.465752 3.2179
346.5039166796005 -35.8471642082214 6.5220323 3.2877
176.93768799004127 0.7991199702364985 9.601 3.3731
316.7484792940004 38.76386244649797 4.766713 3.4904
316.753662752556 38.75607277205679 5.4506445 3.4947
280.6830708352289 59.638357907754816 7.854393 3.522
<Table length=10>
name dtype unit description
---------------- ------- ---- --------------------------------------------------------------
ra float64 deg Right ascension
dec float64 deg Declination
phot_g_mean_mag float32 mag G-band mean magnitude
distance_gspphot float32 pc Distance from GSP-Phot Aeneas best library using BP/RP spectra
```