Skip to main content

python 3+ ctypes wrapper for selected function prototypes defined by IPhreeqc version 3 in IPhreeqc.h and Var.h

Project description


A python 3+ ctypes wrapper for selected function prototypes defined by IPhreeqc version 3 in IPhreeqc.h and Var.h.

Version 0.1a5 is an "alpha" pre-release.

See "Change Log" below for recent changes.

This package is tailored to the author's preference but is made available in the event others find it useful.

The author is not affiliated with the USGS or the Phreeqc project.


Option 1

pip install iphreeqc-py

Option 2

pip install git+

Option 3

git clone -b 'v0.1a5' --single-branch
cd iphreeqc-py; python install

This python package intentionally does not install or come with an IPhreeqc instance. An IPhreeqc shared library must be built and installed by the user. An example IPhreeqc install is below.

Additional Documentation

See IPhreeqc.h and Var.h.

Example iphreeqc-3.6.2-15100 install

Using Ubuntu 18.04.4 LTS with gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0:

screen # optional, start screen session
tmpDir=$(mktemp -d)
cd $tmpDir
tar xvf ./iphreeqc-3.6.2-15100.tar.gz
cd iphreeqc*/
# configure options used by the author
./configure --libdir=${HOME}/local/lib/iphreeqc-3.6.2-15100 --includedir=${HOME}/local/include/iphreeqc-3.6.2-15100 --docdir=${HOME}/local/share/doc/iphreeqc-3.6.2-15100 CFLAGS="-g -O2 -march=native" CXXFLAGS="-g -O2 -march=native"
ncp1=$(expr $(cat /proc/cpuinfo | grep processor | wc -l) + 1)
make -j $ncp1 V=s 2>&1 | tee ipcBuild-$(date +"%Y%m%d-%H%M").log | grep -i '[^_-\"a-z]error[^_-.a-z]'
make install

Example iphreeqc-py tests

Assuming iphreeqc-py is installed and an IPhreeqc shared library has been configured, built, and installed as described above, try:

python -c "import iphreeqc; print(iphreeqc.ex1_mod(lib=\"${HOME}/local/lib/iphreeqc-3.6.2-15100/\", database=\"${HOME}/local/share/doc/iphreeqc-3.6.2-15100/database/phreeqc.dat\"))"
python -c "from test_iphreeqc.test_ex2 import ex2; print(ex2(lib=\"${HOME}/local/lib/iphreeqc-3.6.2-15100/\", database=\"${HOME}/local/share/doc/iphreeqc-3.6.2-15100/database/phreeqc.dat\"))"

Clean up

rm -fr $tmpDir
exit # screen session


For the above examples, IPhreeqc.h and Var.h are in


Last tested with iphreeqc-3.6.2-15100 and python 3.8.1 in a virtual environment on Ubuntu 18.04.4 LTS, February 2020.

References & Attribution

    Note the files in the examples directory and content used from 
    these files elsewhere in iphreeqc-py are copied from:


    and are distributed under the terms of the PHREEQC Public Domain
    declaration (see the "phreeqc-version-3" link above).

PhreeqPy, Python Tools for PHREEQC
Copyright 2011 Mike Mueller and contributors

IPhreeqcPy, a python wrapper for IPhreeqc
Copyright 2016 Ravi Patel

This work is derived from IPhreeqcPy.

License Notice

iphreeqc-py Copyright (C) 2020 Stuart Nolan

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <>.

License Usage Reference


Change Log

iphreeqc-py is a work in progress and is not fully tested

Notable changes from 0.1a4:

  • remove functionality to index back from the value returned by functions such as GetDumpStringLineCount given a negative index argument to the python functions GetDumpStringLine, GetErrorStringLine, GetLogStringLine, GetOutputStringLine, GetSelectedOutputStringLine, and GetWarningStringLine. See for examples of how retaining this functionality could lead to issues.
  • change default error text for error code 1 to 'Error string' and edit the _RaiseIphreeqcError method accordingly
  • edit download options 2 and 3 for installing an iphreeqc-py release via github by release tag
  • implement X.X<pre-release>X.devX versioning for development releases i.e. after the 0.1a5 release, the version will be 0.1a6.dev0 on un-tagged git master branch commits until 0.1a6 is released (and the git tag v0.1a6 is pushed to github)
  • miscellaneous documentation edits
  • add test_iphreeqc/ module

See here for specifics.

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

iphreeqc-py-0.1a5.tar.gz (69.1 kB view hashes)

Uploaded source

Built Distribution

iphreeqc_py-0.1a5-py3-none-any.whl (90.7 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page