Emmet API Server
Emmet is a toolkit of packages designed to build the Materials API, which is the Materials Project (MP) specification for defining and disseminating “materials documents”. The `emmet-api` package specifically provides the API server component for serving these material documents. It is currently at version 0.86.3 and receives frequent development builds (e.g., 0.87.0.devX) with stable releases occurring periodically.
Warnings
- breaking The Emmet project is under active development with frequent pre-release versions (e.g., `0.87.0.devX`). While `emmet-api` has stable releases, significant architectural and API changes are common across the broader Emmet ecosystem, which may lead to breaking changes in minor versions or impact integration with other Emmet packages.
- gotcha While `emmet-api` is a standalone PyPI package, it is part of a larger 'Emmet toolkit' from the Materials Project. Full functionality and understanding of the data models often require interaction with or knowledge of `emmet-core`. Users might need to install `emmet-core` separately to access core document definitions and utilities.
- gotcha The `emmet-api` package explicitly requires Python >=3.11. Attempting to install or run it with older Python versions will result in installation failures or runtime errors.
Install
-
pip install emmet-api -
pip install 'emmet-api[test,docs]' # for optional extras
Imports
- FastAPI
from fastapi import FastAPI
- build_router
from emmet_api.routes import build_router
- EmmetSettings
from emmet_api.core.config import EmmetSettings
Quickstart
import uvicorn
from fastapi import FastAPI
from emmet_api.routes import build_router
from emmet_api.core.config import EmmetSettings
# Initialize FastAPI app
app = FastAPI(
title="Emmet API Server Example",
description="Minimal Emmet API instance for demonstration",
version="0.86.3"
)
# Load settings (adjust as per your environment variables or config files)
settings = EmmetSettings() # This will load settings from environment variables or .env file
# Build and include routers into the FastAPI app
# The build_router function modifies the app in-place.
build_router(app, settings)
# To run this application, save it as, e.g., `my_api.py` and execute:
# uvicorn my_api:app --host 0.0.0.0 --port 8000 --reload
# Alternatively, if running directly from the installed emmet-api package's entry point:
# uvicorn emmet_api.main:app --host 0.0.0.0 --port 8000 --reload
# The following lines are for demonstration if this script were the entry point
# if __name__ == "__main__":
# uvicorn.run(app, host="0.0.0.0", port=8000)
# Note: This quickstart primarily shows the Python setup.
# Running the server typically involves the `uvicorn` command-line tool.