Skip to main content

ChemQL

ChemQL is a chemistry-focused query language for searching and working with chemical data from Python or an interactive terminal. It provides a compact way to query elements, molecules, and chemical reactions using filters, logical conditions, sorting, and result projections.

Package: chemql-python
Python import: chemql

Features

  • Query element, molecule, and reaction datasets.
  • Filter records with comparisons and logical conditions.
  • Match text using wildcard patterns with like and case-sensitive like!.
  • Use and, or, not, and parentheses to combine conditions.
  • Use likep for Python regular-expression matching.
  • Combine list results with union and intersection.
  • Sort, limit, count, and project results with return.
  • Look up elements, molecules, and reactions using findel, findmol, and findre.
  • Balance chemical equations.
  • Set reaction conditions, including temperature, pressure, and catalysts.
  • Use Python expressions and control blocks alongside ChemQL queries.
  • Use ChemQL from the command line or through its Python API.

Installation

Install the Python package from PyPI:

pip install chemql-python

Quick start

Start the interactive terminal:

chemql

Then try:

search elements name = "Hydrogen"
findel "He"
findmol "H2O"
search molecules molecular_weight < 20 return name formula molecular_weight
search reactions reaction_type = "combustion" return name equation

Show the built-in command reference from the REPL:

help

Command-line usage

Run a single command with -c:

chemql -c 'search elements name = "Hydrogen"'

Run commands from a file with -f:

chemql -f queries.chemql

Check the installed version:

chemql --version

A query file can contain multiple ChemQL commands, one per line. Use the // comment marker for comments and a trailing backslash (\) to continue a command onto the next line.

Example queries.chemql:

// Find lighter molecules
search molecules molecular_weight < 20 return name formula molecular_weight

// Show a subset of the periodic table
search elements atomic_number > 10 and atomic_number < 20 sort atomic_number desc limit 5

Query language

Data sources

ChemQL provides three main sources:

Source Contents


elements Periodic-table element data molecules Molecule properties and identifiers reactions Reaction equations, conditions, and metadata

Search a source explicitly:

search elements
search molecules
search reactions

You can also use search all before a source name, for example:

search all elements atomic_mass < 100

Change the active source in an interactive session with:

source elements
source molecules
source reactions

Filtering

Use comparison operators to filter records:

Operator Meaning


= Equal != Not equal > Greater than < Less than >= Greater than or equal <= Less than or equal like Case-insensitive wildcard match like! Case-sensitive wildcard match likep Python regular-expression match has Check whether a value contains an item

Examples:

search elements atomic_number > 10
search molecules molecular_weight <= 20
search molecules name like "*water*"
search reactions id likep ".*haber(\s*|-|_)process.*"

The wildcard matcher supports * for a sequence of characters and other wildcard tokens supported by ChemQL's pattern matcher. Use likep when you need regular expressions rather than wildcard patterns.

Logical conditions and parentheses

Combine conditions with and, or, and not. Parentheses group conditions. Comparison operators and parentheses can be written without surrounding spaces.

search elements name not like "*ium"
search elements name not like "*ium" and not atomic_mass < 50
search elements atomic_mass > 50 and (density<10 or boil<100)

Combining query results

Use union to combine results and intersection to keep records present in both result lists. Operations are evaluated from left to right.

search elements name not like "*ium" intersection search elements name like "*um"

Use the Python API's query-object operators | and & for union and intersection, respectively, when working with ChemQLQuery objects.

Sorting, limiting, counting, and returning fields

search elements sort atomic_number
search molecules sort molecular_weight desc
search molecules limit 10
search molecules count
search molecules molecular_weight < 20 return name
search molecules molecular_weight < 20 return name formula molecular_weight
  • sort <field> [asc|desc] sorts results.
  • limit <number> limits the number of results.
  • count returns the number of matches.
  • return <field...> returns only selected fields. One field produces a list; multiple fields produce a table-like result.
  • first and last can be used to select one result.

Find commands

findel "He"
findel "Hydrogen"

findmol "H2O"
findmol "Water"

findre "Haber process"
findre "RHEA:10000" return name equation source

