Python Wrapper

Automatic installation

Using the pip installation program, you can install the official release from the pypi server using:

pip install CoolProp

If you dare, you can also try the latest nightly release from Python or get it directly from the development server using:

pip install -vvv --pre --trusted-host www.coolprop.dreamhosters.com --find-links http://www.coolprop.dreamhosters.com/binaries/Python/ -U --force-reinstall CoolProp

Manual installation

Compilation of the python wrapper requires a few common wrapper pre-requisites

On all platforms, if it is not already there, you need Cython to be installed:

sudo pip install Cython

Then, follow the commands:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp/wrappers/Python
# Start the installation
sudo python setup.py install

If you would like to install CoolProp just for a given version of Python (for example if python links to python3.4 and you also have a python2.7 executable), simply use this version of python to execute the setup.py script:

sudo python2.7 setup.py install

Local installation

If you prefer not to be sudoer when compiling coolprop on Linux/MacOS, you can also install it locally using the --user switch:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp/wrappers/Python
# Start the installation
python setup.py install --user

For Pyzo users

Suppose the directory containing pyzo is on your Desktop in ~/Desktop/pyzo2014a/. Then you can install CoolProp to be used within pyzo by following the same lines as above:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp/wrappers/Python
# Start the installation (~/Desktop/pyzo2014a/ to be changed according to
# your effective installation)
sudo ~/Desktop/pyzo2014a/bin/python setup.py install

Usage

There is example code at the end of this page

Once installed, you can use CoolProp for various things:

  • Compute special values in SI units:

    import CoolProp.CoolProp as CP
    fluid = 'Water'
    pressure_at_critical_point = CP.PropsSI(fluid,'pcrit')
    # Massic volume (in m^3/kg) is the inverse of density
    # (or volumic mass in kg/m^3). Let's compute the massic volume of liquid
    # at 1bar (1e5 Pa) of pressure
    vL = 1/CP.PropsSI('D','P',1e5,'Q',0,fluid)
    # Same for saturated vapor
    vG = 1/CP.PropsSI('D','P',1e5,'Q',1,fluid)
    
  • Get some nice graphs:

    import CoolProp.Plots as CPP
    ph_plot = CPP.PropertyPlot('Water','Ph')
    ph_plot.savefig('enthalpy_pressure_graph_for_Water.png')
    
  • Solve thermodynamics exercices

  • Make you own more complex graphs if you feel the graphing interface is lacking something

  • Make even more complex graphs using 3D stuff

Example Code

from __future__ import print_function
from CoolProp import AbstractState
from CoolProp.CoolProp import PhaseSI, PropsSI, get_global_param_string
import CoolProp.CoolProp as CoolProp
from CoolProp.HumidAirProp import HAPropsSI
from math import sin
print("**************** INFORMATION ***************")
print("This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell")
print("CoolProp version:", get_global_param_string("version"))
print("CoolProp gitrevision:", get_global_param_string("gitrevision"))
print("CoolProp Fluids:", get_global_param_string("FluidsList"))
# See http://www.coolprop.org/coolprop/HighLevelAPI.html#table-of-string-inputs-to-propssi-function for a list of inputs to high-level interface
print("*********** HIGH LEVEL INTERFACE *****************")
print("Critical temperature of water:", PropsSI("Water", "Tcrit"), "K")
print("Boiling temperature of water at 101325 Pa:", PropsSI("T", "P", 101325, "Q", 0, "Water"), "K")
print("Phase of water at 101325 Pa and 300 K:", PhaseSI("P", 101325, "T", 300, "Water"))
print("c_p of water at 101325 Pa and 300 K:", PropsSI("C", "P", 101325, "T", 300, "Water"), "J/kg/K")
print("c_p of water (using derivatives) at 101325 Pa and 300 K:", PropsSI("d(H)/d(T)|P", "P", 101325, "T", 300, "Water"), "J/kg/K")
print("*********** HUMID AIR PROPERTIES *****************")
print("Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa:", HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5), "kg_w/kg_da")
print("Relative humidity from last calculation:", HAPropsSI("R", "T", 300, "P", 101325, "W", HAPropsSI("W", "T", 300, "P", 101325, "R", 0.5)), "(fractional)")
print("*********** INCOMPRESSIBLE FLUID AND BRINES *****************")
print("Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa:", PropsSI("D", "T", 300, "P", 101325, "INCOMP::MEG-50%"), "kg/m^3")
print("Viscosity of Therminol D12 at 350 K, 101325 Pa:", PropsSI("V", "T", 350, "P", 101325, "INCOMP::TD12"), "Pa-s")
# If you don't have REFPROP installed, disable the following lines
print("*********** REFPROP *****************")
print("REFPROP version:", get_global_param_string("REFPROP_version"))
print("Critical temperature of water:", PropsSI("REFPROP::Water", "Tcrit"), "K")
print("Boiling temperature of water at 101325 Pa:", PropsSI("T", "P", 101325, "Q", 0, "REFPROP::Water"), "K")
print("c_p of water at 101325 Pa and 300 K:", PropsSI("C", "P", 101325, "T", 300, "REFPROP::Water"), "J/kg/K")
print("*********** TABULAR BACKENDS *****************")
TAB = AbstractState("BICUBIC&HEOS", "R245fa")
TAB.update(CoolProp.PT_INPUTS, 101325, 300)
print("Mass density of refrigerant R245fa at 300 K, 101325 Pa:", TAB.rhomass(), "kg/m^3")
print("*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************")
AS_SAT = AbstractState("HEOS", "R245fa")
AS_SAT.update(CoolProp.PQ_INPUTS, 101325, 0)
print("First saturation derivative:", AS_SAT.first_saturation_deriv(CoolProp.iP, CoolProp.iT), "Pa/K")
print("*********** LOW-LEVEL INTERFACE *****************")
AS = AbstractState("HEOS", "Water&Ethanol")
z = [0.5, 0.5]
AS.set_mole_fractions(z)
AS.update(CoolProp.PQ_INPUTS, 101325, 1)
print("Normal boiling point temperature of water and ethanol:", AS.T(), "K")
# If you don't have REFPROP installed, disable the following block
print("*********** LOW-LEVEL INTERFACE (REFPROP) *****************")
AS2 = AbstractState("REFPROP", "Methane&Ethane")
z2 = [0.2, 0.8]
AS2.set_mole_fractions(z2)
AS2.update(CoolProp.QT_INPUTS, 1, 120)
print("Vapor molar density:", AS2.keyed_output(CoolProp.iDmolar), "mol/m^3")

