Skip to content

Commit 4e826e8

Browse files
committed
Packer tests, updated format, .env
* Updated tests * Added fetching a scenario directly in the Jupyter notebook to the example * Convert from yml settings to .env * Separated inputs and outputs into their own folders at root
1 parent e2d9488 commit 4e826e8

25 files changed

+3263
-199
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ import_graph.svg
1818
tmp/
1919

2020
*.xlsx
21-
# Keep the example input
22-
!examples/example_input_excel.xlsx
21+
# Keep the examples
22+
!inputs/example_input_excel.xlsx
23+
!examples/example.config.env

README.md

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ If you want development dependencies (testing, linting, etc.) then append the
8080

8181
#### How to use the environment:
8282
You can either:
83-
- Run commands inside Poetrys environment:
83+
- Run commands inside Poetry's environment:
8484
```bash
8585
poetry run pytest
8686
poetry run pyetm
@@ -97,25 +97,40 @@ You can either:
9797

9898
## Configuring Your Settings
9999

100-
You can configure your API token and base URL either with a **config.yml** file or environment variables. You can now simply set an `environment` and the base URL will be inferred for you.
100+
You can configure your API token and base URL either with a **config.env** file or environment variables. You can simply set an `environment` and the base URL will be inferred for you.
101101

102-
### Option 1: `config.yml`
103-
1. Duplicate the example file (`examples/example.config.yml`) and rename it to `config.yml`.
104-
2. Edit `config.yml`:
105-
- **etm_api_token**: Your ETM API token (overridden by `$ETM_API_TOKEN` if set).
106-
- **environment**: pro (default), beta, local, or a stable tag like `2025-01`. When set, `base_url` is inferred automatically.
107-
- (optional) **base_url**: API base URL (overridden by `$BASE_URL` if set). If both `environment` and `base_url` are set, `base_url` wins.
108-
Examples if you need a direct override:
109-
- `https://engine.energytransitionmodel.com/api/v3` (pro)
110-
- `https://beta.engine.energytransitionmodel.com/api/v3` (beta)
111-
- `https://2025-01.engine.energytransitionmodel.com/api/v3` (stable tag)
112-
- **proxy_servers**: (Optional) HTTP/HTTPS proxy URLs.
113-
- **csv_separator** and **decimal_separator**: Defaults are `,` and `.`.
102+
### Option 1: `config.env` (Recommended)
103+
1. Copy the example file (`example.config.env`) and rename it to `config.env`.
104+
2. Edit `config.env`:
105+
```bash
106+
# Your ETM API token (required)
107+
ETM_API_TOKEN=your.token.here
114108

115-
Place `config.yml` in the project root (`pyetm/` folder).
109+
# Environment (default: pro)
110+
ENVIRONMENT=pro
111+
112+
# Optional: Override base URL directly
113+
# BASE_URL=https://engine.energytransitionmodel.com/api/v3
114+
115+
# Optional: Proxy settings
116+
# PROXY_SERVERS_HTTP=http://user:[email protected]:8080
117+
# PROXY_SERVERS_HTTPS=http://user:[email protected]:8080
118+
119+
# CSV settings (optional)
120+
CSV_SEPARATOR=,
121+
DECIMAL_SEPARATOR=.
122+
```
123+
124+
Place `config.env` in the project root (`pyetm/` folder).
125+
126+
**Environment Options:**
127+
- `pro` (default): Production environment
128+
- `beta`: Staging environment
129+
- `local`: Local development environment
130+
- `YYYY-MM`: Stable tagged environment (e.g., `2025-01`)
116131

