Skip to main content

ctb

化学工具箱核心库:化学方程式配平。

安装

pip install ctb

用法

from ctb import balance

# 普通方程式
balance("H2+O2=H2O")                 # '2H2+O2=2H2O'
balance("Fe2O3+CO=Fe+CO2")           # 'Fe2O3+3CO=2Fe+3CO2'

# 支持箭头
balance("H2+O2->H2O")                # '2H2+O2=2H2O'

# 离子方程式:^数字+ 表示正电荷,^数字- 表示负电荷
balance("H^1++OH^1-=H2O")            # 'H^1++OH^1-=H2O'
balance("CO3^2-+H^1+=HCO3^1-")       # 'CO3^2-+H^1+=HCO3^1-'

输入格式约定

符号 含义
= 或 -> 或 → 反应箭头
+ 分隔化合物
^n+ 带 n 个正电荷(如 H^1+、Fe^3+)
^n- 带 n 个负电荷(如 CO3^2-、SO4^2-)
括号 支持 () 与 [],可嵌套

返回

返回配平后的方程式字符串(不含空格)。

错误

格式错误或无法配平时抛出 ValueError。

许可证

MIT License Copyright (c) 2026 123IOPjklbnm Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for ctb 0.1.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 ctb 0.1.0
File Size Uploaded
ctb-0.1.0.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ctb 0.1.0
File Interpreter ABI Platform
ctb-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / ctb-0.1.0.tar.gz

Download URL ctb-0.1.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6af34e578f138437bce7acf6196d1b657075e2a3c5bd4bc423760eff8df536ea
BLAKE2b-256 checksum
How to use checksums
4e3a3fb5fdde5a83fed7bf9bf56ca8bdb034905c511ade214231da0087c3be78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / ctb-0.1.0-py3-none-any.whl

Download URL ctb-0.1.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28a0e0562d3a0f8580c225b1a7805a0847dff0a65c0d39fb759c57304b0d7a62
BLAKE2b-256 checksum
How to use checksums
221d1b5b63a74549d23691726e827a8d08b1314287b0fb51a8d64a63b6239104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.0 This release

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