|
1 | 1 | # pyetm
|
2 | 2 |
|
3 |
| -This package provides a set of tools for interaction with the Energy Transition Model's API. Learn more |
4 |
| -about the Energy Transition Model [here](https://energytransitionmodel.com/). The |
5 |
| -package is designed to be a modular tool that advanced users can incorporate into their workflows. The |
6 |
| -complete documentation is available [via the ETM documentation page](https://docs.energytransitionmodel.com/main/pyetm/introduction). |
| 3 | +This package provides a set of tools for interaction with the Energy Transition Model's API. |
| 4 | +Learn more about the Energy Transition Model [here](https://energytransitionmodel.com/). |
| 5 | + |
| 6 | +The package is designed to be a modular tool that advanced users can incorporate into their scenario workflows. |
| 7 | +The complete documentation is available [via the ETM documentation page](https://docs.energytransitionmodel.com/main/pyetm/introduction). |
| 8 | + |
| 9 | +--- |
7 | 10 |
|
8 | 11 | ## Installation
|
9 | 12 |
|
10 |
| -You can clone the pyetm from [our Github](https://github.com/quintel/pyetm). The package is also |
11 |
| -available via pip like any other python package - install it and use it in your project! |
12 |
| -``` |
| 13 | +You can install **pyetm** directly from PyPI: |
| 14 | +```bash |
13 | 15 | pip install pyetm
|
14 | 16 | ```
|
15 | 17 |
|
16 |
| -## Just running the Jupyter Notebooks - or a beginner friendly guide to PyETM |
17 |
| -If you are not planning on developing the tool, but would like to open and run our Jupyter notebooks |
18 |
| -in VS Code, follow the beginner friendly guide at [Running notebooks](running_notebooks.md). |
| 18 | +Or clone from [our GitHub repository](https://github.com/quintel/pyetm) if you want the latest development version: |
| 19 | +```bash |
| 20 | +git clone https://github.com/quintel/pyetm.git |
| 21 | +cd pyetm |
| 22 | +``` |
19 | 23 |
|
20 |
| -## Getting started |
21 |
| -Make sure you have [Python 3](https://www.python.org/downloads/) installed. Then, install all required |
22 |
| -libraries by opening a terminal/command-prompt window in the `pyetm` folder (or navigate to this folder |
23 |
| -in the terminal using `cd "path/to/scenario-tools-folder"`). All following examples of running the tool |
24 |
| -expect you to be in this folder. |
| 24 | +--- |
25 | 25 |
|
26 |
| -#### Using pipenv |
27 |
| -It is recommended (but not required) that you use [`pipenv`](https://pipenv.pypa.io/en/latest/) for |
28 |
| -running these tools. When using `pipenv` it will create a virtual environment for you. A virtual |
29 |
| -environment helps with keeping the libraries you install here separate of your global libraries (in |
30 |
| -other words your `pyetm` will be in a stable and isolated environment and are thus less |
31 |
| -likely to break when updating things elsewhere on your computer). |
| 26 | +## Running Jupyter Notebooks (Beginner Friendly) |
32 | 27 |
|
33 |
| -You can install `pipenv` with `pip` or `pip3` if you don't have it installed yet. |
34 |
| -``` |
35 |
| -pip3 install pipenv |
36 |
| -``` |
| 28 | +If you only want to open and run our Jupyter notebooks in VS Code without developing the package, |
| 29 | +follow the beginner guide here: [Running notebooks](running_notebooks.md). |
37 | 30 |
|
38 |
| -Then you can create a new environment and install all the libraries in one go by running: |
39 |
| -``` |
40 |
| -pipenv install |
41 |
| -``` |
| 31 | +--- |
42 | 32 |
|
43 |
| -If you plan to develop with the tool, install the dev dependencies too: |
44 |
| -``` |
45 |
| -pipenv install --dev |
| 33 | +## Development Setup (Using Poetry) |
| 34 | + |
| 35 | +We recommend using [Poetry](https://python-poetry.org/) to manage dependencies and virtual environments. |
| 36 | +Poetry ensures all dependencies are installed in an isolated environment, keeping your system clean. |
| 37 | + |
| 38 | +### Python |
| 39 | +Make sure you have **Python 3.12** or later installed: |
| 40 | +- **Windows**: [Download from python.org](https://www.python.org/downloads/windows/) |
| 41 | +- **macOS**: Install via [Homebrew](https://brew.sh/) |
| 42 | + ```bash |
| 43 | + brew install python@3.12 |
| 44 | + ``` |
| 45 | +- **Linux**: Use your package manager or install from source. |
| 46 | + |
| 47 | +Check your version: |
| 48 | +```bash |
| 49 | +python3 --version |
46 | 50 | ```
|
47 | 51 |
|
48 |
| -#### Configuring your settings |
| 52 | +--- |
49 | 53 |
|
50 |
| -You can set your API token and the base url for your requests (depending which |
51 |
| -[environment](https://docs.energytransitionmodel.com/api/intro#environments) you want to interact with) |
52 |
| -either directly in the ENV or via a config.yml file. |
| 54 | +### Poetry |
| 55 | +Follow the [official instructions](https://python-poetry.org/docs/#installation): |
53 | 56 |
|
54 |
| -##### config.yml |
55 |
| -pyetm uses a `config.yml` file in the project root to store your personal settings: |
| 57 | +```bash |
| 58 | +curl -sSL https://install.python-poetry.org | python3 - |
| 59 | +``` |
56 | 60 |
|
57 |
| -1. Duplicate the example file provided (`examples/config.example.yml`) and rename it to `config.yml`. |
58 |
| -2. Open `config.yml` and fill in your values: |
59 |
| - - **etm_api_token**: Your personal ETM API token (overridden by the `$ETM_API_TOKEN` environment variable if set). |
60 |
| - - **base_url**: The API base URL for the target environment (overridden by the `$BASE_URL` environment |
61 |
| - variable if set) e.g., default pro, a stable engine at `https://2025-01.engine.energytransitionmodel.com/api/v3`, |
62 |
| - or beta at `https://beta.engine.energytransitionmodel.com/api/v3`. |
63 |
| - - **local_engine_url** and **local_model_url**: URLs for a local ETM instance, if running locally. |
64 |
| - - **proxy_servers**: (Optional) HTTP/HTTPS proxy URLs, if required by your network. |
65 |
| - - **csv_separator** and **decimal_separator**: Defaults are `,` and `.`; adjust if your CSV exports |
66 |
| - use different separators. |
| 61 | +After installation, ensure Poetry is available: |
| 62 | +```bash |
| 63 | +poetry --version |
| 64 | +``` |
67 | 65 |
|
68 |
| -Your `config.yml` should reside in the root `pyetm/` folder. |
69 | 66 |
|
70 |
| -##### ENV variables |
71 |
| -If you use pyetm as a package, you may want to set your ENV variables using a custom flow. In that |
72 |
| -case, the variables you need to set are: |
| 67 | +#### Install Dependencies |
73 | 68 |
|
74 |
| - $ETM_API_TOKEN - Your api token (specific to the environment you are interacting with) |
75 |
| - $BASE_URL - The base url of the environment you are interacting with. |
76 |
| - $LOCAL_ENGINE_URL - The local url of the engine if running locally. |
77 |
| - $LOCAL_MODEL_URL - The local url of the model if running locally. |
| 69 | +Navigate to the `pyetm` folder and install all dependencies: |
| 70 | +```bash |
| 71 | +cd pyetm |
| 72 | +poetry install |
| 73 | +``` |
78 | 74 |
|
| 75 | +This will: |
| 76 | +- Create a virtual environment |
| 77 | +- Install runtime dependencies |
| 78 | +If you want development dependencies (testing, linting, etc.) then append the |
| 79 | +"--with dev" flag to the install command. |
| 80 | + |
| 81 | + |
| 82 | +#### Activating the Environment |
| 83 | +You can either: |
| 84 | +- Run commands inside Poetry’s environment: |
| 85 | + ```bash |
| 86 | + poetry run pytest |
| 87 | + poetry run pyetm |
| 88 | + ``` |
| 89 | +- Or activate the shell: |
| 90 | + ```bash |
| 91 | + eval $(poetry env activate) |
| 92 | + ``` |
| 93 | + Then run commands normally: |
| 94 | + ```bash |
| 95 | + pytest |
| 96 | + pyetm |
| 97 | + ``` |
| 98 | + |
| 99 | + |
| 100 | +## Configuring Your Settings |
| 101 | + |
| 102 | +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. |
| 103 | + |
| 104 | +### Option 1: `config.yml` |
| 105 | +1. Duplicate the example file (`examples/example.config.yml`) and rename it to `config.yml`. |
| 106 | +2. Edit `config.yml`: |
| 107 | + - **etm_api_token**: Your ETM API token (overridden by `$ETM_API_TOKEN` if set). |
| 108 | + - **environment**: pro (default), beta, local, or a stable tag like `2025-01`. When set, `base_url` is inferred automatically. |
| 109 | + - (optional) **base_url**: API base URL (overridden by `$BASE_URL` if set). If both `environment` and `base_url` are set, `base_url` wins. |
| 110 | + Examples if you need a direct override: |
| 111 | + - `https://engine.energytransitionmodel.com/api/v3` (pro) |
| 112 | + - `https://beta.engine.energytransitionmodel.com/api/v3` (beta) |
| 113 | + - `https://2025-01.engine.energytransitionmodel.com/api/v3` (stable tag) |
| 114 | + - **proxy_servers**: (Optional) HTTP/HTTPS proxy URLs. |
| 115 | + - **csv_separator** and **decimal_separator**: Defaults are `,` and `.`. |
| 116 | + |
| 117 | +Place `config.yml` in the project root (`pyetm/` folder). |
| 118 | + |
| 119 | +### Option 2: Environment Variables |
| 120 | +If you prefer, set these environment variables: |
| 121 | +```bash |
| 122 | +ETM_API_TOKEN=<your token> |
| 123 | +ENVIRONMENT=<pro|beta|local|YYYY-MM> |
| 124 | +# or provide a direct override instead of ENVIRONMENT |
| 125 | +BASE_URL=<api url> |
| 126 | +``` |
79 | 127 |
|
80 |
| -#TODO - check links |
| 128 | +--- |
| 129 | + |
| 130 | +## Cross-Platform Notes |
| 131 | +- **Windows**: |
| 132 | + - Use `py` instead of `python3` if `python3` is not recognized. |
| 133 | + - In PowerShell, set environment variables with: |
| 134 | + ```powershell |
| 135 | + $env:ETM_API_TOKEN="your-token" |
| 136 | + ``` |
| 137 | +- **macOS/Linux**: |
| 138 | + - Use `python3` in commands. |
| 139 | + - Set environment variables with: |
| 140 | + ```bash |
| 141 | + export ETM_API_TOKEN="your-token" |
| 142 | + export ENVIRONMENT=beta # or pro/local/2025-01 |
| 143 | + ``` |
0 commit comments