A Python package for parsing and working with chemical formulas
Project description
chemformulapy
A lightweight Python package for parsing, analyzing, and working with chemical formulas.
chemformulapy provides tools to:
- Parse chemical formulas into structured representations
- Compute molar masses
- Work with chemical elements and their properties
- Generate chemically intuitive formula orderings
🚀 Features
- 🧪 Parse formulas like
H2O,C6H12O6,KNO3,H2SO4 - ⚖️ Calculate molar masses using built-in element data
- 🔬 Access element properties (atomic number, molar mass, electronegativity)
- 📐 Chemically intuitive ordering of elements
- 🧩 Extensible design using enums and descriptors
📦 Installation
pip install chemformulapy
⚡ Quick Start
from chemformulapy import Element
oxygen = Element.O
print(oxygen.name)
print(oxygen.mass())
🧠 Use Cases
Molar Mass Calculation
from chemformulapy import parse_formula
formula = "H2O"
mass = parse_formula(formula).mass()
print(mass)
Chemical Formula Parsing
compound = parse_formula("C6H12O6")
print(compound.elements)
Element Property Analysis
from chemformulapy import Element
carbon = Element.C
print(carbon.value)
📥 Example Scripts
molar_mass_calculator.py
from chemformulapy import parse_formula
formula = input("Enter chemical formula: ")
compound = parse_formula(formula)
print(f"Molar mass of {formula}: {compound.mass()} g/mol")
element_lookup.py
from chemformulapy import Element
symbol = input("Enter element symbol: ")
element = Element[symbol]
print(f"Atomic number: {element.number}")
print(f"Molar mass: {element.mass}")
print(f"Electronegativity: {element.eneg}")
formula_parser_demo.py
from chemformulapy import parse_formula
formula = "H2SO4"
compound = parse_formula(formula)
print("Parsed formula:", compound.elements)
🧩 API Overview
Element Enum
Represents chemical elements with:
- Atomic number
- Molar mass
- Electronegativity
🛠️ Dependencies
- numpy
- pyparsing
🤝 Contributing
Contributions are welcome!
📄 License
MIT License
👤 Author
Evgenii Nekhoroshev, contact at evgnekhoroshev@gmail.com
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 Distribution
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 chemformulapy-1.0.0.tar.gz.
File metadata
- Download URL: chemformulapy-1.0.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.7 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f45a4e16164dfb872512198ec8f9371ae803d501e662026ccb4349e4b972e3db
|
|
| MD5 |
60f198bcee1b7b5d91798b0ad5c0f9a7
|
|
| BLAKE2b-256 |
6d5217697819eddb8e700d3fc95ea91ac2280f69fcec51765fdaee188734b624
|
File details
Details for the file chemformulapy-1.0.0-py3-none-any.whl.
File metadata
- Download URL: chemformulapy-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.7 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d088f8609e9bffde300b2831ff899ea455c22413c4ddb8ff60c4398917a8d14d
|
|
| MD5 |
82061c7c9577704c454eba3772da64c1
|
|
| BLAKE2b-256 |
d78a9c4fb9717fda0103f0dcf3a5556e57624fc011f8f680e365cacf408b88a3
|