Skip to main content

Python-ETM Connector

Project description

PyETM Logo (16xRes)

This package provides a set of tools for interaction with the Energy Transition Model's API. Learn more about the Energy Transition Model here.

The package is designed to be a modular tool that advanced users can incorporate into their scenario workflows. More documentation is available via the ETM documentation page.


Installation

Note: If you are not familiar working with python packages, please refer to the quick start guide first.

Install pyetm from PyPI:

pip install pyetm

Requirements: Python 3.12 or later

Check your Python version:

python3 --version

If you need to install Python:


Quick Start

1. Create a Virtual Environment

We recommend using a virtual environment to keep your project dependencies isolated:

# Create a new virtual environment
python3 -m venv .venv

# Activate it
# On macOS/Linux:
source .venv/bin/activate

# On Windows (PowerShell):
.venv\Scripts\Activate.ps1

# On Windows (Command Prompt):
.venv\Scripts\activate.bat

More details on how python virtual environments work can be found here

2. Install pyetm

With your virtual environment activated:

pip install pyetm

Note: New versions of pyetm are consistently released. Check here for the latest release

An example of how to install a specific release:

pip install pyetm==2.0.0

3. Initialize Your Project

Run the interactive setup command:

pyetm init

This will:

  • Prompt you for your ETM API token (get your token here)
  • Ask which environment you want to use (production, beta, or local)
  • Create a .env configuration file
  • Copy example Jupyter notebooks and helper files to your current directory

Non-interactive mode: You can also provide options directly:

pyetm init --token etm_your.token.here --environment pro --log-level INFO

Options:

  • --token: Your ETM API token
  • --environment: Target environment (pro, beta, or local)
  • --log-level: Logging verbosity (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • --force: Overwrite existing files without prompting

Using Jupyter Notebooks

After running pyetm init, you'll have example notebooks in your current directory. Here's how to set them up:

1. Install Jupyter

In your virtual environment:

pip install notebook ipykernel

2. Create a Jupyter Kernel

Register your virtual environment as a Jupyter kernel:

python -m ipykernel install --user --name=pyetm-env --display-name "Python (pyetm)"

This creates a kernel called "Python (pyetm)" that Jupyter can use.

3. Launch Jupyter

jupyter notebook

4. Select the Kernel

When you open a notebook:

  1. Click KernelChange kernel
  2. Select Python (pyetm)

Using VS Code

If you prefer VS Code:

  1. Install the Python and Jupyter extensions
  2. Open a .ipynb file
  3. Click Select Kernel at the top right
  4. Choose Python (pyetm) from the list

Important notes

The notebooks are set up to run against scenarios on pro. You will need to make some edits to the paths in these notebooks, for example in basic_features.ipynb the examples attempt to read from:

"../examples/inputs/example_input_excel.xlsx"

Whereas your example_input_excel.xlsx is more likely to be at:

"inputs/example_input_excel.xlsx"

You can change the paths or move the files!


Configuration

The pyetm init command creates a .env file with your settings. You can also configure manually:

Environment Variables

Create a .env file in your project directory:

# Your ETM API token (required)
ETM_API_TOKEN=etm_your_token_here

# Environment (default: pro)
# Options: pro, beta, local, or stable tags like 2025-01
ENVIRONMENT=pro

# Logging level (default: INFO)
LOG_LEVEL=INFO

# CSV export settings (optional)
CSV_SEPARATOR=,
DECIMAL_SEPARATOR=.

Environment Options:

  • pro (default): Production environment
  • beta: Staging environment
  • local: Local development environment
  • YYYY-MM: Stable tagged environment (e.g., 2025-01)

Advanced Configuration

You can override the base URL directly if needed:

BASE_URL=https://engine.energytransitionmodel.com/api/v3

SSL/TLS Configuration

For corporate environments or custom certificate setups:

Option Default Description
SSL_VERIFY true Verify SSL certificates. Set to false only for testing with self-signed certificates. Never disable in production!
TRUST_ENV false Enable system proxy environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY)
SSL_CERT_PATH (empty) Path to custom CA certificate bundle for corporate environments

Example for corporate CA:

SSL_CERT_PATH=/path/to/corporate-ca-bundle.pem
TRUST_ENV=true
HTTP_PROXY=http://proxy.company.com:8080

For more advanced options, see the full documentation.


Example Usage

After setup, you can use pyetm in your Python code. The main object you'll work with is the Scenario:

from pyetm.models.scenario import Scenario

# Create a new scenario
scenario = Scenario.create({
    "area_code": "nl2023",
    "end_year": 2050,
    "title": "My Netherlands Scenario"
})

# Update inputs (sliders in the ETM)
scenario.update_user_values({
    "capacity_of_energy_power_solar_pv_solar_radiation": 15000,
    "capacity_of_energy_power_wind_turbine_inland": 8000
})

# Get results via gqueries
scenario.add_queries(['total_energy_demand', 'dashboard_total_costs'])
scenario.execute_queries()
results = scenario.results()
print(results)

# Load an existing scenario
existing = Scenario.load(saved_scenario_id=12345)
print(f"Loaded: {existing.title}")

Working with Multiple Scenarios

from pyetm.models.scenarios import Scenarios

# Load from Excel
scenarios = Scenarios.from_excel("inputs/my_scenarios.xlsx")

# Compare results across scenarios
comparison = scenarios.combine.gquery_results()
print(comparison)

# Export to Excel
scenarios.combine.to_excel("outputs/results.xlsx")

For more examples, check the notebooks created by pyetm init or visit our documentation.


Temporary File Storage

The package stores temporary files (cached curves and custom data) in your system's temp directory:

  • macOS/Linux: /tmp/pyetm/
  • Windows: %TEMP%\pyetm\

Contributing

Interested in contributing to pyetm development? See our Contributing Guide for details on:

  • Setting up the development environment with Poetry
  • Running tests
  • Code style guidelines
  • Submitting pull requests

Getting Help

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

pyetm-2.0.0b7.tar.gz (433.2 kB view details)

Uploaded Source

Built Distribution

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

pyetm-2.0.0b7-py3-none-any.whl (126.7 kB view details)

Uploaded Python 3

File details

Details for the file pyetm-2.0.0b7.tar.gz.

File metadata

  • Download URL: pyetm-2.0.0b7.tar.gz
  • Upload date:
  • Size: 433.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pyetm-2.0.0b7.tar.gz
Algorithm Hash digest
SHA256 68389bfaafef828948fd1557ce3e9b500d36f757d15978f25897dabf19f7382c
MD5 787eb3027a0b2c8d96d2890a26e690ca
BLAKE2b-256 4e92300dee37e1509f3ea6ddc430cabad13384714d07be666cb8fc95f1bce1e6

See more details on using hashes here.

File details

Details for the file pyetm-2.0.0b7-py3-none-any.whl.

File metadata

  • Download URL: pyetm-2.0.0b7-py3-none-any.whl
  • Upload date:
  • Size: 126.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pyetm-2.0.0b7-py3-none-any.whl
Algorithm Hash digest
SHA256 66c79b309f50bb464a0743105a6e315a33c4fa34e7d6e9b3928e75c8b4ed7c33
MD5 15ffe816152edb67978f1240227b7d5a
BLAKE2b-256 5f57eb681f26b711b046f5b609c9d287c9945e313c3daa6772342220e64568d1

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