117132
### Option 2: Environment Variables
118-
If you prefer, set these environment variables:
133+
If you prefer, set these environment variables directly:
119134
```bash
120135
ETM_API_TOKEN=<your token>
121136
ENVIRONMENT=<pro|beta|local|YYYY-MM>

examples/create_or_query_scenarios.ipynb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
"id": "2884d014",
2828
"metadata": {},
2929
"source": [
30-
"For the purposes of this demonstration workbook, we will use the pre-filled template 'my_input_excel.xlsx' which demonstrates a few of the possibilities afforded by the pyetm package. If it's your first time using the tool, have a look at the excel to get a sense of the structure.\n",
30+
"For the purposes of this demonstration workbook, we will use the pre-filled template 'example_input_excel.xlsx' which demonstrates a few of the possibilities afforded by the pyetm package. If it's your first time using the tool, have a look at the excel to get a sense of the structure. The input excel is available in the /inputs folder. In pyetm, by default files will be read from the /inputs folder and written to the /outputs folder.\n",
3131
"\n",
3232
"In the example, there are two scenarios, with short names scen_a and scen_b. You can use short names in the slider_settings sheet to specify which inputs belong to which scenario. Because scen_b has no scenario_id, it is being created. It will be created with all the metadata included in the sheet, plus any of the inputs under the column with its short_name and any sortables and curves specified in the sheets named beside the sortables and custom_curves rows. The same goes for scen_a, but because it has a scenario_id (1357395) that scenario will be loaded, and then updated with anything as set in the excel.\n",
3333
"\n",
34-
"**TODO**: Figure out how to manage the fact that for this example whatever scenario 1357395 is will be constantly updated etc by everyone who wants to try running this script on pro/beta. At the moment its just a local scenario."
34+
"The example scenario ids are scenarios on pro. It's recommended to change the scenario_ids in the example and experiment with scenarios you own."
3535
]
3636
},
3737
{
@@ -42,9 +42,14 @@
4242
"outputs": [],
4343
"source": [
4444
"from pyetm.models.scenarios import Scenarios\n",
45+
"from pyetm.models.scenario import Scenario\n",
46+
"\n",
4547
"\n",
4648
"scenarios = Scenarios.from_excel(\"example_input_excel.xlsx\")\n",
47-
"#scenario_a = Scenario.load(123456789) #TODO: Also load a scenario and include it in the array"
49+
"\n",
50+
"# Here we're also loading a scenario directly from the API and adding it to the scenarios loaded/created via the excel\n",
51+
"scenario_a = Scenario.load(1357691)\n",
52+
"scenarios.add(scenario_a)"
4853
]
4954
},
5055
{
@@ -84,7 +89,7 @@
8489
"source": [
8590
"# Inputs\n",
8691
"for scenario in scenarios:\n",
87-
" inputs = scenario.inputs.to_dataframe(columns=[\"user\", \"default\", \"min\", \"max\"]).head(20)\n",
92+
" inputs = scenario.inputs.to_dataframe(columns=[\"user\", \"default\", \"min\", \"max\"]).head(15)\n",
8893
" print(inputs)\n",
8994
" print(\"\")"
9095
]

examples/example.config.env

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# ETM API Configuration
2+
# Copy this file to .env and update with your personal settings
3+
# Never commit your .env file to version control!
4+
5+
# Your personal ETM API Token (REQUIRED)
6+
# Get your token from: https://docs.energytransitionmodel.com/api/authentication
7+
# Format: etm_<JWT> or etm_beta_<JWT>
8+
ETM_API_TOKEN=your.token.here
9+
10+
# ETM Environment (default: pro)
11+
# Options: pro, beta, local, or stable tags like 2025-01
12+
ENVIRONMENT=pro
13+
14+
# Override API base URL (optional - will be inferred from ENVIRONMENT if not set)
15+
# Examples:
16+
# BASE_URL=https://engine.energytransitionmodel.com/api/v3
17+
# BASE_URL=https://beta.engine.energytransitionmodel.com/api/v3
18+
# BASE_URL=http://localhost:3000/api/v3
19+
# BASE_URL=https://2025-01.engine.energytransitionmodel.com/api/v3
20+
# BASE_URL=
21+
22+
# Logging level (default: INFO)
23+
# Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
24+
LOG_LEVEL=INFO
25+
26+
# Proxy Settings (optional)
27+
# Never commit authenticated proxy URLs to version control!
28+
# PROXY_SERVERS_HTTP=http://user:[email protected]:8080
29+
# PROXY_SERVERS_HTTPS=http://user:[email protected]:8080
30+
31+
# CSV File Settings
32+
# CSV separator character (default: ,)
33+
CSV_SEPARATOR=,
34+
35+
# Decimal separator character (default: .)
36+
DECIMAL_SEPARATOR=.

examples/example.config.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.
File renamed without changes.

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,43 @@
22
requires = ["poetry-core>=1.0.0"]
33
build-backend = "poetry.core.masonry.api"
44

5-
[tool.poetry]
5+
6+
[project]
67
name = "pyetm"
78
version = "2.0"
8-
description = "A Python package for energy transition modeling."
9-
authors = ["Your Name <[email protected]>"]
10-
license = "MIT"
9+
description = "Python-ETM Connector"
1110
readme = "README.md"
12-
homepage = "https://github.com/quintel/pyetm"
13-
repository = "https://github.com/quintel/pyetm"
14-
documentation = "https://docs.energytransitionmodel.com/main/pyetm/introduction"
15-
keywords = ["energy", "transition", "modeling", "api"]
11+
license = { text = "MIT" }
12+
authors = [
13+
{ name = "Nora Schinkel", email = "[email protected]" },
14+
{ name = "Louis Parkes-Talbo", email = "[email protected]" }
15+
]
16+
keywords = ["energy", "transition", "modeling", "api", "ETM"]
17+
requires-python = ">=3.12,<4.0"
18+
19+
dependencies = [
20+
"pydantic",
21+
"pandas",
22+
"requests",
23+
"python-dotenv",
24+
"pyyaml",
25+
"pydantic-settings",
26+
"xlsxwriter",
27+
"openpyxl"
28+
]
29+
30+
[project.scripts]
31+
pyetm = "pyetm.__main__:main"
32+
33+
[project.urls]
34+
"Repository" = "https://github.com/quintel/pyetm"
35+
"Documentation" = "https://docs.energytransitionmodel.com/main/pyetm/introduction"
36+
"Issue tracker" = "https://github.com/quintel/pyetm/issues"
37+
38+
[tool.poetry]
1639
packages = [{ include = "pyetm", from = "src" }]
40+
include = ["LICENSE"]
1741

18-
[tool.poetry.dependencies]
19-
python = ">=3.12,<4.0"
20-
pydantic = "*"
21-
pandas = "*"
22-
requests = "*"
23-
python-dotenv = "*"
24-
pyyaml = "*"
25-
pydantic-settings = "*"
26-
xlsxwriter = "*"
27-
openpyxl = "*"
2842

2943
[tool.poetry.group.dev.dependencies]
3044
pytest = "*"
@@ -35,12 +49,7 @@ notebook = "*"
3549
pytest-cov = "*"
3650
pydeps = "*"
3751

38-
[tool.poetry.scripts]
39-
pyetm = "pyetm.__main__:main"
4052

41-
[tool.poetry.urls]
42-
"Issue tracker" = "https://github.com/quintel/pyetm/issues"
43-
"Documentation" = "https://docs.energytransitionmodel.com/main/pyetm/introduction"
4453

4554
[tool.pytest.ini_options]
4655
addopts = "--cov=pyetm --cov-report=term-missing"

0 commit comments

Comments
 (0)