Skip to main content

polars-gdx

Lazy, prefiltered Polars access to GAMS GDX files — no GAMS installation required.

  • scan_gdx(path, symbol=...) returns a pl.LazyFrame; nothing is read until collect(), and column projection is pushed down via Polars' IO-source interface. read_gdx(...) is the eager convenience wrapper (scan_gdx(...).collect(), same arguments).
  • Predicates on key columns (key_filter={dim_index: allowed_labels} or filter()) are folded into a native, index-based prefilter inside the Rust read loop, so unwanted records are never materialized — unlike the official gamsapi reader, which must load everything into pandas first. The prefilter runs inside a bulk C callback (gdxDataReadRawFastEx): one FFI crossing for the whole symbol, with early termination for head(n).
  • read_domains(path, symbol=...) lists the unique labels actually used per index dimension in a single bulk C scan (gdxGetDomainElements) — the cost of unique() over a key column without reading or materialising any records, valuable on very large symbols.
  • Under the hood: hand-written FFI to the vendored MIT-licensed GDX C library, extracted from lolow/gdxcomp, building on GAMS-dev/gdx.

Usage

import polars as pl
from polars_gdx import scan_gdx, list_symbols

list_symbols("trnsport.gdx").filter(pl.col("type") == "Param")

# lazy: nothing read yet
x = scan_gdx("trnsport.gdx", symbol="x")

# read only the seattle rows, skipping all others natively
x.filter(pl.col("dim_0") == "seattle").collect()

# eager convenience: read_gdx = scan_gdx(...).collect()
from polars_gdx import read_gdx
df = read_gdx("trnsport.gdx", symbol="x", key_filter={0: ["seattle"]})

# unique labels per index dimension without reading the records:
from polars_gdx import read_domains
read_domains("trnsport.gdx", symbol="x")

Label matching

Key labels (key_filter and filter(pl.col(key) == label) predicates) are matched case-insensitively (ASCII-folded), the way GAMS does — "SEATTLE" matches a stored "seattle". The labels in the produced frame always keep the file's original casing. For predicate filters whose label only differs in case from the stored one, the plugin deliberately skips the native prefilter and re-applies a case-folded predicate on the full read, because Polars' == is case-sensitive and would otherwise silently drop the rows.

File handle lifetime

scan_gdx keeps the GDX file open until the returned LazyFrame is collected and released (Polars may read the source more than once). Use read_gdx, or an explicit Reader with its close() / context-manager support, to release the handle eagerly — relevant on Windows, where an open handle locks the file.

Benchmark

vs gamsapi 54.5.0 (pandas-backed), on a 2M-record parameter (80 MB GDX); best of 5 runs. See benchmarks/bench_vs_gamsapi.py (run as a CI job on every push).

Scenario polars-gdx gamsapi (pandas)
Full read (2M rows) 0.128 s 0.086 s
filter(dim_0 == label) — 1000 of 2M rows 0.059 s 0.096 s¹
Explicit key_filter — 1000 rows 0.058 s —
head(1000) of 2M rows 0.001 s 0.101 s¹

¹ gamsapi has no lazy loading or pushdown: it must materialize the whole symbol, then filter. The advantage of polars-gdx grows with predicate selectivity; head(n)/n_rows terminates the native read after n records.

Build

maturin develop --release   # builds the vendored GDX C library + extension
pytest

Requires a C++17 compiler and CMake ≥ 3.5 at build time; runtime has no GAMS dependency.

Layout

crates/gdx-sys        # raw FFI; builds vendored GDX-dev/gdx via CMake
crates/gdx            # safe RAII wrapper (global lock; lazy UEL interning)
crates/polars-gdx     # PyO3 extension: symbol listing + Arrow streaming with prefiltering
python/polars_gdx     # Python layer: scan_gdx / list_symbols

Metadata

Release files for polars-gdx 0.1.3

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

Source distribution (sdist)

Source distribution for polars-gdx 0.1.3
File Size Uploaded
polars_gdx-0.1.3.tar.gz 2.3 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-gdx 0.1.3
File
polars_gdx-0.1.3-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
polars_gdx-0.1.3-cp39-abi3-manylinux_2_28_x86_64.whl CPython 3.9 abi3 Linux glibc 2.28+ x86-64 Details
polars_gdx-0.1.3-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details
polars_gdx-0.1.3-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
polars_gdx-0.1.3-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details

Total release size: 5.2 MB

Release files / polars_gdx-0.1.3.tar.gz

Download URL polars_gdx-0.1.3.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
a51f8afac07c474b18699ac45d2f7e71d08c97847d506f704ea2a28f74c3db61
BLAKE2b-256 checksum
How to use checksums
2601a908f5776bdbe739dbc2b8acc619d6ade8b9b4b23a868af18b2cbda7db92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Release files / polars_gdx-0.1.3-cp39-abi3-win_amd64.whl

Download URL polars_gdx-0.1.3-cp39-abi3-win_amd64.whl
Size 704.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1fb681031de93f414d5288f2febd670a00d8397867cb9ac4d5bfc055a617a466
BLAKE2b-256 checksum
How to use checksums
8808b5d6c66f1b267abf4dc37cf65e75133d587b7ecaf4a9dcb3011f023def3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Release files / polars_gdx-0.1.3-cp39-abi3-manylinux_2_28_x86_64.whl

Download URL polars_gdx-0.1.3-cp39-abi3-manylinux_2_28_x86_64.whl
Size 590.9 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
ada1eca8695696cb2c58d0b43db291015c4a2ef27be71801abe55b3ab27814de
BLAKE2b-256 checksum
How to use checksums
6d51c3ba02fc9e9ea123ac73b21a7877c8c8960f81a880470e1ca41ca8db5179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Release files / polars_gdx-0.1.3-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL polars_gdx-0.1.3-cp39-abi3-manylinux_2_28_aarch64.whl
Size 564.8 kB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
9af6cef6981ea23c01d1df72be8054c125f9f050fecb57df3667a72289ed238a
BLAKE2b-256 checksum
How to use checksums
a69367951f39cd720433cc1ab26b7d0efb1eef5997fb0382d7b7c34b613bcb39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Release files / polars_gdx-0.1.3-cp39-abi3-macosx_11_0_arm64.whl

Download URL polars_gdx-0.1.3-cp39-abi3-macosx_11_0_arm64.whl
Size 493.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
20b4d4251e7a6bdff1598078bdd831dea469ef6dc71c5c6cf615163507bc788f
BLAKE2b-256 checksum
How to use checksums
b79c7ac7612bd7700eb52d20cb151e6abddd76eb8eef6efda430a4042fd69898
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Release files / polars_gdx-0.1.3-cp39-abi3-macosx_10_12_x86_64.whl

Download URL polars_gdx-0.1.3-cp39-abi3-macosx_10_12_x86_64.whl
Size 531.0 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
0e1d60fa385573c0c35ecfe34d0b1fb6d8aa69618f16efc42503645474b21cdb
BLAKE2b-256 checksum
How to use checksums
56bfd73d0aca120bcf6a4f7280bc0c76d6fcc5d233828d6deb89b3f9ea320466
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.6.0

6 release files

0.5.0

6 release files

0.4.0

6 release files

0.3.1

6 release files

0.3.0

6 release files

0.2.0

6 release files

This release

0.1.3 This release

6 release files

0.1.2

6 release files

0.1.1

6 release files

0.1.0

6 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