SegmentStream pipeline SDK
Declare source tables with s.ingestion and warehouse SQL transformations with
s.model. The SDK resolves inputs, validates explicit partitioning and capabilities,
and compiles native Dagster definitions using the existing warehouse loader.
from collections.abc import Iterator
import ibis.expr.types as ir
import segmentstream as s
@s.ingestion(
tier=s.Tier.Bronze,
partitioning=s.Partitioning.Unpartitioned,
schema={"amount": "float64"},
)
def orders() -> Iterator[s.IngestionRow]:
yield {"amount": 25.0}
@s.model(
tier=s.Tier.Gold,
partitioning=s.Partitioning.Unpartitioned,
schema={"total_revenue": "float64"},
)
def revenue(orders: ir.Table) -> ir.Table:
return orders.aggregate(total_revenue=orders.amount.sum())
defs = s.definitions(
assets=[orders, revenue],
jobs=[s.job("revenue", assets=[revenue], include_upstream=True)],
)
Connections are declared with the connections SDK,
segmentstream-connections, which this SDK depends on at the same release. Pipeline code reaches
a declared connection with s.get_connection(key).get_http_client(). The declaration classes are
still re-exported from segmentstream and segmentstream.connections for connections.py files
that import them from there.
The workspace documentation (docs/README.md) is organized by concept:
connections (docs/connections.md), ingestion (docs/ingestion.md),
models (docs/models.md), partitioning (docs/partitioning.md),
jobs (docs/jobs.md), execution (docs/execution.md), checks (docs/checks.md),
runtime values (docs/runtime.md), and warehouse storage (docs/warehouse.md).
The CLI bundles these same pages into every starter workspace.
s.validate(defs) checks the graph and named job configuration without executing
assets. s.describe(defs) explains resolved inputs, per-asset policies, storage,
capabilities, same-day input mappings, and job selections without resolving
credentials. See the
modular commerce starter
for daily row ingestion, batched models, and a partitioned check.
Daily inputs may begin earlier or end later than their consumers when they use
the same timezone and day boundaries. The upstream must cover every downstream
date. The SDK supplies strict same-day mappings for inputs and ordering-only
dependencies; no native Dagster decorator or mapping option is needed. Named
jobs still select one daily calendar, with other calendars left as inputs.
Slack connection
SlackConnection(key="slack") reaches the Slack Web API as the bot of your own Slack app,
installed in one Slack workspace. Enter the app's client ID and secret on the connection after
deployment, add the redirect URI shown there to the app, then authorize to install it. Its
default bot scopes are those the workspace agent's Slack channel uses; pass scopes to request
fewer. Custom OAuth2 connections gain access_token_type for providers that name their bearer
tokens differently, as Slack's bot. Connections inspection publishes connections manifest
schema 17: upgrade Cloud before deploying declarations from the next SDK release. See
Slack (docs/connections.md#slack).
Destinations and asset kinds (0.1.0a73)
@s.destination(connection=...) sends its input tables' rows through one connection and
returns s.Delivery(sent, rejected); it stores no table and nothing reads from it. The
manifest (version 13) marks each asset as an ingestion, a model or a destination, and
carries an ingestion's result, schema origin, keys and replacement mode. Upgrade the
backend before deploying declarations from this SDK. See
destinations (docs/destinations.md).
Gmail connection (0.1.0a71)
GmailConnection(key="gmail") reaches one Google account's mailbox through the Gmail API
on users/me. Google admits Gmail's restricted scopes only on internal or verified
applications, so it always authorizes through your own Google OAuth client: enter its
client ID and secret on the connection after deployment. It requests every Gmail scope
except full mail access by default; pin scopes to those you use. Permanent deletion is
not admitted. Upgrade the backend before deploying declarations from this SDK. See
connections (docs/connections.md#gmail).
Runtime capability limit (0.1.0a70)
An asset, and the union of a job's or run's selected assets, may require up to 64
connections and secrets combined, up from 16. Deployments built with earlier SDK
versions keep their 16-capability authoring limit. segmentstream exec still
selects at most 16 connections.
One-time asset runs (0.1.0a67)
After deploying with the updated managed runtime, users with the required asset
permissions can materialize through Lineage or segmentstream asset materialize
without declaring a job. Cloud checks the complete resolved selection; see
asset-run permissions (docs/asset-backfills.md#permissions-and-deployment).
The published manifest includes each asset's materializability, required co-produced
assets, and configuration readiness. Daily selections may use different calendar
starts and ends when the requested dates exist in every selected calendar and their
timezones agree. Unpartitioned assets refresh once.
These runs use asset and resource definition defaults. A named job's configuration
does not apply. Inspection flags required configuration and native config mappings
that cannot be validated without executing user code. Checks run with their selected
assets; any credential capabilities they declare must be covered by the target
asset's runtime requirements. Workspace app credentials continue to use opted-in
named jobs.
Runs from a workspace app (0.1.0a65)
Opt in individual jobs with s.job("land_watch", assets=[land_checks], allow_app_runs=True).
After deployment, app SDK 0.15.0 can start and read their runs with the workspace app
credential. Other jobs stay unavailable to that credential; removing the flag revokes access.
Apps must still authorize their signed-in users before submitting or reading runs.
See app data access (docs/app-data.md#start-a-pipeline-job-from-the-app).
Identity-resolution support (0.1.0a39)
Models can declare s.AllPartitions(asset) inputs for retained-history rollups.
WarehouseResource.materialize_scratch and iterate execute bounded fixed-point
algorithms in warehouse SQL and retain their results until output publication.
The SDK owns scratch cleanup; each algorithm owns its convergence and key invariants.
Compatibility
The SDK contains authoring, graph inspection, Ibis resources, connection HTTP
clients, and managed secret access. Managed orchestration, workers, PostgreSQL setup, and the metadata
webserver live in the internal pipeline runtime.
In 0.1.0a28, use s.get_connection(key).get_http_client() for provider requests.
The client forwards requests through the backend, where provider credentials and
refresh remain. The access-token and full-credential accessors have been removed.
See connections (docs/connections.md) for declaring API destinations.
Workspace pipelines declare segmentstream-pipeline[bigquery]; our image supplies
the runtime. The old SDK cloud-run and webserver extras and
segmentstream.runtime module are removed in a22.
segmentstream.dagster retains its native exports. Native assets and high-level
declarations can coexist in s.definitions. Root s.resource and
s.IngestionResource remain available for legacy ingestion. Import their helpers
from segmentstream; the old public segmentstream.ingestion module is retired
so s.ingestion can be the decorator. Migration examples (docs/native-dagster.md)
cover the mapping and IO defaults.
Ontology access
Pipeline workers automatically have full ontology access in their own workspace,
in an active managed run and in a step of a production deployment on the
SegmentStream engine. No role declaration, connection, or API-key secret is required.
Use the same HTTPX client convention as get_connection:
import segmentstream as s
with s.get_ontology().get_http_client() as client:
response = client.get("/api/ontology/me")
response.raise_for_status()
principal = response.json()
async def read_ontology():
async with s.get_ontology().get_async_http_client() as client:
response = await client.get("/api/ontology/me")
response.raise_for_status()
return response.json()
The handle discovers the deployed ontology URL through SegmentStream: the runtime
broker of a managed run, or the deployment's identity on the SegmentStream engine.
Short-lived credentials stay in memory and refresh automatically before expiry
throughout the active run; on the engine the process shares one token across its runs. Sync and async clients share the refresh cache.
Requests stay within the discovered origin and path; redirects and environment
proxy configuration are disabled. HTTP errors remain ordinary HTTPX responses,
and requests are not automatically replayed after an authentication or transport
failure. If a refresh discovers a changed deployment URL, create a new client.
Local commands, external jobs, and access to another workspace use an explicit
API key with the permissions assigned to that key:
ontology = s.Ontology(
ontology_url="https://my-workspace.example.com",
api_key=your_existing_api_key,
)
with ontology.get_http_client() as client:
response = client.get("/api/ontology/me")
response.raise_for_status()
For managed own-workspace calls, replace manually configured ontology URLs and
API-key headers with s.get_ontology(). Existing API keys remain supported through
s.Ontology(...). Automatic access is unavailable in segmentstream exec,
segmentstream dev sessions, preview deployments and other local Python processes,
and never falls back to an environment API key.
Managed Google clients
The Sandbox runtime integration supplies refreshable credentials to the built-in
BigQuery warehouse and GCS IO manager. Ibis remains the user-facing warehouse API;
its internal official Google client renews credentials automatically throughout
the authorized run. Ten minutes is the lifetime of each access token, not a limit
on pipeline duration. Managed execution does not provide general ADC support.
Managed Dagster execution uses the backend compute provider API for every step,
including SQL assets and checks. The coordinator owns scheduling and retries; the
backend owns execution identity, scoped credentials and cleanup.
Releases
SDK 0.1.0a39 adds explicit all-partition model inputs and managed warehouse
iteration with temporary SQL tables, supporting full-history identity resolution.
SDK 0.1.0a38 adds compatible daily calendars with strict same-day dependency
mappings. Consumers can start later than their upstream assets; each job still
selects one daily calendar.
The GA4 query client targets 0.1.0a37. A model constructs it with
s.ga4_bigquery_client(key, context=context) and submits SQL through the backend;
BigQuery writes the result directly to the model's warehouse partition. See
GA4 BigQuery connections (docs/bigquery-connections.md).
Publish the SDK before releasing a CLI whose starter
pins it. PyPI versions are immutable; do not republish an existing version.
pyproject.toml keeps the placeholder version 0.0.0. A pull request that changes src/
or the published pyproject.toml metadata adds a changeset naming segmentstream-pipeline
(.changeset/README.md); each merge that adds one is the next
pre-release, derived from main's history by scripts/sdk-release.mjs. Repository CI on
main builds a wheel and source distribution at that version after Cloud deploys, publishes
them with PyPI Trusted Publishing from the pypi GitHub environment, and tags
pipeline-sdk-v<version>. No long-lived publishing token is stored in GitHub. The pipeline
images install the SDK from the same commit at the same version. The app, ontology and agent
SDKs release the same way.
Unreleased: full-refresh storage layout
Models with s.Partitioning.Unpartitioned may set
storage=s.TableStorage(partition_by_date="session_date"). They run as global
steps and atomically replace the whole table while retaining physical BigQuery
DATE partitions. Daily models keep selected-date replacement. s.describe
reports the storage layout independently of execution partitioning. See
the model contract (docs/models.md#full-refresh-tables-with-physical-date-partitions).
Available in SDK 0.1.0a40; update the workspace dependency and lockfile before using it.
Unreleased: destinations without a connection (deprecated)
@s.destination takes connection=None when it declares at least one workspace secret in
secrets=: it calls its API with s.get_secret, on Dagster and on the SegmentStream engine,
and its lineage group defaults to destinations. With neither, the declaration is refused. Its
manifest entry has kind destination and no destination field; the manifest version is
unchanged. It is deprecated with workspace secrets read by name and works until 2027-01-19;
connection is then required again. Declare a connection instead. See
destinations (docs/destinations.md).
Unreleased: evaluations on the SegmentStream engine
A step on the SegmentStream engine calls s.evaluation_client(key).evaluate(...) as a
managed run's step does, for a key its asset declares, while the workspace's current
deployment is a ready production deployment on the engine. Errors are a managed run's.
Each evaluation is one request with a managed run's timeout, never sent again by the SDK.
A step that returns a table is called again in each later leg while a warehouse job outlasts
a leg; an evaluation in such a repeated call is refused before it is sent, and the attempt
fails without a retry. Evaluate in an ingestion that yields or pages its rows and waits on no
warehouse job of its own, and do the warehouse work in a model downstream. Create the client in
the function itself: one created in a thread that starts without the step's context is not
refused, and its evaluations are sent again in every repeated call.
See evaluation connections (docs/evaluation-connections.md).
Ontology entity sources (0.1.0a56)
Pipeline manifest v10 describes assets, schemas, jobs and checks. Declare business metrics in
ontology entity sources (docs/ontology-metrics.md). The semantic_models argument and
segmentstream.semantics package were removed. Release platform support before upgrading workspaces.
Evaluation connection (0.1.0a43)
EvaluationConnection(key="evaluation") evaluates state against typed boolean,
choice and score questions through Vercel AI Gateway's evaluation API; SegmentStream
chooses the model and holds the credential, so it needs no configuration or
authorization. Call s.evaluation_client("evaluation").evaluate(state=..., questions=...)
in managed runs. See evaluation connections (docs/evaluation-connections.md).
Connections inspection publishes connections manifest schema 8: upgrade the backend
before deploying declarations from this SDK.
Path values and Telegram connection (0.1.0a58)
ApiKeyConnection accepts path={"<prefix>": Secret(...)} for providers that read the
value from the URL path: the backend inserts <prefix><value> right after the API's base
path. TelegramBotConnection(key="telegram") declares the Telegram Bot API with the token
from @BotFather, sent as https://api.telegram.org/bot<token>/. Connections inspection
publishes connections manifest schema 14: upgrade the backend before deploying
declarations from this SDK. See Telegram (docs/connections.md#telegram).
Read-only connections
HTTP connection declarations accept read_only=True, for example
XeroConnection(key="xero_uk", read_only=True). The backend proxy allows GET,
HEAD and OPTIONS and rejects other supported methods with HTTP 403
connection_read_only, regardless of OAuth scopes. POST-only read APIs, including
GraphQL queries, are blocked. Existing provider policies remain in force.