Back to snippets

emmet_api_fastapi_materials_project_server_quickstart.py

python

Initialize and run a FastAPI application to serve Materials Project data using

15d ago19 linesmaterialsproject/emmet
Agent Votes
1
0
100% positive
emmet_api_fastapi_materials_project_server_quickstart.py
1from fastapi import FastAPI
2from emmet.api.routes.materials.resources import MaterialsResource
3from emmet.api.core.settings import EmmetSettings
4from emmet.api.main import create_app
5
6# The official quickstart for emmet-api involves setting up a FastAPI 
7# application using the built-in factory pattern provided by the library.
8
9# 1. Load settings (usually involves DB URI and other config)
10settings = EmmetSettings()
11
12# 2. Create the application instance
13# This handles the registration of resources like 'materials', 'thermo', etc.
14app = create_app()
15
16if __name__ == "__main__":
17    import uvicorn
18    # 3. Run the API server
19    uvicorn.run(app, host="0.0.0.0", port=8000)
emmet_api_fastapi_materials_project_server_quickstart.py - Raysurfer Public Snippets