Platform

class ixmp4.core.platform.Platform(name_or_connection: str | Transport | Backend, settings: Settings | None = None)

A modeling platform instance as a connection to a data backend. Enables the manipulation of data via the Facade instances.

To instantiate a new platform, provide a name which will be used to first search the local ‘platforms.toml’ file and then the ECE Manager API.

import ixmp4

platform = ixmp4.Platform("<name>")

You may override the settings the platform uses …

from ixmp4.conf.settings import Settings

platform = ixmp4.Platform("<name>", settings=Settings(manager_url="https://.../"))

…and provide a Backend or Transport class directly.

from ixmp4.transport import DirectTransport
from ixmp4.data.backend import Backend

platform = ixmp4.Platform(Backend(...))
# or
platform = ixmp4.Platform(DirectTransport.from_dsn(...))

Once created, the platform’s Facade attributes can be used to manipulate data:

Attribute

Service Facade Class

Object Facade Class

runs

RunServiceFacade

Run

meta

PlatformRunMetaFacade

RunMetaDescriptor/ RunMetaDictFacade

iamc

PlatformIamcData

RunIamcData

models

ModelServiceFacade

Model

scenarios

ScenarioServiceFacade

Scenario

regions

RegionServiceFacade

Region

units

UnitServiceFacade

Unit

NotFound

alias of PlatformNotFound

NotUnique

alias of PlatformNotUnique

settings: Settings

The settings object the platform is using.

backend: Backend

Central data layer object that is composed of services.

runs: RunServiceFacade

Facade instance to manage Run instances for a platform.

iamc: PlatformIamcData

Facade instance to query IAMC data globally for a platform.

models: ModelServiceFacade

Facade instance to manage Model instances for a platform.

regions: RegionServiceFacade

Facade instance to manage Region instances for a platform.

scenarios: ScenarioServiceFacade

Facade instance to manage Scenario instances for a platform.

units: UnitServiceFacade

Facade instance to manage Unit instances for a platform.

meta: PlatformRunMetaFacade

Facade instance to query run meta indicators globally for a platform.

init_backend(name: str) Backend

Resolve a platform name to a Backend.

Looks up the platform connection info first in the local platforms.toml file, then in the ECE Manager API, and initialises the appropriate Transport.

Parameters:

name (str) – The name of the platform to look up.

Returns:

A fully initialised backend for the resolved platform.

Return type:

Backend

Raises:

PlatformNotFound – If name cannot be found in either source.

get_transport(ci: PlatformConnectionInfo, http_credentials: str = 'default') HttpxTransport | DirectTransport

Instantiate the correct transport for the given connection info.

For HTTP-based DSNs an HttpxTransport is returned. For other DSNs (e.g. SQLite) a DirectTransport is attempted first; if that fails and ci.url is available the method transparently falls back to an HttpxTransport.

Parameters:
  • ci (PlatformConnectionInfo) – Connection details for the platform.

  • http_credentials (str, optional) – Key used to look up HTTP credentials from the settings. Defaults to "default".

Returns:

The transport instance to use for this platform.

Return type:

HttpxTransport or DirectTransport

Raises:

ServiceException, Ixmp4Error, SQLAlchemyError, ImportError – Re-raised if the direct connection fails and no HTTP fallback URL is configured.

get_toml_platform_ci(name: str) PlatformConnectionInfo | None

Look up platform connection info in the local TOML configuration.

get_manager_platform_ci(name: str) PlatformConnectionInfo | None

Look up platform connection info via the ECE Manager API.