Example Code Output

**************** INFORMATION ***************
This example was auto-generated by the language-agnostic dev/scripts/example_generator.py script written by Ian Bell
CoolProp version: 6.1.0
CoolProp gitrevision: 7864c2614ce5a0ef972386ee7f39859f0d3f8038
CoolProp Fluids: 1-Butene,Acetone,Air,Ammonia,Argon,Benzene,CarbonDioxide,CarbonMonoxide,CarbonylSulfide,cis-2-Butene,CycloHexane,Cyclopentane,CycloPropane,D4,D5,D6,Deuterium,Dichloroethane,DiethylEther,DimethylCarbonate,DimethylEther,Ethane,Ethanol,EthylBenzene,Ethylene,EthyleneOxide,Fluorine,HeavyWater,Helium,HFE143m,Hydrogen,HydrogenChloride,HydrogenSulfide,IsoButane,IsoButene,Isohexane,Isopentane,Krypton,m-Xylene,MD2M,MD3M,MD4M,MDM,Methane,Methanol,MethylLinoleate,MethylLinolenate,MethylOleate,MethylPalmitate,MethylStearate,MM,n-Butane,n-Decane,n-Dodecane,n-Heptane,n-Hexane,n-Nonane,n-Octane,n-Pentane,n-Propane,n-Undecane,Neon,Neopentane,Nitrogen,NitrousOxide,Novec649,o-Xylene,OrthoDeuterium,OrthoHydrogen,Oxygen,p-Xylene,ParaDeuterium,ParaHydrogen,Propylene,Propyne,R11,R113,R114,R115,R116,R12,R123,R1233zd(E),R1234yf,R1234ze(E),R1234ze(Z),R124,R125,R13,R134a,R13I1,R14,R141b,R142b,R143a,R152A,R161,R21,R218,R22,R227EA,R23,R236EA,R236FA,R245ca,R245fa,R32,R365MFC,R40,R404A,R407C,R41,R410A,R507A,RC318,SES36,SulfurDioxide,SulfurHexafluoride,Toluene,trans-2-Butene,Water,Xenon
*********** HIGH LEVEL INTERFACE *****************
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.124295848 K
Phase of water at 101325 Pa and 300 K: liquid
c_p of water at 101325 Pa and 300 K: 4180.63577656 J/kg/K
c_p of water (using derivatives) at 101325 Pa and 300 K: 4180.63577656 J/kg/K
*********** HUMID AIR PROPERTIES *****************
Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa: 0.0110955297052 kg_w/kg_da
Relative humidity from last calculation: 0.5 (fractional)
*********** INCOMPRESSIBLE FLUID AND BRINES *****************
Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa: 1061.17930772 kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 Pa: 0.000522883799096 Pa-s
*********** REFPROP *****************
REFPROP version: 9.1.1.10
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.124295848 K
c_p of water at 101325 Pa and 300 K: 4180.63577658 J/kg/K
*********** TABULAR BACKENDS *****************
Mass density of refrigerant R245fa at 300 K, 101325 Pa: 5.64812825705 kg/m^3
*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************
First saturation derivative: 4058.51975505 Pa/K
*********** LOW-LEVEL INTERFACE *****************
Normal boiling point temperature of water and ethanol: 357.272980172 K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
Vapor molar density: 0.441465625159 mol/m^3