Simple, full-featured, lightweight CoolProp wrapper for Python.
Run the following command:
pip install pyfluids
Fluid
class - an implementation of pure fluids and binary mixtures.Mixture
class - an implementation of mixtures with pure fluids components.FluidsList
enum - the list of all available fluids.Input
class - the inputs for the Fluid
and Mixture
classes.HumidAir
class - an implementation of real humid air.InputHumidAir
class - the inputs for the HumidAir
class.Using a configuration file, you can choose the units system
that will be used in your project (for both inputs and outputs of PyFluids
).
UnitsSystem.SI
):
UnitsSystem.SIWithCelsius
):
UnitsSystem.SIWithCelsiusAndPercents
) - by default:
pyfluids.ini
;pyfluids.json
;pyproject.toml
;tox.ini
.pyfluids.ini
example[pyfluids]
units_system = SI
pyfluids.json
example{
"pyfluids": {
"units_system": "SIWithCelsius"
}
}
pyproject.toml
example[tool.pyfluids]
units_system = "SIWithCelsiusAndPercents"
tox.ini
example[pyfluids]
units_system = SI
If the required property is not present in the instance of the fluid, then you can add it by extending
the Fluid
, Mixture
or HumidAir
classes (see how to add other properties).
Fluid
and Mixture
instancescompressibility
- compressibility factor (dimensionless).conductivity
- thermal conductivity (W/m/K).critical_pressure
- absolute pressure at the critical point (Pa).critical_temperature
- temperature at the critical point (by default, °C; see how to change it).density
- mass density (kg/m3).dynamic_viscosity
- dynamic viscosity (Pa*s).enthalpy
- mass specific enthalpy (J/kg).entropy
- mass specific entropy (J/kg/K).freezing_temperature
- temperature at the freezing point (for incompressible fluids) (by default, °C; see how to change it).internal_energy
- mass specific internal energy (J/kg).kinematic_viscosity
- kinematic viscosity (m2/s).max_pressure
- maximum pressure limit (Pa).max_temperature
- maximum temperature limit (by default, °C; see how to change it).min_pressure
- minimum pressure limit (Pa).min_temperature
- minimum temperature limit (by default, °C; see how to change it).molar_mass
- molar mass (kg/mol).phase
- phase state (enum).prandtl
- Prandtl number (dimensionless).pressure
- absolute pressure (Pa).quality
- mass vapor quality (by default, %; see how to change it).sound_speed
- sound speed (m/s).specific_heat
- mass specific constant pressure specific heat (J/kg/K).specific_volume
- mass specific volume (m3/kg).surface_tension
- surface tension (N/m).temperature
- temperature (by default, °C; see how to change it).triple_pressure
- absolute pressure at the triple point (Pa).triple_temperature
- temperature at the triple point (by default, °C; see how to change it).units_system
- configured units system (enum).HumidAir
instancescompressibility
- compressibility factor (dimensionless).conductivity
- thermal conductivity (W/m/K).density
- mass density per humid air unit (kg/m3).dew_temperature
- dew-point temperature (by default, °C; see how to change it).dynamic_viscosity
- dynamic viscosity (Pa*s).enthalpy
- mass specific enthalpy per humid air (J/kg).entropy
- mass specific entropy per humid air (J/kg/K).humidity
- absolute humidity ratio (kg/kg d.a.).kinematic_viscosity
- kinematic viscosity (m2/s).partial_pressure
- partial pressure of water vapor (Pa).prandtl
- Prandtl number (dimensionless).pressure
- absolute pressure (Pa).relative_humidity
- relative humidity ratio (by default, %; see how to change it).specific_heat
- mass specific constant pressure specific heat per humid air (J/kg/K).specific_volume
- mass specific volume per humid air unit (m3/kg).temperature
- dry-bulb temperature (by default, °C; see how to change it).wet_bulb_temperature
- wet-bulb temperature (by default, °C; see how to change it).units_system
- configured units system (enum).For more information, see the docstrings.
Fluid
instancesfactory
- returns a new fluid instance with no defined state.with_state
- returns a new fluid instance with a defined state.update
- updates the state of the fluid.reset
- resets all non-trivial properties.specify_phase
- specify the phase state for all further calculations.unspecify_phase
- unspecify the phase state and go back to calculating it based on the inputs.clone
- performs deep (full) copy of the fluid instance.isentropic_compression_to_pressure
- the process of isentropic compression to given pressure.compression_to_pressure
- the process of compression to given pressure.isenthalpic_expansion_to_pressure
- the process of isenthalpic expansion to given pressure.isentropic_expansion_to_pressure
- the process of isentropic expansion to given pressure.expansion_to_pressure
- the process of expansion to given pressure.cooling_to_temperature
- the process of cooling to given temperature.cooling_to_enthalpy
- the process of cooling to given enthalpy.heating_to_temperature
- the process of heating to given temperature.heating_to_enthalpy
- the process of heating to given enthalpy.bubble_point_at_pressure
- bubble point at given pressure.bubble_point_at_temperature
- bubble point at given temperature.dew_point_at_pressure
- dew point at given pressure.dew_point_at_temperature
- dew point at given temperature.two_phase_point_at_pressure
- two-phase point at given pressure.mixing
- the mixing process.as_json
- converts the fluid instance to a JSON string.as_dict
- converts the fluid instance to a dict.Mixture
instancesfactory
- returns a new mixture instance with no defined state.with_state
- returns a new mixture instance with a defined state.update
- updates the state of the mixture.reset
- resets all non-trivial properties.specify_phase
- specify the phase state for all further calculations.unspecify_phase
- unspecify the phase state and go back to calculating it based on the inputs.clone
- performs deep (full) copy of the mixture instance.cooling_to_temperature
- the process of cooling to given temperature.heating_to_temperature
- the process of heating to given temperature.as_json
- converts the mixture instance to a JSON string.as_dict
- converts the mixture instance to a dict.HumidAir
instancesfactory
- returns a new humid air instance with no defined state.with_state
- returns a new humid air instance with a defined state.update
- updates the state of the humid air.reset
- resets all properties.clone
- performs deep (full) copy of the humid air instance.dry_cooling_to_temperature
- the process of cooling without dehumidification to given temperature.dry_cooling_to_enthalpy
- the process of cooling without dehumidification to given enthalpy.wet_cooling_to_temperature_and_relative_humidity
- the process of cooling with dehumidification to given temperature and relative humidity ratio.wet_cooling_to_temperature_and_absolute_humidity
- the process of cooling with dehumidification to given temperature and absolute humidity ratio.wet_cooling_to_enthalpy_and_relative_humidity
- the process of cooling with dehumidification to given enthalpy and relative humidity ratio.wet_cooling_to_enthalpy_and_absolute_humidity
- the process of cooling with dehumidification to given enthalpy and absolute humidity ratio.heating_to_temperature
- the process of heating to given temperature.heating_to_enthalpy
- the process of heating to given enthalpy.humidification_by_water_to_relative_humidity
- the process of humidification by water (isenthalpic) to given relative humidity ratio.humidification_by_water_to_absolute_humidity
- the process of humidification by water (isenthalpic) to given absolute humidity ratio.humidification_by_steam_to_relative_humidity
- the process of humidification by steam (isothermal) to given relative humidity ratio.humidification_by_steam_to_absolute_humidity
- the process of humidification by steam (isothermal) to given absolute humidity ratio.mixing
- the mixing process.as_json
- converts the humid air instance to a JSON string.as_dict
- converts the humid air instance to a dict.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 300 m above sea level, 30 °C and 50 % relative humidity:
from pyfluids import HumidAir, InputHumidAir
humid_air = HumidAir().with_state(
InputHumidAir.altitude(300),
InputHumidAir.temperature(30),
InputHumidAir.relative_humidity(50),
)
print(humid_air.wet_bulb_temperature) # 21.917569033181564
You can simply determine the equality of Fluid
, Mixture
and HumidAir
instances by its state.
Just use the equality operators (==
or !=
).
Exactly the same way you can compare inputs (Input
and InputHumidAir
).
For example:
from pyfluids import HumidAir, InputHumidAir
humid_air = HumidAir().with_state(
InputHumidAir.altitude(0),
InputHumidAir.temperature(20),
InputHumidAir.relative_humidity(50),
)
same_humid_air = HumidAir().with_state(
InputHumidAir.pressure(101325),
InputHumidAir.temperature(20),
InputHumidAir.relative_humidity(50),
)
print(humid_air == same_humid_air) # True
print(InputHumidAir.altitude(0) == InputHumidAir.pressure(101325)) # True
The Fluid
, Mixture
and HumidAir
classes have a method as_json
,
which performs converting of instance to a JSON string.
For example, converting a Fluid
instance to an indented JSON string:
from pyfluids import Fluid, FluidsList
refrigerant = Fluid(FluidsList.R32).dew_point_at_temperature(5)
print(refrigerant.as_json())
As a result:
{
"compressibility": 0.8266625877210833,
"conductivity": 0.013435453854396475,
"critical_pressure": 5782000.0,
"critical_temperature": 78.10500000000002,
"density": 25.89088151061046,
"dynamic_viscosity": 1.2606543144761657e-05,
"enthalpy": 516105.7800378023,
"entropy": 2136.2654412978777,
"fraction": 100,
"freezing_temperature": null,
"internal_energy": 479357.39743435377,
"kinematic_viscosity": 4.869105418289953e-07,
"max_pressure": 70000000.0,
"max_temperature": 161.85000000000002,
"min_pressure": 47.999893876059375,
"min_temperature": -136.80999999999997,
"molar_mass": 0.052024,
"name": "R32",
"phase": "TwoPhase",
"prandtl": 1.2252282243443504,
"pressure": 951448.019691762,
"quality": 100.0,
"sound_speed": 209.6337575990297,
"specific_heat": 1305.7899441785378,
"specific_volume": 0.03862363664945844,
"surface_tension": 0.010110117241546162,
"temperature": 5.0,
"triple_pressure": 47.999893876059375,
"triple_temperature": -136.80999999999997,
"units_system": "SIWithCelsiusAndPercents"
}
The Fluid
, Mixture
and HumidAir
classes have a method as_dict
,
which performs converting of instance to a Python dict.
For example:
from pyfluids import Fluid, FluidsList
refrigerant = Fluid(FluidsList.R32).dew_point_at_temperature(5)
print(refrigerant.as_dict()) # {'compressibility': 0.8266625877210833, 'conductivity': ...
The Fluid
, Mixture
and HumidAir
classes have a method clone
,
which performs deep (full) copy of instance:
from pyfluids import Fluid, FluidsList, Input
origin = Fluid(FluidsList.Water).with_state(
Input.pressure(101325), Input.temperature(20)
)
clone = origin.clone()
print(origin == clone) # True
clone.update(Input.pressure(101325), Input.temperature(30))
print(origin == clone) # False