ln f = [lnρ + Ares/RT + P/ρRT]P,T + ln(RT) - 1,
where f is fugacity, Ares is residual Helmholtz energy, ρ is 'molar' density (n/V) and P, T, R are pressure, temperature and the universal gas constant, respectively.
Python functions to caculate volume and fugacity can be found here
Dekker, T.J. Finding a Zero by Means of Successive Linear Interpolation. In: Constructive Aspects of the Fundamental Theorem of Algebra. Ed. B. Dejon and P. Henrici. Wiley-Interscience, 1969. Pitzer, K.S. and Sterner, S.M. (1994). Equations of state valid continuously from zero to extreme pressures for H2O and CO2. Journal of Chemical Physics. 101: 3111-3116. Shampine, L.F. and Watts, H.A.(1970). FZERO, A Root-solving Code. Report SC-TM-70-631, Sandia Laboratories.
Sterner, S.M. and Pitzer, K.S. (1994). An equation of state for carbon dioxide valid from zero to extreme pressures. Contributions to Mineralogy and Petrology. 117: 362-374.