Skip to main content

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) -> FormulaSummary
  • to_molecular_formula(input: str) -> FormulaSummary
  • to_wt_percent(input: str) -> FormulaSummary
  • molecular_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.

Release files for chemical-formula-rs 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chemical-formula-rs 0.1.3
File Size Uploaded
chemical_formula_rs-0.1.3.tar.gz 40.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for chemical-formula-rs 0.1.3
File Interpreter ABI Platform
chemical_formula_rs-0.1.3-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
chemical_formula_rs-0.1.3-cp39-abi3-manylinux_2_34_x86_64.whl CPython 3.9 abi3 Linux glibc 2.34+ x86-64 Details
chemical_formula_rs-0.1.3-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details

Total release size: 1.9 MB

Release files / chemical_formula_rs-0.1.3.tar.gz

Download URL chemical_formula_rs-0.1.3.tar.gz
Size 40.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3759c5fbf9a6bd1d9b9532a648a8f9a496bdd7ab1ea54270a954a39c0e2d4420
BLAKE2b-256 checksum
How to use checksums
079835b1d643d8f11ca39438c5885e4ac2da33310957387c98fab21126dff0bd
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / chemical_formula_rs-0.1.3-cp39-abi3-win_amd64.whl

Download URL chemical_formula_rs-0.1.3-cp39-abi3-win_amd64.whl
Size 207.9 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8f3143bdd3242fafffa97bbb0fdaf834c8e98f15b24fb165fbd45b95eb11db32
BLAKE2b-256 checksum
How to use checksums
1941623e969c5172f02b399f2e353b55b2f0e88036241fa375a5a22439b29fae
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / chemical_formula_rs-0.1.3-cp39-abi3-manylinux_2_34_x86_64.whl

Download URL chemical_formula_rs-0.1.3-cp39-abi3-manylinux_2_34_x86_64.whl
Size 1.3 MB
Tags CPython 3.9 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
a037448b10d99d1e1716601779ecfad1883b0b0cbc2c312909d75560e0a8b19d
BLAKE2b-256 checksum
How to use checksums
0007278b6d2e7702cd61269232fc5983f0166feba73eb1070b4d716ce65803e0
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / chemical_formula_rs-0.1.3-cp39-abi3-macosx_11_0_arm64.whl

Download URL chemical_formula_rs-0.1.3-cp39-abi3-macosx_11_0_arm64.whl
Size 313.8 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
c48e1f140a0c512689cc482fdff105c82bd8a0cb14b42cad79948ced9e857a92
BLAKE2b-256 checksum
How to use checksums
21c6dec5d74c13d72bd50afae0a1a8ec0fdf7b9ee9acb7c8e97efbc21de9d67c
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.3 This release

4 release files

0.1.2

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page