Skip to main content

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 formulas
  • products: List or tuple of product chemical formulas
  • max_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:

  1. String representation of the balanced equation
  2. Dictionary of reactants with their coefficients
  3. 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

Release files for balance-rxns 0.2.0

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

Source distribution (sdist)

Source distribution for balance-rxns 0.2.0
File Size Uploaded
balance_rxns-0.2.0.tar.gz 53.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for balance-rxns 0.2.0
File Interpreter ABI Platform
balance_rxns-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 59.5 kB

Release files / balance_rxns-0.2.0.tar.gz

Download URL balance_rxns-0.2.0.tar.gz
Size 53.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a9743aeac6c656c798e62bc24d5543a5d3687af8d35b5f84786892a6723897b2
BLAKE2b-256 checksum
How to use checksums
2dd274197b05684c797a368b0e519085a0ab01cbc2c7bf69db001e844cbe611b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.4

Release files / balance_rxns-0.2.0-py3-none-any.whl

Download URL balance_rxns-0.2.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b06031c3c594dfed3763ec6d252a964fd717f8bb9197c43e757bc28e28feb0c
BLAKE2b-256 checksum
How to use checksums
28db1f6d282fbbd0d6f532d87b58afe3111ef544d6a63db52ec09f45c0a73dc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 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