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).
  • Key columns are Polars Enum typed over the file's UEL table (requires Polars ≥ 2.0). The Rust layer emits Arrow dictionary arrays whose values are the full UEL table in file order and whose indices are the raw 0-based UEL numbers, so Polars reinterprets the buffers zero-copy: no per-record string materialisation, and ==/is_in/join/group_by on keys run as integer category comparisons. Use .cast(pl.String) when you need string operations on keys.
  • Predicates on key columns (key_filter={dim_index: allowed_labels}, filter(pl.col(key) == label) or filter(pl.col(key).is_in(labels))) 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).
  • threads= (on scan_gdx/read_gdx) parallelises the raw read across independent file handles. With a first-dimension filter, each worker scans a contiguous range of the first key dimension and whole non-matching ranges are skipped without touching the file. Without one, the data section is split by file position at exact record boundaries: a cached restart-position index (one cheap sequential pass, built once per file+symbol) provides the boundaries, and each worker decodes only its own byte range. In both cases results are concatenated in range order so record order matches the serial read exactly, and any boundary/count mismatch falls back to a verified serial read. threads="auto" (recommended) uses all cores for symbols of 5M+ records and stays serial for smaller ones. Filters on non-leading dimensions still decode every record within each worker's range, but the decode is now spread across all workers instead of the single-threaded wall-time floor. Block-compressed GDX files (written with GAMS compression) are fully supported: record checkpoints become (compressed-block start, offset-in-block) pairs, so workers resume mid-block exactly and the span-seek path skips the decompression of the whole prefix before a first-dimension filter's window.
  • 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"]})

# large symbols: parallel raw read across all cores
big = scan_gdx("huge.gdx", symbol="x", threads="auto")

# 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 exactly (case-sensitively, byte-for-byte as stored in the file). The labels in the produced frame always keep the file's original casing.

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.117 s 0.086 s
filter(dim_0 == label) — 1000 of 2M rows 0.006 s 0.096 s¹
Explicit key_filter — 1000 rows 0.005 s —
head(1000) of 2M rows 0.004 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.6.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 polars-gdx 0.6.0
File Size Uploaded
polars_gdx-0.6.0.tar.gz 2.4 MB Details

Built distributions (wheels)

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

Total release size: 5.5 MB

Release files / polars_gdx-0.6.0.tar.gz

Download URL polars_gdx-0.6.0.tar.gz
Size 2.4 MB
Tags Source
SHA-256 checksum
How to use checksums
a9a61dc8805b876edea700d7d84fff96b67f6691dfafca612d279d5429e56547
BLAKE2b-256 checksum
How to use checksums
27a63105b8503f3ca6f7fcf2d3b2de9cee42eac15117be8f19078e42fb169526
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 6, 2026.

Transparency log

Release files / polars_gdx-0.6.0-cp310-abi3-win_amd64.whl

Download URL polars_gdx-0.6.0-cp310-abi3-win_amd64.whl
Size 753.6 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
144c6148bcba9ea4a2cf5bb05d7bbb8f8243011544539ccb501f8bd71853cc05
BLAKE2b-256 checksum
How to use checksums
0b35b6b33787d288166e6ea588819c21b593e4d51fe01d3fbcb7d14f0da718e1
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 6, 2026.

Transparency log

Release files / polars_gdx-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL polars_gdx-0.6.0-cp310-abi3-manylinux_2_28_x86_64.whl
Size 638.5 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
4ed028c75b0cb51f09fac3fb64a7b4c1151f7f8a9faa6ab19a7ff2a5f76f2596
BLAKE2b-256 checksum
How to use checksums
a07d9ae1fcb770dc3ffb687cc135ce5dc2de84f2bb61e31bdb2c63745f9dd385
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 6, 2026.

Transparency log

Release files / polars_gdx-0.6.0-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL polars_gdx-0.6.0-cp310-abi3-manylinux_2_28_aarch64.whl
Size 606.2 kB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
9df6563537e0c1292560040d4993080d4cf38aba0dd2d8a0d00b289ee03ff973
BLAKE2b-256 checksum
How to use checksums
04b29a42a04757c4ee364eea2be8c05bf71603e71b8c5093b8e2f317b1eb703f
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 6, 2026.

Transparency log

Release files / polars_gdx-0.6.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL polars_gdx-0.6.0-cp310-abi3-macosx_11_0_arm64.whl
Size 529.9 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9bd72fb340b07d9f22d73e9bf0c42b2a315a55801f71f50edfdd30ce05fc8b1f
BLAKE2b-256 checksum
How to use checksums
d9cc983c6072be6622eb3aa1ff6332b7c1fa3618503f3c5d66219546d7eb01cf
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 6, 2026.

Transparency log

Release files / polars_gdx-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL polars_gdx-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 573.1 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
329daf51ee0a3a60344feeca77e1e413970d81dee9cc894b3173a8d1f921a908
BLAKE2b-256 checksum
How to use checksums
7949462b4d5d89d774ed70f6a5f2f7058550ecc4f8a63e5c3dc0c1b245866d55
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 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

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

0.1.3

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