Skip to main content

PyGekko: Gekko Timeseries and Modeling Software for Python

Project description

PyGekko: Gekko Timeseries And Modeling

PyGekko is a Python package for Gekko. Gekko is open-source timeseries-oriented software for handling and analyzing timeseries data, and for solving and analyzing large-scale economic models. You may install the PyGekko package with the following (Windows, Python 3.11-3.13):

pip install pygekko

BEWARE: PyGekko is in its very early stages!

You may for instance use PyGekko like this:

import pygekko as pg
t1 = 2021
t2 = 2023
pg.run("reset;")
pg.run(f"time {t1} {t2};")
pg.run("x1 = 2, 3, 4;")
pg.run("x2 = 7, 5, 6;")
pg.run("y = x1 + x2;")
pg.run("prt x1, x2, x1/y;")

In general, at the moment, you call Gekko through text strings containing Gekko statements, with the run() function. Printed output will be shown in the Python terminal, in this case:

                 x1         %             x2         %           x1/y         % 
2021         2.0000         M         7.0000         M         0.2222         M
2022         3.0000     50.00         5.0000    -28.57         0.3750     68.75
2023         4.0000     33.33         6.0000     20.00         0.4000      6.67

You may open the Gekko help system with pg.run("help;").

Looks

The following is how the Gekko stand-alone application looks. PyGekko does not show the main Gekko window, but can show other windows like plot, decomp, flowgraph, data-trace viewer, etc. As mentioned later on, you may have to end your Python program with a pg.wait() to make the Gekko windows stay open.

Main window

Disclaimers

PyGekko is work in progress and quite immature as a package right now. Still, the string-based interface is expected to be stable and work as-is, also in the longer run.

The PyGekko 3.3.1 version corresponds to the official Gekko 3.3.1 version, and moving forwards, these version numbers will match. Note that 'beta' releases for PyGekko are expected, for instance PyGekko 3.3.2b1, signifying work in progress towards an official PyGekko 3.3.2 version (beta versions are not installed by pip install unless the user explicitly asks for it). You may also encounter 'post' releases like 3.3.1.post1, where typically only very minor PyGekko interface problems are addressed.

Requirements

The PyGekko package only works for Python versions 3.11-3.13 under Windows 64-bit (Python 3.11 was released in October 2022). PyGekko uses the Python.NET package under the hood, which only works for Windows and does not yet support Python 3.14 (released in October 2025). PyGekko support for Python < 3.11 could be provided if there is sufficient interest. Windows 32-bit is no longer supported for newer Gekko versions 3.3.x, and hence is not supported for PyGekko either. PyGekko uses the .NET Framework (not .NET Core) with version at least 4.6.1. If a normal Gekko version can run on your Windows 64-bit pc, so should PyGekko (because it uses the same .NET Framework). PyGekko is self-contained regarding Gekko: it works completely independently of any Gekko installation.

Known issues

  • It seems there can be some issues regarding scaling of the plot window.
  • Loops and conditionals etc. (lines of Gekko code ending with an end;) cannot be directly transformed into corresponding lines of pg.run() calls. Using one glued-together string delimited with ;'s will work though.
  • Talking to dataframes (Pandas/Polars etc.) containing timeseries data can be done through csv files, cf. Gekko's import and export. Gekko can write Apache Arrow files (export<arrow>) for easy consumption by Pandas/Polars, but cannot read arrow files (yet). (Gekko's python_run amounts to calling Python from Gekko, and would be bizarre to use in PyGekko).
  • When you open up Gekko windows like for instance the plot window (example: pg.run("plot x1, x2, x1/y;"), you may put a pg.wait() at the end of your Python program to make the window(s) stay open. Otherwise Python may take these windows down when it finishes its job.

Gekko links

Contributing + source code

See the GitHub repository.

Roadmap

Among other things, it is expected that the string-based interface will gradually be supplemented with a more proper Python-function interface, for instance supplementing the string-based pg.run(f"decomp <{t1} {t2} {op}> qBNP from E_qBNP;") with an in-built pg.decomp() function providing a more Pythonic pg.decomp("qBNP", t=[t1, t2], op=op, from_="E_qBNP").

Regarding Python and PyGekko, see much more details in this roadmap.

More info

Since 2009, Gekko is being used by Danish ministeries, banks, interest groups and universities, for the simulation of economic and energy-related models. It is also used to show and analyze GAMS models. The software runs under Windows (.NET), and is licenced under GNU GPL.

Some features:

  • Timeseries-oriented software, with flexible databanks. Suitable data handling/wrangling and modeling, etc.
  • Timeseries can be dimensional (so-called array-timeseries). Data-tracing remembers how timeseries are constructed (data lineage).
  • Annual, quarters, months, weeks, days and undated frequencies supported. Conversions between these + seasonal correction.
  • Other variable types like values, dates, strings, lists, maps and matrices, including many functions dealing with these.
  • Dynamically loaded and compiled models, including failsafe mode.
  • Gauss and Newton solvers, with ordering and feedback logic. Fair-Taylor or Newton-Fair-Taylor solver for forward-looking models. Any number of simultaneous goals/means possible.
  • In-built equation browser, with integrated variable list.
  • Decomposition of model equations (including GAMS models), showing contributions. Flowgraphs to show this info, too.
  • User-defined functions and procedures, can be stored in libraries.
  • Graphics by means of embedded gnuplot
  • Interface to Python, R, GAMS and others. Reads/writes file formats like xls, xlsx, prn, csv, tsd, gdx, px, arrow-files. Integrated add-in for Excel.
  • Tabelling and menu system, outputting in text, html or Excel
  • Open databank format, using (Google) protocol buffers for storage.
  • Strict and consistent language syntax (via in-built ANTLR parser), with loops, conditionals etc.
  • Used by Statistics Denmark, Ministry of Finance, Ministry for Economic Affairs, Danish Economic Councils, the central bank of Denmark, institutions, universities and more.
  • Easy installation by means of a all-inclusive Windows installer, or manually by means of a zip-file with gekko.exe etc.
  • Open source. No licenses to compilers etc. -- everything used is C#/.NET (+ gnuplot and x12a). So everything is open-source, and therefore free of charge.

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

pygekko-3.3.3rc1.tar.gz (49.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygekko-3.3.3rc1-py3-none-any.whl (50.5 MB view details)

Uploaded Python 3

File details

Details for the file pygekko-3.3.3rc1.tar.gz.

File metadata

  • Download URL: pygekko-3.3.3rc1.tar.gz
  • Upload date:
  • Size: 49.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for pygekko-3.3.3rc1.tar.gz
Algorithm Hash digest
SHA256 b189489b35856b7a121805c89b100e0e5d2a17118abd873e918d829dd8f46d9b
MD5 e1f8f5dafa717aca45d4be887bb21974
BLAKE2b-256 2918cfbb7d2ea7caf46cbb15f7b7069a73611b27730c4b58c9be1a7a67ac96b1

See more details on using hashes here.

File details

Details for the file pygekko-3.3.3rc1-py3-none-any.whl.

File metadata

  • Download URL: pygekko-3.3.3rc1-py3-none-any.whl
  • Upload date:
  • Size: 50.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.0

File hashes

Hashes for pygekko-3.3.3rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ed05289a23291e7eb94ef51a0bb855cb878f511a85db9a1951dbaeb7cd778a5
MD5 5a76001d3d893aff3f4ba6e43756135a
BLAKE2b-256 5552c7d28cb4d368801a152c88b9885ecca75aa3c217b85385a83e6fd1794717

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page