Serve
Serve
The serve command starts a FastAPI server to expose Trilogy models from a directory. This is useful for interactive development/debugging and can be added as a remote store in Trilogy Studio.
Requires pytrilogy[serve] extras.
Arguments:
@argument("directory", type=Path(exists=True, file_okay=False, dir_okay=True))
@argument("engine", type=str, required=False, default="generic")
@option("--port", "-p", default=8100, help="Port to run the server on")
@option("--host", "-h", default="0.0.0.0", help="Host to bind the server to")
@option("--timeout", "-t", default=None, type=float, help="Shutdown after N seconds")
Endpoints Exposed
/- Server info/index.json- List of available models/models/<name>.json- Specific model details/files/<name>- Raw .preql/.sql file content
Full Examples
# Serve a directory of models
trilogy serve ./models/ duckdb
# Serve on a custom port
trilogy serve ./models/ duckdb --port 8080
# Serve with auto-shutdown (useful for testing)
trilogy serve ./models/ generic --timeout 60
# Bind to specific host
trilogy serve ./models/ postgres --host 127.0.0.1 -p 3000
Notes
- Requires FastAPI and uvicorn:
pip install pytrilogy[serve] - CORS is enabled by default for all origins
- The server scans for
.preql,.sql, and.csvfiles - Useful for connecting to Trilogy Studio for interactive exploration
