Python bindings for chemical-formula
Project description
chemical-formula-rs
Python bindings for the Rust chemical-formula parser.
Use this package to parse chemical formulas, convert between molecular and
weight-percent representations, and calculate molecular weights. It supports
ordinary formulas such as H2O, weight-percent annotations such as
Pt5wt%/SiO2, and flexible catalyst loading notation such as 1%Pt/SiO2,
Pt1%/SiO2, and 1wt%Pt@SiO2.
Installation
pip install chemical-formula-rs
With uv:
uv add chemical-formula-rs
Quick Start
import chemical_formula_rs as cf
catalyst = cf.parse_formula("1%Pt/SiO2")
print(catalyst)
# {
# "formula": "Pt1wt%O2Si",
# "elements": ["O", "Si", "Pt"],
# "stoichiometry": {"O": 2.0, "Si": 1.0},
# "wt_percent": {"Pt": 1.0},
# }
molecular = cf.to_molecular_formula("1%Pt/SiO2")
print(molecular["stoichiometry"]["Pt"])
# 0.0031109624054201776
water = cf.to_wt_percent("H2O")
print(water["wt_percent"])
# {"H": 11.19067443796836, "O": 88.80932556203165}
print(cf.molecular_weight("H2O"))
# 18.015
API
FormulaSummary is returned as a dictionary:
{
"formula": str,
"elements": list[str],
"stoichiometry": dict[str, float],
"wt_percent": dict[str, float],
}
parse_formula(input: str) -> FormulaSummaryto_molecular_formula(input: str) -> FormulaSummaryto_wt_percent(input: str) -> FormulaSummarymolecular_weight(input: str) -> float
Parsing and conversion errors raise ValueError.
Supported Notation Examples
These examples all describe 1 wt% Pt on silica:
cf.parse_formula("1%Pt/SiO2")
cf.parse_formula("Pt1%/SiO2")
cf.parse_formula("1wt%Pt/SiO2")
cf.parse_formula("Pt1wt%/SiO2")
cf.parse_formula("1wt%Pt@SiO2")
cf.parse_formula("1 wt % Pt / SiO2")
Bare % is interpreted as wt%.
Nested materials are supported:
composite = cf.to_wt_percent("(Pt5wt%/SiO2)50wt%(CeO2)50wt%")
print(composite["wt_percent"]["Pt"])
# 2.5000000000000004
Package Notes
The Python extension is built with PyO3 and ships the shared Rust parser as a
native module imported through chemical_formula_rs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chemical_formula_rs-0.1.3.tar.gz.
File metadata
- Download URL: chemical_formula_rs-0.1.3.tar.gz
- Upload date:
- Size: 40.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3759c5fbf9a6bd1d9b9532a648a8f9a496bdd7ab1ea54270a954a39c0e2d4420
|
|
| MD5 |
6456546a28416a605621b3b38a4b1cc9
|
|
| BLAKE2b-256 |
079835b1d643d8f11ca39438c5885e4ac2da33310957387c98fab21126dff0bd
|
File details
Details for the file chemical_formula_rs-0.1.3-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: chemical_formula_rs-0.1.3-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 207.9 kB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f3143bdd3242fafffa97bbb0fdaf834c8e98f15b24fb165fbd45b95eb11db32
|
|
| MD5 |
33e6180675c0d8f5c351dc09d8404856
|
|
| BLAKE2b-256 |
1941623e969c5172f02b399f2e353b55b2f0e88036241fa375a5a22439b29fae
|
File details
Details for the file chemical_formula_rs-0.1.3-cp39-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: chemical_formula_rs-0.1.3-cp39-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a037448b10d99d1e1716601779ecfad1883b0b0cbc2c312909d75560e0a8b19d
|
|
| MD5 |
2f01768febde225b7cce54f78d94b503
|
|
| BLAKE2b-256 |
0007278b6d2e7702cd61269232fc5983f0166feba73eb1070b4d716ce65803e0
|
File details
Details for the file chemical_formula_rs-0.1.3-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: chemical_formula_rs-0.1.3-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 313.8 kB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c48e1f140a0c512689cc482fdff105c82bd8a0cb14b42cad79948ced9e857a92
|
|
| MD5 |
43e4f97f29c162ac2a0bf4d4360020e6
|
|
| BLAKE2b-256 |
21c6dec5d74c13d72bd50afae0a1a8ec0fdf7b9ee9acb7c8e97efbc21de9d67c
|