A Python package for balancing chemical equations and finding possible reactions
Project description
balance-rxns
A Python package for balancing chemical equations and finding possible reactions.
Installation
pip install balance-rxns
Features
- Automatically balance chemical equations
- Find all possible reactions from given reactants and products
- Support for complex chemical formulas
- Accurate calculations based on sympy and pymatgen
Usage
Basic Usage
from balance_rxns import balance_rxns
# Define reactants and products
reactants = ("Fe", "O2")
products = ("FeO", "Fe2O3", "Fe3O4")
# Find all possible balanced equations
results = balance_rxns(reactants, products)
# Print results
for equation, reactant_coeffs, product_coeffs in results:
print(equation)
Output:
2Fe + O2 -> 2FeO
4Fe + 3O2 -> 2Fe2O3
3Fe + 2O2 -> Fe3O4
Advanced Options
# Limit the number of products
results = balance_rxns(
reactants=["Cu", "Al2O3"],
products=["CuAlO2"],
max_products_in_equation=2, # Maximum 2 products per equation
require_all_reactants_used=True # Require all reactants to be used
)
for equation, r_map, p_map in results:
print(f"Equation: {equation}")
print(f"Reactant coefficients: {r_map}")
print(f"Product coefficients: {p_map}")
print()
Parameters
reactants: List or tuple of reactant chemical formulasproducts: List or tuple of product chemical formulasmax_products_in_equation: Maximum number of products in each equation (default: all)require_all_reactants_used: Whether all reactants must be used (default: True)
Return Value
Returns a list where each element contains:
- String representation of the balanced equation
- Dictionary of reactants with their coefficients
- Dictionary of products with their coefficients
Dependencies
- pymatgen >= 2024.1.0
- sympy >= 1.12.0
License
MIT License
Contributing
Issues and Pull Requests are welcome!
Changelog
0.1.0 (2026-01-30)
- Initial release
- Support for chemical equation balancing
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
balance_rxns-0.1.0.tar.gz
(53.0 kB
view details)
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 balance_rxns-0.1.0.tar.gz.
File metadata
- Download URL: balance_rxns-0.1.0.tar.gz
- Upload date:
- Size: 53.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d88108db6b66d34d19fa6c51c5d885cad39d1b433d9b903c8f871debac8e1d3
|
|
| MD5 |
50597013d4ba07ffe048d1ac8a9f0d3d
|
|
| BLAKE2b-256 |
314af98bd18941edba232cc93d7405e1bb91578770d38d5ff35ca8c2fc65cbe7
|
File details
Details for the file balance_rxns-0.1.0-py3-none-any.whl.
File metadata
- Download URL: balance_rxns-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48bdf08bd2b2dc75ddaad9e43c89dc0159887c33e73ae5c166725c94c1b7be12
|
|
| MD5 |
fb96007e731099b18f0bea67153fa137
|
|
| BLAKE2b-256 |
9962377459898493168f8081ba6261604e0ca928e2ea1f19697d4c0032c8f38e
|