Skip to main content

Chemical formula parser

Project description


A lightweight package for parsing chemical formula strings into python dictionaries.


  • Convert a chemical formula string into a python dictionary.
    • example: "CH4" returns {"C":1.0, "H":4.0}
  • Handles fractional stoichiometry.
    • example: "C1.5O3" returns {"C":1.5, "O":3.0}
    • example: "H2e-1O1e-1" returns {"H":0.2, "O":0.1}
  • Handles groups with parentheses.
    • example: "(CH3)2(CH2)4" returns {"C":6.0, "H":14.0}
    • Note: chemparse currently only handles non-nested paretheses. A formula with nested parentheses like "CH3(C2(CH3)2)3CH3" will not work properly.


Install chemparse with pip:

$ pip install chemparse


Import chemparse in python and use the parse_formula function:

import chemparse


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chemparse-0.1.3.tar.gz (3.7 kB view hashes)

Uploaded source

Built Distribution

chemparse-0.1.3-py3-none-any.whl (3.9 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page