Skip to main content

GSW-Python

Tests Wheels DOI

This Python implementation of the Thermodynamic Equation of Seawater 2010 (TEOS-10) is based primarily on numpy ufunc wrappers of the GSW-C implementation. This library replaces the original python-gsw pure-python implementation. The primary reasons for this change are that by building on the C implementation we reduce code duplication and we gain an immediate update to the 75-term equation.
Additional benefits include a major increase in speed, a reduction in memory usage, and the inclusion of more functions. The penalty is that a C (or MSVC C++ for Windows) compiler is required to build the package from source.

Warning: this is for Python >=3.8 only.

Documentation is provided at https://teos-10.github.io/GSW-Python/.

For the core functionality, we use an auto-generated C extension module to wrap the C functions as numpy ufuncs, and then use an autogenerated Python module to add docstrings and handle masked arrays. 165 scalar C functions with only double-precision arguments and return values are wrapped as ufuncs, and 158 of these are exposed in the gsw namespace with an additional wrapper in Python.

A hand-written wrapper is used for one C function, and others are re-implemented directly in Python instead of being wrapped. Additional functions present in GSW-Matlab but not in GSW-C may be re-implemented in Python, but there is no expectation that all such functions will be provided.

Installation

Pip users can install the pre-built wheels with:

pip install gsw

conda users will find binaries on conda-forge,

conda install gsw --channel conda-forge

The development version of the package can be installed from a clone of the repo using

pip install .

Citation

If you use GSW-Python, please cite: McDougall, T.J. and P.M. Barker, 2011: Getting started with TEOS-10 and the Gibbs Seawater (GSW) Oceanographic Toolbox, 28pp., SCOR/IAPSO WG127, ISBN 978-0-646-55621-5

@book{mcdougall2011getting,
  author = {McDougall, T. J. and Barker, P. M.},
  title = {Getting started with TEOS-10 and the Gibbs Seawater (GSW) Oceanographic Toolbox},
  year = {2011},
  pages = {28},
  publisher = {SCOR/IAPSO WG127},
  isbn = {978-0-646-55621-5}
}

Note for xarray users

A wrapper around gsw called gsw-xarray exists for xarray. It adds CF compliant attributes when possible, units, and name.

Note on generating the docstrings

The autogenerated docstrings are checked with codespell in the CIs. When autogenerating them we need to run pre-commit run --all-files and fix the documentation issues found.

Development notes

You will need a suitable compiler: gcc or clang for unix-like systems, or the MSVC compiler set used for Python itself on Windows. For Windows, some of the source code has been modified to C++ because the MSVC C compiler does not support the C99 complex data type used in original GSW-C.

The subdirectory ('tools') contains modules and scripts for maintaining the code that is autogenerated from the upstream GSW-Matlab and GSW-C repos. The scripts are to be run from this directory; they make assumptions about where they are, and about where upstream repos are. Specifically, it is assumed that GSW-Matlab, GSW-C, and GSW-Python git repos are all in the same base directory.

Scripts

  • copy_from_GSW-C.py: copies the relevant .c and .h files from a sibling GSW-C repo, if the latter are newer.
  • mat2npz.py: generates an npz file in gsw/tests containing the test data and check values from the gsw_data_v3_0.mat file in the sibling GSW-Matlab repo.
  • make_ufuncs.py: Generates the src/_ufuncs.c file to turn the scalar C functions into numpy ufuncs. It writes ufuncs.list in the current directory as a record of the ufunc names. Functions are identified as ufunc candidates based on their signatures, parsed from src/c_gsw/gswteos-10.h.
  • make_wrapped_ufuncs.py: Generates gsw/_wrapped_ufuncs.py based on the output of make_ufuncs.py. It adds docstrings constructed from the Matlab help text.
  • fix_wrapped_ufunc_typos.py: Fixes docstring typos that have been identified, but not yet fixed, in the GSW-Matlab repo.
  • codegen: Runs the last three python scripts.

Modules

  • c_header_parser.py: Functions for taking apart the function declarations in gswteos-10.h.
  • matlab_parser.py: Functions specifically for reading the GSW-Matlab function signatures and for splitting out the help text.
  • docstring_parts.py: Blocks of text for assembling docstrings.
  • docstring_utils.py: Functions for assembling docstrings in numpydoc format.
  • categories.py: Functions for listing gsw function names by category. This is not used by any of the other functions or scripts, but was used when initially categorizing the functions for inclusion in submodules.

Notes

  • In addition to the generated src/_ufuncs.c, there are two C files that are hand-written: src/method_bodies.c and src/method_def_entries.c. These are imported by src/_ufuncs.c. They handle some C functions that are not suitable for ufuncs.
  • Specialized Matlab parsing is also done in gsw/tests/check_functions.py, which is used by gsw/tests/test_check_functions.py; see the docstring of the former for more info.

