Python-ETM Connector
Project description
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:
- Windows: Download from python.org
- macOS: Install via Homebrew:
brew install python@3.12 - Linux: Use your package manager (e.g.,
apt install python3)
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
.envconfiguration 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, orlocal)--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:
- Click Kernel → Change kernel
- Select Python (pyetm)
Using VS Code
If you prefer VS Code:
- Install the Python and Jupyter extensions
- Open a
.ipynbfile - Click Select Kernel at the top right
- 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 environmentbeta: Staging environmentlocal: Local development environmentYYYY-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
- Documentation: docs.energytransitionmodel.com
- Issues: GitHub Issues
- Repository: github.com/quintel/pyetm
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyetm-2.0.0b8.post1.tar.gz.
File metadata
- Download URL: pyetm-2.0.0b8.post1.tar.gz
- Upload date:
- Size: 434.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c20fc96c3c39f2382551e3948d68b0f88a33d8ed08dc7ec94c90467674e9d15d
|
|
| MD5 |
25920f89aef783b90509e961fddd0f2c
|
|
| BLAKE2b-256 |
cc73b14a525020798156a340c41d945772e4956289ac506a21cb00b702faffdb
|
File details
Details for the file pyetm-2.0.0b8.post1-py3-none-any.whl.
File metadata
- Download URL: pyetm-2.0.0b8.post1-py3-none-any.whl
- Upload date:
- Size: 474.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9e8faa62fce6d6c336030035b56d3fb26fa234af92ba4ab3dedc4528720a17f
|
|
| MD5 |
d79f70e2151eeee9dd436ee0fe6b1343
|
|
| BLAKE2b-256 |
3c156bd6c8e3b7d518608c047c6bc9a0e82b7c9c8e68645bf9ed7a8c2ca77c28
|