Examples & API Showcases
Every SemanticFed developer repository ships runnable example applications and automated smoke tests so you can verify integration flows locally — both offline in --demo mode (no credentials required) and against a live workspace.
Example catalog
| Repository | Example | What it demonstrates | How to run |
|---|---|---|---|
semanticfed-sdk-node | examples/01-federated-model-and-query.ts | Registering connectors & data sources, authoring and publishing a semantic model (entities, dimensions, metrics), publishing and running a saved federated query, and reading plan/result rows | bun examples/01-federated-model-and-query.ts --demo |
semanticfed-sdk-node | examples/02-governed-sql-and-policies.ts | Introspecting sqlCatalog(), listing active access policies, running a governed SELECT via sql(), inspecting masked column metadata, and exporting RFC-4180 CSV | bun examples/02-governed-sql-and-policies.ts --demo |
semanticfed-sdk-python | examples/basic_usage.py | Minimal async client initialization with workspace tokens, listing connectors and shared tags, and clean sdk.close() teardown | uv run python examples/basic_usage.py |
semanticfed-sdk-python | examples/federated_analytics_showcase.py | Async Python data-pipeline / BI bridge: listing connectors and models, inspecting sql_catalog() and access_policies, running governed sql(), and exporting masked rows to CSV | uv run python examples/federated_analytics_showcase.py --demo |
semanticfed-mcp | examples/governed-agent-client.ts | Real @modelcontextprotocol/sdk stdio client spawning semanticfed-mcp in --read-only and full mode, inspecting semanticfed:// resources & prompts, and verifying policy-write gating and destructive confirmation refusal | bun examples/governed-agent-client.ts |
Showcase 1: Federated semantic model & saved query (Node.js)
semanticfed-sdk-node/examples/01-federated-model-and-query.ts walks through the full semantic modeling and governed query lifecycle:
git clone https://github.com/algoshred/semanticfed-sdk-node.git
cd semanticfed-sdk-node
bun install
# Offline demo mode (in-process GraphQL transport stub)
bun examples/01-federated-model-and-query.ts --demo
# Live workspace inspection
export SEMANTICFED_ACCESS_TOKEN="<platform-token>"
export SEMANTICFED_WORKSPACE_TOKEN="<workspace-token>"
bun examples/01-federated-model-and-query.ts
Key SDK operations exercised:
sdk.semanticfed.connectors.create()/list()anddataSources.create()sdk.semanticfed.models.create()/publish(),entities.create(),dimensions.create(),metrics.create()sdk.semanticfed.queries.create()/publish()/run()sdk.semanticfed.queryRuns.get()andqueryRuns.result()
Showcase 2: Governed SQL endpoint & BI CSV bridge (Node.js & Python)
Both SDKs expose typed helpers over the read-only SQL endpoint (semSqlCatalog and semExecuteSql) so downstream BI tools and notebooks receive governed, policy-masked datasets without authoring raw GraphQL.
Node.js (examples/02-governed-sql-and-policies.ts)
cd semanticfed-sdk-node
bun examples/02-governed-sql-and-policies.ts --demo
Python (examples/federated_analytics_showcase.py)
git clone https://github.com/algoshred/semanticfed-sdk-python.git
cd semanticfed-sdk-python
uv sync --locked --all-extras
# Offline demo mode (respx HTTP mock)
uv run python examples/federated_analytics_showcase.py --demo
# Live workspace
export SEMANTICFED_ACCESS_TOKEN="<platform-token>"
export SEMANTICFED_WORKSPACE_TOKEN="<workspace-token>"
export SEMANTICFED_MODEL_ID="<model-id>"
uv run python examples/federated_analytics_showcase.py
Both examples output structured JSON including the discovered catalog tables, active access-policy count, masked column names, row count, truncation flag, and an RFC-4180 CSV preview.
Showcase 3: Governed MCP analyst agent (TypeScript)
semanticfed-mcp/examples/governed-agent-client.ts connects a real MCP client (StdioClientTransport) to the semanticfed-mcp server entrypoint and verifies the server's governance guarantees end-to-end:
git clone https://github.com/algoshred/semanticfed-mcp.git
cd semanticfed-mcp
bun install
bun examples/governed-agent-client.ts
What the showcase verifies:
--read-onlymode exposes read tools,semanticfed://resources, prompts,semanticfed_sql_catalog,semanticfed_sql_execute, andsemanticfed_queries_runwhile hiding mutating tools (semanticfed_models_create,semanticfed_entities_delete, policy writes).- Default full mode exposes
semanticfed_access_policies_listwhile keepingsemanticfed_access_policies_createandsemanticfed_access_policies_set_activeoff the tool list unless--enable-policy-writesis explicitly set. - Calling a destructive tool such as
semanticfed_entities_deletewithoutconfirm: trueis refused before any GraphQL request is dispatched.
Showcase 4: Direct GraphQL & PostgreSQL wire smoke calls
GraphQL health and model listing (curl)
curl -sS -X POST https://graphqlworkspaces.burdenoff.com/workspaces/graphql \
-H "Content-Type: application/json" \
-H "Origin: https://app.semanticfed.com" \
-H "Authorization: Bearer $SEMANTICFED_ACCESS_TOKEN" \
-H "X-Workspace-Authorization: Bearer $SEMANTICFED_WORKSPACE_TOKEN" \
-H "x-workspace-id: $WORKSPACE_ID" \
-d '{"query":"query { semHealth semListModels(pagination: { limit: 10 }) { items { id name status } } }"}'
PostgreSQL wire protocol (psql)
PGPASSWORD="$SEMANTICFED_ACCESS_TOKEN" \
PGOPTIONS="-c semanticfed.model=$SEMANTICFED_MODEL_ID" \
psql "host=sql.semanticfed.com port=5432 dbname=$WORKSPACE_ID user=analyst sslmode=verify-full sslrootcert=system" \
-c "\dt" \
-c "SELECT region, SUM(amount) AS revenue FROM orders GROUP BY region ORDER BY revenue DESC LIMIT 10"
Continuous verification
Every runnable example in semanticfed-sdk-node, semanticfed-sdk-python, and semanticfed-mcp is backed by automated tests executed in repository sanity checks (bun test / pytest), alongside GraphQL document validation against the production workspace supergraph (schema/wspace.graphql).