Python Wrapper#

PyFluids (3-party wrapper)#

It is a simple, full-featured, lightweight CoolProp wrapper for Python. PyFluids gets published on PyPI, so you can easily install it using:

pip install pyfluids

All CoolProp features are included: thermophysical properties of pure fluids, mixtures and humid air. Also you can easily convert the results to a JSON string or Python dict, add new properties or inputs for lookups, and more.

Benefits#

  • Easy to use: all fluids and properties are at hand, no need to remember CoolProp keys.

  • Processes for fluids and humid air are included: there is no need to code it anymore.

  • User-friendly interface: writing code is faster.

Examples#

To calculate the specific heat of saturated water vapor at 1 atm:

from pyfluids import Fluid, FluidsList

water_vapour = Fluid(FluidsList.Water).dew_point_at_pressure(101325)
print(water_vapour.specific_heat)  # 2079.937085633241

To calculate the dynamic viscosity of propylene glycol aqueous solution with 60 % mass fraction at 100 kPa and -20 °C:

from pyfluids import Fluid, FluidsList, Input

propylene_glycol = Fluid(FluidsList.MPG, 60).with_state(
    Input.pressure(100e3), Input.temperature(-20)
)
print(propylene_glycol.dynamic_viscosity)  # 0.13907391053938878

To calculate the density of ethanol aqueous solution (with ethanol 40 % mass fraction) at 200 kPa and 4 °C:

from pyfluids import Mixture, FluidsList, Input

mixture = Mixture([FluidsList.Water, FluidsList.Ethanol], [60, 40]).with_state(
    Input.pressure(200e3), Input.temperature(4)
)
print(mixture.density)  # 883.3922771627963

To calculate the wet bulb temperature of humid air at 99 kPa, 30 °C and 50 % relative humidity:

from pyfluids import HumidAir, InputHumidAir

humid_air = HumidAir().with_state(
    InputHumidAir.pressure(99e3),
    InputHumidAir.temperature(30),
    InputHumidAir.relative_humidity(50),
)
print(humid_air.wet_bulb_temperature)  # 21.946578559079228

For any questions or more examples, see PyFluids on GitHub.

Automatic installation#

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

pip install CoolProp

There are also unofficial Conda packages available from the conda-forge channel. To install, use:

conda install conda-forge::coolprop

Using uv (fast Python package manager)#

uv is an extremely fast Python package and project manager written in Rust. To use CoolProp with uv:

# Install CoolProp in the current environment
uv pip install CoolProp

# Or create a new project with CoolProp
uv init my-project
cd my-project
uv add CoolProp

# Run a script with CoolProp (uv will automatically manage the environment)
uv run python my_script.py

For development from source:

# Clone the repository
git clone https://github.com/CoolProp/CoolProp --recursive
cd CoolProp

# Create a virtual environment (recommended)
uv venv

# Install build dependencies
uv pip install --python .venv/bin/python scikit-build-core cython

# Install in editable mode with incremental build support
uv pip install -ve . --python .venv/bin/python --no-build-isolation

Important: The --no-build-isolation flag is required for incremental builds to work properly. Without it, each build will use a temporary isolated environment with different paths, causing CMake to reconfigure and rebuild all files even when only one file changed.

Nightly builds#

If you dare, you can also try the latest nightly release from nightly 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 --no-cache --force-reinstall CoolProp

Manual installation#

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

CoolProp uses a modern build system based on CMake via scikit-build-core. The build dependencies (including Cython and CMake) are automatically installed by pip.

To build and install from source:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp
# Install (pip will automatically handle the build)
pip install .

An editable install (also known as “development mode”) allows you to make changes to the C++ source code and have them take effect after a simple rebuild, without reinstalling the package.

Using pip:

# Install in editable mode
pip install -ve .

Using uv (recommended for faster builds and better dependency management):

# Create a virtual environment
uv venv

# Install build dependencies first (required for --no-build-isolation)
uv pip install --python .venv/bin/python scikit-build-core cython

# Install in editable mode with incremental build support
uv pip install -ve . --python .venv/bin/python --no-build-isolation

When you modify C++ source files, trigger an incremental rebuild:

# With pip (incremental builds work automatically)
pip install -ve .

# With uv (must use --no-build-isolation for incremental builds)
uv pip install -ve . --python .venv/bin/python --no-build-isolation

The build system (scikit-build-core with CMake/Ninja) will automatically detect which files have changed and only recompile those files, making the rebuild much faster than a full rebuild.

Incremental Build Performance:

  • Without --no-build-isolation: Each build uses a fresh isolated environment, causing CMake to reconfigure and rebuild all ~60 source files (~50 seconds)

  • With --no-build-isolation: CMake reuses the existing build directory and only rebuilds changed files (~4 seconds for a single file change)

Note: If you use --no-build-isolation, you must manually install the build dependencies (scikit-build-core and cython) in your virtual environment first.

Local installation#

If you prefer not to install system-wide, you can install locally using the --user flag:

# Check out the sources for CoolProp
git clone https://github.com/CoolProp/CoolProp --recursive
# Move into the folder you just created
cd CoolProp
# Install locally
pip install --user .

For specific Python versions#

If you have multiple Python versions installed, use the specific Python’s pip:

# For Python 3.11 specifically
python3.11 -m pip install .

Building with specific compilers#

You can control CMake options via environment variables:

