collection
collection
Collection model for ETM collection management.
Classes
CollectionError
Bases: Exception
Base collection error
Collection
Bases: Base
Pydantic model for a MyETM Collection (transition path).
A Collection groups multiple scenarios together, optionally with interpolation for multi-year projections.
Source code in src/pyetm/models/base.py
Functions
create
classmethod
create(title, scenario_ids=None, saved_scenario_ids=None, area_code=None, end_year=None, interpolation=False, client=None, **kwargs)
Create a new Collection in MyETM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title for the collection (required) |
required |
scenario_ids
|
Optional[List[int]]
|
List of ETEngine scenario IDs to include |
None
|
saved_scenario_ids
|
Optional[List[int]]
|
List of MyETM saved scenario IDs to include |
None
|
area_code
|
Optional[str]
|
Area code for interpolated collections |
None
|
end_year
|
Optional[int]
|
End year for interpolated collections |
None
|
interpolation
|
bool
|
Whether this is an interpolated collection |
False
|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
**kwargs
|
Any
|
Additional collection parameters |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Collection |
'Collection'
|
The created collection |
Raises:
| Type | Description |
|---|---|
CollectionError
|
If creation fails |
Example
collection = Collection.create( title="My Collection", saved_scenario_ids=[1, 2, 3], interpolation=False )
Source code in src/pyetm/models/collection.py
load
classmethod
Load a Collection from MyETM by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
collection_id
|
int
|
ID of the collection to load |
required |
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Collection |
'Collection'
|
The loaded collection |
Raises:
| Type | Description |
|---|---|
CollectionError
|
If collection not found or loading fails |
Example
collection = Collection.load(123) print(f"Collection: {collection.title}")
Source code in src/pyetm/models/collection.py
load_all
classmethod
Load all collections for the authenticated user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
Returns:
| Type | Description |
|---|---|
List['Collection']
|
List[Collection]: List of all user's collections |
Raises:
| Type | Description |
|---|---|
CollectionError
|
If loading fails |
Example
collections = Collection.load_all() for collection in collections: print(f"{collection.id}: {collection.title}")
Source code in src/pyetm/models/collection.py
update
Update this Collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
**kwargs
|
Any
|
Fields to update (title, area_code, end_year, interpolation, discarded, scenario_ids, saved_scenario_ids) |
{}
|
Raises:
| Type | Description |
|---|---|
CollectionError
|
If update fails |
Example
collection = Collection.load(123) collection.update(title="Updated Title", saved_scenario_ids=[1, 2, 3, 4])
Source code in src/pyetm/models/collection.py
delete
Permanently delete this Collection from MyETM (hard delete).
WARNING: This is a PERMANENT deletion and CANNOT be undone. The collection will be permanently removed from MyETM.
NOTE: SavedScenarios within the collection are NOT deleted. Only the collection itself is removed. The scenarios will remain in MyETM and can still be accessed individually.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Optional[BaseClient]
|
Optional BaseClient instance |
None
|
Raises:
| Type | Description |
|---|---|
CollectionError
|
If deletion fails |
Example
collection = Collection.load(123) collection.delete() # PERMANENT deletion - cannot be recovered
Source code in src/pyetm/models/collection.py
to_dict
Convert collection to dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Dictionary representation of the collection |