Testing

To test, after installation, run "pytest --pyargs gsw".

Metadata

Release files for gsw 3.6.23

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

Source distribution (sdist)

Source distribution for gsw 3.6.23
File Size Uploaded
gsw-3.6.23.tar.gz 2.7 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for gsw 3.6.23
File
gsw-3.6.23-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
gsw-3.6.23-cp311-abi3-pyemscripten_2026_0_wasm32.whl CPython 3.11 abi3 PyEmscripten 2026.0+ WebAssembly Details
gsw-3.6.23-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
gsw-3.6.23-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64, Linux glibc 2.28+ ARM64 Details
gsw-3.6.23-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
gsw-3.6.23-cp311-abi3-macosx_10_9_x86_64.whl CPython 3.11 abi3 macOS 10.9+ x86-64 Details

Total release size: 16.3 MB

Release files / gsw-3.6.23.tar.gz

Download URL gsw-3.6.23.tar.gz
Size 2.7 MB
Tags Source
SHA-256 checksum
How to use checksums
d14a734addfc96445ae84c800ad642d453ff174d48d6c30c0879a4425185b82a
BLAKE2b-256 checksum
How to use checksums
48dc1d4dbe5569f299968aa6f6745c105cccc0cf700ae22717c422fb095e6b6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.

Transparency log

Release files / gsw-3.6.23-cp311-abi3-win_amd64.whl

Download URL gsw-3.6.23-cp311-abi3-win_amd64.whl
Size 2.2 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
b74b5234c44c0a380547aa4e68177dc8cd077c63c58a66acb448b2eece74f7f9
BLAKE2b-256 checksum
How to use checksums
9592f1f4dd4cebf6a56396057e4c3722e15d9cb84505f03fd520164065e4c89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.

Transparency log

Release files / gsw-3.6.23-cp311-abi3-pyemscripten_2026_0_wasm32.whl

Download URL gsw-3.6.23-cp311-abi3-pyemscripten_2026_0_wasm32.whl
Size 2.1 MB
Tags CPython 3.11 PyEmscripten 2026.0+ WebAssembly abi3
SHA-256 checksum
How to use checksums
870a0e0246072ac63cb0359e9c994c98cf0607c1d8c27598e871c7bbc8464505
BLAKE2b-256 checksum
How to use checksums
e7ac57f9df6b2fc6ffc4ba101fe31f0247b7100e0fe1b52edbd3e5d384c726a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.

Transparency log

Release files / gsw-3.6.23-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL gsw-3.6.23-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 2.4 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
a67daf2fe608a8fbcc88b5aef962d1f6afe79a1af2d763e29f6bbfef051b096b
BLAKE2b-256 checksum
How to use checksums
6191cc7b4a4429e596d6ff7fe6cfa8f7e2162d54a5c9b083b24cb2dcbe58db83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.

Transparency log

Release files / gsw-3.6.23-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl

Download URL gsw-3.6.23-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Size 2.4 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
ca81546bdba98a0e4af6e9b738cdaa6f96de23348b8bccb8c2f3221ef166df8b
BLAKE2b-256 checksum
How to use checksums
f8ebea5936ec1a20795194318c0885ab46288175b9cb9fbf3ab0d7c65055b9e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.

Transparency log

Release files / gsw-3.6.23-cp311-abi3-macosx_11_0_arm64.whl

Download URL gsw-3.6.23-cp311-abi3-macosx_11_0_arm64.whl
Size 2.3 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9906645d8d3a897cbd90cc58373ea3ba239a4db63708039b1a11c2dbc4b2e408
BLAKE2b-256 checksum
How to use checksums
6ecd1ce4f60b69a4ad9a95287f4f03d4846c7e3763a6de93883e218f75c169c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.

Transparency log

Release files / gsw-3.6.23-cp311-abi3-macosx_10_9_x86_64.whl

Download URL gsw-3.6.23-cp311-abi3-macosx_10_9_x86_64.whl
Size 2.2 MB
Tags CPython 3.11 abi3 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
756fdf57432ff10d08bd3af9a0c97f8899c8a50b3e444b67b17984e10fbfcf38
BLAKE2b-256 checksum
How to use checksums
22fe3acd7274f19c8641b6891d3bc0d87872166b9aeb1a41fe75b522690d9c45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

3.6.23 This release

7 release files

3.6.22

6 release files

3.6.21

6 release files

3.4.2

16 release files

3.3.1

1 release file

3.3.0

1 release file

3.2.1

1 release file

3.2.0

1 release file

3.1.1

1 release file

3.1.0

1 release file

3.0.6

1 release file

3.0.3

1 release file

3.0.2

1 release file

3.0.1

1 release file

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