Emmet API Server

0.86.3 · active · verified Tue Apr 14

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

Install

Imports

Quickstart

The `emmet-api` library primarily provides an API server, built on FastAPI. The quickstart demonstrates how to set up a basic FastAPI application and integrate Emmet's routers. To run the API server, you would typically use the `uvicorn` command, pointing to the configured FastAPI application instance, whether it's a custom script or the default `emmet_api.main:app` entry point provided by the package. Ensure necessary environment variables for `EmmetSettings` (e.g., database connection) are configured.

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.

view raw JSON →