Infrastructure
Proxy Server
ML data is rarely useful unless it can be exposed to other services.
This is where the proxy server simplifies the entire process.
CLI command
To expose all models and data, use the following command:
aligned proxy-server
You can also use the --expose-tag
option to expose only specific data and model contracts that contain a particular tag.
By default, the command reads contracts from contracts_store.json
. However, you can customise this by using the --contracts
option to specify a different file.
Customising the server
Often, you may want to customise the API further by adding authentication, custom logging, and more. You can achieve this using the following code to obtain the FastAPI
router:
from fastapi import FastAPI, Request, Depends
from contextlib import asynccontextmanager
from aligned import ContractStore
from aligned.proxy_api import router_for_store
async def authenticate_user(request: Request):
...
@asynccontextmanager
async def lifespan(app: FastAPI):
store: ContractStore = ...
contracts_router = router_for_store(
store,
expose_tag="expose-through-api" # Use None to expose all contracts
)
app.include_router(
contracts_router,
dependencies=[Depends(authenticate_user)]
)
yield
app = FastAPI(lifespan=lifespan)