from astropy.cosmology import WMAP9 as cosmo
import astropy.units as u
redshift = <whatever>
appmag, size_arcsec = <whatever>, <whatever>
# use the cosmology modules to get luminosity distance (DL) and angular size distance (DA).
# these will be astropy objects with units attached
DL = cosmo.luminosity_distance(redshift) # in Mpc
DA = cosmo.angular_diameter_distance(redshift) # in Mpc
# to calculate an absolute magnitude, convert DL to parsecs and extract just the value (no units) to pass into the log10 function
absmag = appmag - 5*np.log10(DL.to(u.pc).value) + 5
# convert angular size to physical size using the angular size distance
r_phys = r_arcsec * DA.value / 206265.