💨 Ideal Gas Module
A modern, type-safe Python library for calculating and solving the Ideal Gas Law ($PV = nRT$ and its variations), designed to be intuitive, robust, and high school-friendly.
🐍 Requirements
- Pure Python
>= 3.10 - Zero external runtime dependencies
📦 Installation
pip install ideal-gas
✨ Features
1. Automatic Unit Conversion
Wrap your values in dedicated type-safe unit classes, and the library handles all conversions automatically:
| Physical Quantity | Supported Units | Internal Standard Unit |
|---|---|---|
| Pressure ($P$) | atm, Torr, mmHg |
$\text{atm}$ |
| Volume ($V$) | L, dm3, ml, cm3 |
$\text{L}$ |
| Amount ($n$) | mol |
$\text{mol}$ |
| Temperature ($T$) | K, C ($^\circ\text{C}$) |
$\text{K}$ |
| Mass ($g$) | g, kg |
$\text{g}$ |
| Molar Mass ($M$) | g/mol |
$\text{g/mol}$ |
| Density ($d$) | g/L, g/dm3 |
$\text{g/L}$ |
| Molarity ($M_{\text{olarity}}$) | mol/L, mol/dm3 |
$\text{mol/L}$ |
2. Dual Modes (Default Scientific & School Mode)
Easily switch between scientific precision and standard high school curriculum constants:
| Parameter | Default Scientific Mode | School Mode (school_mode=True) |
|---|---|---|
| Gas Constant ($R$) | 0.082057 $\text{L}\cdot\text{atm}/(\text{mol}\cdot\text{K})$ |
0.0821 $\text{L}\cdot\text{atm}/(\text{mol}\cdot\text{K})$ |
| $0^\circ\text{C}$ to Kelvin Offset | + 273.15 |
+ 273 |
3. Supported Gas Law Formulas
- $PV = nRT$ via
PVnRT - $PV = \frac{g}{M}RT$ via
PVgMRT - $PM = dRT$ via
PMdRT(also aliased asPVdRT) - $P = MRT$ via
PMRT
🚀 Quick Start & Examples
1. $PV = nRT$
Calculate the missing variable by omitting it from the constructor and accessing calculate_<variable>:
from ideal_gas import PVnRT, Volume, Mole, Temperature
# Calculate Pressure (atm)
gas = PVnRT(
volume=Volume(volume=7600, unit="ml"),
mole=Mole(mole=8, unit="mol"),
temperature=Temperature(temperature=27, unit="C"),
)
print(gas.calculate_pressure) # Pressure in atm ~ 25.92569
from ideal_gas import PVnRT, Pressure, Mole, Temperature
# Calculate Volume (L)
gas = PVnRT(
pressure=Pressure(pressure=1520, unit="mmHg"),
mole=Mole(mole=7, unit="mol"),
temperature=Temperature(temperature=298, unit="K"),
)
print(gas.calculate_volume) # Volume in L ~ 85.54442
2. $PV = \frac{g}{M}RT$
from ideal_gas import PVgMRT, Volume, Gram, MolarMass, Temperature
# Calculate Pressure (atm)
gas = PVgMRT(
volume=Volume(volume=3, unit="L"),
gram=Gram(gram=4, unit="kg"),
molar_mass=MolarMass(molar_mass=8, unit="g/mol"),
temperature=Temperature(temperature=45, unit="C"),
)
print(gas.calculate_pressure) # Pressure in atm
from ideal_gas import PVgMRT, Pressure, Volume, Gram, Temperature
# Calculate Molar Mass (g/mol)
gas = PVgMRT(
pressure=Pressure(pressure=1520, unit="Torr"),
volume=Volume(volume=20, unit="ml"),
gram=Gram(gram=6, unit="kg"),
temperature=Temperature(temperature=25, unit="C"),
)
print(gas.calculate_molar_mass) # Molar Mass in g/mol
3. $PM = dRT$
from ideal_gas import PMdRT, Density, MolarMass, Temperature
# Calculate Pressure (atm) from density and molar mass
gas = PMdRT(
density=Density(density=1.429, unit="g/L"),
molar_mass=MolarMass(molar_mass=32, unit="g/mol"),
temperature=Temperature(temperature=0, unit="C"),
)
print(gas.calculate_pressure) # Pressure in atm
from ideal_gas import PMdRT, Pressure, MolarMass, Temperature
# Calculate Gas Density (g/L)
gas = PMdRT(
pressure=Pressure(pressure=2, unit="atm"),
molar_mass=MolarMass(molar_mass=44, unit="g/mol"),
temperature=Temperature(temperature=27, unit="C"),
)
print(gas.calculate_density) # Density in g/L
4. $P = MRT$ (where $M$ = Molarity)
from ideal_gas import PMRT, Molarity, Temperature
# Calculate Pressure (atm)
gas = PMRT(
molarity=Molarity(molarity=8, unit="mol/L"),
temperature=Temperature(temperature=277, unit="K"),
)
print(gas.calculate_pressure) # Pressure in atm
5. Using School Mode
from ideal_gas import PVnRT, Volume, Mole, Temperature, GasConstant
gas = PVnRT(
volume=Volume(volume=7600, unit="ml"),
mole=Mole(mole=8, unit="mol"),
# Set school_mode=True on Temperature (Kelvin offset = 273)
temperature=Temperature(temperature=27, unit="C", school_mode=True),
# Set school_mode=True on GasConstant (R = 0.0821)
gas_constant=GasConstant(school_mode=True),
)
print(gas.calculate_pressure) # Output: 25.926315789473686
🛠️ Development & Testing
Run all unit tests with pytest:
pip install pytest
pytest
Build the distribution package:
pip install --upgrade build
python -m build
📄 License
This project is licensed under the MIT License.
Metadata
Release files for ideal-gas 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ideal_gas-0.1.1.tar.gz | 11.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ideal_gas-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.4 kB
Release files / ideal_gas-0.1.1.tar.gz
| Download URL | ideal_gas-0.1.1.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1abb56f207ef2a654e69563dcba117abc633c6432dfbc2a741a560397a20d5df
|
|
BLAKE2b-256 checksum How to use checksums |
b464363d3696181c9f62ac82cb2631cb0ff48482b558488168bcaaa1046e1916
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / ideal_gas-0.1.1-py3-none-any.whl
| Download URL | ideal_gas-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b36bc93e4d9657c25525618b6e2d29f46dd49eb2783009891cb80f08d309a77b
|
|
BLAKE2b-256 checksum How to use checksums |
491f1976e3f1401f40e5c9e6961d1adcebe636d27bc4dfa81f99544d07edb466
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|