# Example: Specify a different C++ compiler
export CXX=/usr/bin/g++-11
pip 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 your 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: 7.1.1dev
CoolProp gitrevision: 471bf493bedff3f4a50e4efa2a0a6bee54e7c154
CoolProp Fluids: Isopentane,Neon,Fluorine,R11,R125,cis-2-Butene,R13I1,trans-2-Butene,Ethylene,Acetone,MethylPalmitate,DimethylEther,R152A,Hydrogen,ParaHydrogen,R22,CycloHexane,R1233zd(E),Isohexane,R236EA,CarbonMonoxide,R12,SES36,MD3M,Dichloroethane,Argon,R115,m-Xylene,n-Nonane,R13,R14,R114,n-Propane,n-Dodecane,n-Decane,MethylStearate,R410A,R236FA,n-Undecane,Xenon,R113,n-Butane,HeavyWater,Toluene,RC318,EthyleneOxide,Helium,n-Heptane,R1243zf,Ammonia,CycloPropane,MD4M,Water,R218,D6,R142b,MDM,CarbonylSulfide,HFE143m,MethylOleate,ParaDeuterium,Ethanol,R134a,Oxygen,HydrogenSulfide,o-Xylene,Nitrogen,HydrogenChloride,R1234yf,CarbonDioxide,DimethylCarbonate,R1234ze(E),R507A,MethylLinolenate,Propylene,R41,OrthoHydrogen,Novec649,R404A,Methanol,Krypton,D5,R407C,D4,R245ca,R32,R161,MD2M,R21,NitrousOxide,n-Hexane,R123,OrthoDeuterium,Methane,n-Octane,Cyclopentane,SulfurDioxide,R143a,1-Butene,R116,IsoButane,R23,MethylLinoleate,R365MFC,Benzene,Deuterium,R227EA,IsoButene,DiethylEther,R245fa,R1336mzz(E),R1234ze(Z),n-Pentane,Propyne,Ethane,R124,Air,Neopentane,R141b,EthylBenzene,MM,p-Xylene,SulfurHexafluoride,R40
*********** HIGH LEVEL INTERFACE *****************
Critical temperature of water: 647.0959999999873 K
Boiling temperature of water at 101325 Pa: 373.1242958476665 K
Phase of water at 101325 Pa and 300 K: liquid
c_p of water at 101325 Pa and 300 K: 4180.6357765560715 J/kg/K
c_p of water (using derivatives) at 101325 Pa and 300 K: 4180.6357765560715 J/kg/K
*********** HUMID AIR PROPERTIES *****************
Humidity ratio of 50% rel. hum. air at 300 K, 101325 Pa: 0.01109552970536823 kg_w/kg_da
Relative humidity from last calculation: 0.4999999999999999 (fractional)
*********** INCOMPRESSIBLE FLUID AND BRINES *****************
Density of 50% (mass) ethylene glycol/water at 300 K, 101325 Pa: 1061.1793077204613 kg/m^3
Viscosity of Therminol D12 at 350 K, 101325 Pa: 0.0005228837990955358 Pa-s
*********** REFPROP *****************
REFPROP version: 10.0
Critical temperature of water: 647.096 K
Boiling temperature of water at 101325 Pa: 373.124295847701 K
c_p of water at 101325 Pa and 300 K: 4180.635776575593 J/kg/K
*********** TABULAR BACKENDS *****************
Mass density of refrigerant R245fa at 300 K, 101325 Pa: 5.648128257046375 kg/m^3
*********** SATURATION DERIVATIVES (LOW-LEVEL INTERFACE) ***************
First saturation derivative: 4058.5197550500957 Pa/K
*********** LOW-LEVEL INTERFACE *****************
Normal boiling point temperature of water and ethanol: 357.27297152718097 K
*********** LOW-LEVEL INTERFACE (REFPROP) *****************
Vapor molar density: 0.44146562665387795 mol/m^3

Code Warnings#

Messages may be issued from the Python CoolProp wrapper via the Python warnings module. This module allows non-fatal warning messages to be issued to the calling program and stdout to warn of improper function usage or deprecation of features. These warnings will, by default, be issued each and every time a suspect call is made to CoolProp. While, the best solution is to correct the calling code according to the message received, sometimes this is difficult to do in a legacy or third party code and can result in many, many warning messages that obscure the output and hinder debugging.

Suppressing warning messages#

The calling code can suppress or ignore these warning messages by overriding the default warnings filter and changing the behavior of the warnings module. As an example, the following script will result in a DeprecationWarning on each call to the deprecated function Props():

from CoolProp.CoolProp import Props
Rho = Props('D','T',298.15,'P',10000,'R744')
print("R744 Density at {} K and {} kPa      = {} kg/m³".format(298.15, 10000, Rho))
H = Props('H','T',298.15,'Q',1,'R134a');
print("R134a Saturated Liquid Enthalpy at {} K = {} kJ/kg".format(298.15, H))

Example output:

TestProps.py:14: DeprecationWarning: Props() function is deprecated; Use the PropsSI() function
Rho = Props('D','T',298.15,'P',10000,'R744')
R744 Density at 298.15 K and 10000 kPa      = 817.6273812375758 kg/m³
TestProps.py:16: DeprecationWarning: Props() function is deprecated; Use the PropsSI() function
H = Props('H','T',298.15,'Q',1,'R134a');
R134a Saturated Liquid Enthalpy at 298.15 K = 412.33395323186807 kJ/kg

Legacy applications can create a filter override to ignore all deprecation warnings by including the following code just after the last import from CoolProp, but before any calls to CoolProp:

import warnings
warnings.filterwarnings('ignore', category=DeprecationWarning)

To suppress, for example, only deprecation warning messages that contain the string “Props()”, the second parameter to filterwarnings() can be a pattern matching regular expression:

import warnings
warnings.filterwarnings('ignore', '.*Props()*.', category=DeprecationWarning)

This filter will suppress any DeprecationWarning messages that contain the string “Props()” but will allow all other warning messages to be displayed. The first parameter, ignore, can also be set to once, which will result in a given message to be issued only once and then ignored on further instances.

See Python >>> Module Warnings for more information on using filterwarnings()

Module Documentation#