findmol searches the local molecule dataset first and can use external chemical-data services when a local match is not found. External lookups require an internet connection and may be unavailable if the service is down.

Reactions and equation balancing

ChemQL includes reaction data and commands for working with reaction conditions.

findre "Haber process"
balance O2 + H2 -> H2O
balance O2 + H2 <-> H2O

The -> arrow denotes an irreversible reaction, while <-> denotes a reversible reaction.

Set conditions before using react:

set temperature 723K
set pressure 20265000pa
set catalysts iron zinc
conditions
react N2 3H2

Temperature can be supplied in Celsius (C), Fahrenheit (F), or Kelvin (K). Pressure supports units such as pascals and bar; the available unit conversions depend on the installed version. Preset conditions are also available:

set temperature standard
set pressure room

Use help in the terminal for the command reference included with your installed version.

Python API

Import ChemQL from Python:

import chemql

result = chemql.execute_query_text(
    'search elements name = "Hydrogen"'
)
print(result)

You can also use execute_query for a query string:

import chemql

result = chemql.execute_query('search molecules molecular_weight < 20')
print(result)

The package exposes chemistry data classes and helpers, including Element, Molecule, Reaction, ChemQLError, Unknown, ReturnTable, and balance_stoichiometry.

Query builder API

Versions that include the query-builder API also support chaining query conditions:

import chemql

x = chemql.search("elements")
y = x.atomic_mass.condition(lt=10)
z = y.return_("name")

print(z)          # The query as text
print(z.execute())  # Execute the query

Query objects can be combined with | (union) and & (intersection). The convenience functions chemql.union(x, y) and chemql.intersection(x, y) are also available in versions that include this API.

Hybrid Python

ChemQL can execute Python expressions inside square brackets:

[x = 10]
[print(x)]

It also supports Python control blocks using [for ...], [if ...], [elif ...], [else], [while ...], [break], [continue], and [endblock].

Use {{ ... }} to evaluate a ChemQL query and insert its result into Python:

[print({{ search elements atomic_number = 1 }})]

Only run Python code and shell commands from sources you trust.

Data and external services

ChemQL loads bundled JSON datasets for elements, molecules, reactions, molecule bonds, and bond energies. Some molecule lookups may query PubChem or other external sources when the local dataset does not contain a match.

The periodic-table dataset is based on PeriodicTableJSON by Bowserinator. Review the dataset's accompanying license and attribution requirements when redistributing it or derivative data. The licenses and sources for the other bundled datasets should be checked in their respective files before redistribution.

Safety note

ChemQL's hybrid Python functionality can execute Python code. If your installed version supports backtick-wrapped shell commands, those can execute operating-system commands as well. Do not run untrusted ChemQL scripts or queries.

Development notes

  • The interactive shell uses prompt_toolkit.
  • The command-line interface supports single-command execution (-c) and file execution (-f).
  • Consult the package's source and included help output for the exact commands and fields supported by your installed version.

License

MIT License

Created by Mohammad Rakibul Islam. Source code: rakibulofficial1017/ChemQL.

Metadata

Release files for chemql-python 1.0.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 chemql-python 1.0.0
File Size Uploaded Provenance
chemql_python-1.0.0.tar.gz 220.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for chemql-python 1.0.0
File Interpreter ABI Platform
chemql_python-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 445.5 kB

Release files / chemql_python-1.0.0.tar.gz

Download URL chemql_python-1.0.0.tar.gz
Size 220.5 kB
Tags Source
SHA-256 checksum
How to use checksums
417317d9f818cc5378ab4597255dda587dbce0ed99bf7f5d986fa00e9c2f44fe
BLAKE2b-256 checksum
How to use checksums
a648df3285f2fbdd5ceae3837e478b98dba8df010b41d9c0017fb1659ba783bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / chemql_python-1.0.0-py3-none-any.whl

Download URL chemql_python-1.0.0-py3-none-any.whl
Size 225.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d251288ea71bc0aa105b70a33885d5c0e2a77d792e1c02dbdd329fa21a687d19
BLAKE2b-256 checksum
How to use checksums
b766c5732ea7725f0c5040339f59460f3c679aed5e4f62321bf28b52b17973cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for chemql-python 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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