Skip to content

Config

NoFallback (Exception)

No fallback value can be found.

ServerConfig (BaseSettings) pydantic-model

This class stores server config parameters in a way that can be easily extended for new config file types.

aliases: Dict[Literal['links', 'references', 'structures'], Dict[str, str]] pydantic-field

A mapping between field names in the database with their corresponding OPTIMADE field names, broken down by endpoint.

base_url: str pydantic-field

Base URL for this implementation

config_file: str pydantic-field

File to load alternative defaults from

debug: bool pydantic-field

Turns on Debug Mode for the OPTIMADE Server implementation

default_db: str pydantic-field

ID of /links endpoint resource for the chosen default OPTIMADE implementation (only relevant for the index meta-database)

implementation: Implementation pydantic-field

Introspective information about this OPTIMADE implementation

Absolute path to a JSON file containing the MongoDB collection of /links resources for the index meta-database

length_aliases: Dict[Literal['links', 'references', 'structures'], Dict[str, str]] pydantic-field

A mapping between a list property (or otherwise) and an integer property that defines the length of that list, for example elements -> nelements. The standard aliases are applied first, so this dictionary must refer to the API fields, not the database fields.

Mongo collection name for /links endpoint resources

mongo_database: str pydantic-field

Mongo database for collection data

mongo_uri: str pydantic-field

URI for the Mongo server

page_limit: int pydantic-field

Default number of resources per page

page_limit_max: int pydantic-field

Max allowed number of resources per page

provider: Provider pydantic-field

General information about the provider of this OPTIMADE implementation

provider_fields: Dict[Literal['links', 'references', 'structures'], List[str]] pydantic-field

A list of additional fields to be served with the provider's prefix attached, broken down by endpoint.

references_collection: str pydantic-field

Mongo collection name for /references endpoint resources

structures_collection: str pydantic-field

Mongo collection name for /structures endpoint resources

use_real_mongo: bool pydantic-field

Use a real Mongo server rather than MongoMock

load_default_settings(values) classmethod

Loads settings from a root file if available and uses that as defaults in place of built in defaults

Source code in optimade/server/config.py
@root_validator(pre=True)
def load_default_settings(cls, values):  # pylint: disable=no-self-argument
    """
    Loads settings from a root file if available and uses that as defaults in
    place of built in defaults
    """
    config_file_path = Path(values.get("config_file", DEFAULT_CONFIG_FILE_PATH))

    new_values = {}

    if config_file_path.exists() and config_file_path.is_file():
        logger.debug("Found config file at: %s", config_file_path)
        with open(config_file_path) as f:
            new_values = json.load(f)
    else:
        logger.debug(  # pragma: no cover
            "Did not find config file at: %s", config_file_path
        )

    new_values.update(values)

    return new_values