Skip to content

academy.exchange.cloud.config

Cloud exchange configuration file parsing.

ExchangeAuthConfig pydantic-model

Bases: BaseModel

Exchange authentication configuration.

Attributes:

  • method (Optional[Literal['globus']]) –

    Authentication method.

  • kwargs (Dict[str, Any]) –

    Arbitrary keyword arguments to pass to the authenticator. The kwargs are excluded from the repr() of this class because they often contain secrets.

Config:

  • extra: forbid

Fields:

ExchangeServingConfig pydantic-model

Bases: BaseModel

Exchange serving configuration.

Attributes:

  • host (str) –

    Network interface the server binds to.

  • port (int) –

    Network port the server binds to.

  • certfile (Optional[str]) –

    Certificate file (PEM format) use to enable TLS.

  • keyfile (Optional[str]) –

    Private key file. If not specified, the key will be taken from the certfile.

  • auth (ExchangeAuthConfig) –

    Authentication configuration.

  • log_file (Optional[str]) –

    Location to write logs.

  • log_level (Union[int, str]) –

    Verbosity of logs.

Fields:

from_toml classmethod

from_toml(filepath: str | Path) -> Self

Parse an TOML config file.

Example

Minimal config without SSL and without authentication.

exchange.toml
port = 8700

from academy.exchange.cloud.config import ExchangeServingConfig

config = ExchangeServingConfig.from_toml('exchange.toml')
Example

Serve with SSL and Globus Auth.

relay.toml
host = "0.0.0.0"
port = 8700
certfile = "/path/to/cert.pem"
keyfile = "/path/to/privkey.pem"

[auth]
method = "globus"

[auth.kwargs]
client_id = "..."
client_secret = "..."

Note

Omitted values will be set to their defaults (if they are an optional value with a default).

relay.toml
[serving]
certfile = "/path/to/cert.pem"

from academy.exchange.cloud.config import ExchangeServingConfig

config = ExchangeServingConfig.from_config('relay.toml')
assert config.certfile == '/path/to/cert.pem'
assert config.keyfile is None
Source code in academy/exchange/cloud/config.py
@classmethod
def from_toml(cls, filepath: str | pathlib.Path) -> Self:
    """Parse an TOML config file.

    Example:
        Minimal config without SSL and without authentication.
        ```toml title="exchange.toml"
        port = 8700
        ```

        ```python
        from academy.exchange.cloud.config import ExchangeServingConfig

        config = ExchangeServingConfig.from_toml('exchange.toml')
        ```

    Example:
        Serve with SSL and Globus Auth.
        ```toml title="relay.toml"
        host = "0.0.0.0"
        port = 8700
        certfile = "/path/to/cert.pem"
        keyfile = "/path/to/privkey.pem"

        [auth]
        method = "globus"

        [auth.kwargs]
        client_id = "..."
        client_secret = "..."
        ```

    Note:
        Omitted values will be set to their defaults (if they are an
        optional value with a default).
        ```toml title="relay.toml"
        [serving]
        certfile = "/path/to/cert.pem"
        ```

        ```python
        from academy.exchange.cloud.config import ExchangeServingConfig

        config = ExchangeServingConfig.from_config('relay.toml')
        assert config.certfile == '/path/to/cert.pem'
        assert config.keyfile is None
        ```
    """
    with open(filepath, 'rb') as f:
        return load(cls, f)

load

load(model: type[BaseModelT], fp: BinaryIO) -> BaseModelT

Parse TOML from a binary file to a data class.

Parameters:

  • model (type[BaseModelT]) –

    Config model type to parse TOML using.

  • fp (BinaryIO) –

    File-like bytes stream to read in.

Returns:

  • BaseModelT

    Model initialized from TOML file.

Source code in academy/exchange/cloud/config.py
def load(model: type[BaseModelT], fp: BinaryIO) -> BaseModelT:
    """Parse TOML from a binary file to a data class.

    Args:
        model: Config model type to parse TOML using.
        fp: File-like bytes stream to read in.

    Returns:
        Model initialized from TOML file.
    """
    return loads(model, fp.read().decode())

loads

loads(model: type[BaseModelT], data: str) -> BaseModelT

Parse TOML string to data class.

Parameters:

  • model (type[BaseModelT]) –

    Config model type to parse TOML using.

  • data (str) –

    TOML string to parse.

Returns:

  • BaseModelT

    Model initialized from TOML file.

Source code in academy/exchange/cloud/config.py
def loads(model: type[BaseModelT], data: str) -> BaseModelT:
    """Parse TOML string to data class.

    Args:
        model: Config model type to parse TOML using.
        data: TOML string to parse.

    Returns:
        Model initialized from TOML file.
    """
    data_dict = tomllib.loads(data)
    return model.model_validate(data_dict, strict=True)