config¶
LogLevel (Enum)
¶
Replication of logging LogLevels
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
index_base_url: AnyHttpUrl
pydantic-field
¶
An optional link to the base URL for the index meta-database of the provider.
index_links_path: Path
pydantic-field
¶
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.
links_collection: str
pydantic-field
¶
Mongo collection name for /links endpoint resources
log_dir: Path
pydantic-field
¶
Folder in which log files will be saved.
log_level: LogLevel
pydantic-field
¶
Logging level for the OPTIMADE server.
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
root_path: str
pydantic-field
¶
Sets the FastAPI app root_path
parameter. This can be used to serve the API under a path prefix behind a proxy or as a sub-application of another FastAPI app. See https://fastapi.tiangolo.com/advanced/sub-applications/#technical-details-root_path for details.
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
Config
¶
This is a pydantic model Config object that modifies the behaviour of ServerConfig by adding a prefix to the environment variables that override config file values. It has nothing to do with the OPTIMADE config.
load_settings(values)
classmethod
¶
Loads settings from a JSON config file, if available, and uses them in place of the built-in defaults.
Source code in optimade/server/config.py
@root_validator(pre=True)
def load_settings(cls, values):
"""
Loads settings from a JSON config file, if available, and uses them in place
of the built-in defaults.
"""
config_file_path = Path(values.get("config_file", DEFAULT_CONFIG_FILE_PATH))
new_values = {}
if config_file_path.is_file():
try:
with open(config_file_path) as f:
new_values = json.load(f)
except json.JSONDecodeError as exc:
warnings.warn(
f"Unable to parse config file {config_file_path} as JSON. Error: {exc}."
)
else:
if DEFAULT_CONFIG_FILE_PATH != str(config_file_path):
warnings.warn(
f"Unable to find config file in requested location {config_file_path}, "
"using the built-in default settings instead."
)
else:
warnings.warn(
f"Unable to find config file in default location {DEFAULT_CONFIG_FILE_PATH}, "
"using the built-in default settings instead."
)
if not new_values:
values["config_file"] = None
new_values.update(values)
return new_values
set_implementation_version(v)
classmethod
¶
Set defaults and modify bypassed value(s)
Source code in optimade/server/config.py
@validator("implementation", pre=True)
def set_implementation_version(cls, v):
"""Set defaults and modify bypassed value(s)"""
res = {"version": __version__}
res.update(v)
return res