config¶
CONFIG = ServerConfig()
module-attribute
¶
This singleton loads the config from a hierarchy of sources (see
customise_sources
)
and makes it importable in the server code.
DEFAULT_CONFIG_FILE_PATH = str(Path.home().joinpath('.optimade.json'))
module-attribute
¶
Default configuration file path.
This variable is used as the fallback value if the environment variable
OPTIMADE_CONFIG_FILE
is not set.
Note
It is set to: pathlib.Path.home()/.optimade.json
For Unix-based systems (Linux) this will be equivalent to ~/.optimade.json
.
ConfigFileSettingsSource
¶
Bases: PydanticBaseSettingsSource
Configuration file settings source.
Based on the example in the pydantic documentation, this class defines loading ServerConfig settings from a configuration file.
The file must be of either type JSON or YML/YAML.
Source code in optimade/server/config.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
|
__call__()
¶
Source code in optimade/server/config.py
138 139 |
|
get_field_value(field, field_name)
¶
Must be defined according to parent abstract class.
It does not make sense to use it for this class, since 'extra' is set to 'allow'. We will instead just parse and take every key/field specified in the config file.
Source code in optimade/server/config.py
82 83 84 85 86 87 88 89 90 91 |
|
parse_config_file()
¶
Parse the config file and return a dictionary of its content.
Source code in optimade/server/config.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
LogLevel
¶
Bases: Enum
Replication of logging LogLevels
notset
debug
info
warning
error
critical
Source code in optimade/server/config.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
CRITICAL = 'critical'
class-attribute
instance-attribute
¶
DEBUG = 'debug'
class-attribute
instance-attribute
¶
ERROR = 'error'
class-attribute
instance-attribute
¶
INFO = 'info'
class-attribute
instance-attribute
¶
NOTSET = 'notset'
class-attribute
instance-attribute
¶
WARNING = 'warning'
class-attribute
instance-attribute
¶
ServerConfig
¶
Bases: BaseSettings
This class stores server config parameters in a way that can be easily extended for new config file types.
Source code in optimade/server/config.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
aliases = {}
class-attribute
instance-attribute
¶
base_url = None
class-attribute
instance-attribute
¶
create_default_index = False
class-attribute
instance-attribute
¶
custom_landing_page = None
class-attribute
instance-attribute
¶
database_backend = SupportedBackend.MONGOMOCK
class-attribute
instance-attribute
¶
debug = False
class-attribute
instance-attribute
¶
default_db = 'test_server'
class-attribute
instance-attribute
¶
elastic_hosts = None
class-attribute
instance-attribute
¶
implementation = Implementation(name='OPTIMADE Python Tools', version=__version__, source_url='https://github.com/Materials-Consortia/optimade-python-tools', maintainer={'email': 'dev@optimade.org'}, issue_tracker='https://github.com/Materials-Consortia/optimade-python-tools/issues', homepage='https://optimade.org/optimade-python-tools')
class-attribute
instance-attribute
¶
index_base_url = None
class-attribute
instance-attribute
¶
index_links_path = Path(__file__).parent.joinpath('index_links.json')
class-attribute
instance-attribute
¶
index_schema_url = f'https://schemas.optimade.org/openapi/v{__api_version__}/optimade_index.json'
class-attribute
instance-attribute
¶
insert_from_jsonl = None
class-attribute
instance-attribute
¶
insert_test_data = True
class-attribute
instance-attribute
¶
is_index = False
class-attribute
instance-attribute
¶
length_aliases = {}
class-attribute
instance-attribute
¶
links_collection = 'links'
class-attribute
instance-attribute
¶
log_dir = Path('/var/log/optimade/')
class-attribute
instance-attribute
¶
log_level = LogLevel.INFO
class-attribute
instance-attribute
¶
model_config = SettingsConfigDict(env_prefix='optimade_', extra='allow', env_file_encoding='utf-8', case_sensitive=False)
class-attribute
instance-attribute
¶
mongo_count_timeout = 5
class-attribute
instance-attribute
¶
mongo_database = 'optimade'
class-attribute
instance-attribute
¶
mongo_uri = 'localhost:27017'
class-attribute
instance-attribute
¶
page_limit = 20
class-attribute
instance-attribute
¶
page_limit_max = 500
class-attribute
instance-attribute
¶
provider = Provider(prefix='exmpl', name='Example provider', description='Provider used for examples, not to be assigned to a real database', homepage='https://example.com')
class-attribute
instance-attribute
¶
provider_fields = {}
class-attribute
instance-attribute
¶
references_collection = 'references'
class-attribute
instance-attribute
¶
root_path = None
class-attribute
instance-attribute
¶
schema_url = f'https://schemas.optimade.org/openapi/v{__api_version__}/optimade.json'
class-attribute
instance-attribute
¶
structures_collection = 'structures'
class-attribute
instance-attribute
¶
use_real_mongo = None
class-attribute
instance-attribute
¶
validate_api_response = True
class-attribute
instance-attribute
¶
validate_query_parameters = True
class-attribute
instance-attribute
¶
align_mongo_uri_and_mongo_database()
¶
Prefer the value of database name if set from mongo_uri
rather than
mongo_database
.
Source code in optimade/server/config.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
check_jsonl_path(value)
classmethod
¶
Check that the path to the JSONL file is valid.
Source code in optimade/server/config.py
435 436 437 438 439 440 441 442 |
|
set_implementation_version(value)
classmethod
¶
Set defaults and modify bypassed value(s)
Source code in optimade/server/config.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
settings_customise_sources(settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings)
classmethod
¶
Priority of config settings sources:
- Passed arguments upon initialization of
ServerConfig
. - Environment variables, matching the syntax:
"OPTIMADE_"
or"optimade_"
+<config_name>
, e.g.,OPTIMADE_LOG_LEVEL=debug
oroptimade_log_dir=~/logs_dir/optimade/
. - Configuration file (JSON/YAML) taken from:
- Environment variable
OPTIMADE_CONFIG_FILE
. - Default location (see DEFAULT_CONFIG_FILE_PATH).
- Environment variable
- Settings from secret file (see pydantic documentation for more information).
Source code in optimade/server/config.py
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
use_real_mongo_override()
¶
Overrides the database_backend
setting with MongoDB and
raises a deprecation warning.
Source code in optimade/server/config.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
|
SupportedBackend
¶
Bases: Enum
Enumeration of supported database backends
elastic
: Elasticsearch.mongodb
: MongoDB.mongomock
: Also MongoDB, but instead of using thepymongo
driver to connect to a live Mongo database instance, this will use themongomock
driver, creating an in-memory database, which is mainly used for testing.
Source code in optimade/server/config.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|