Sources
A source pulls data from one system, such as an ad platform, a REST API, a file store or a database. It is a
folder of YAML, not code: one source.yaml and one file per stream in streams/. Use a source when you want to pull
data and write it to files or a warehouse.
source.yaml says who you are and how to connect. Each streams/*.yaml file says what to fetch, shape and
write. Each run brings its own settings and secrets.
my_source/
├── source.yaml
└── streams/
├── accounts.yaml
├── campaigns.yaml
└── metrics.yaml
Run it with streamwright run my_source. Check it first with streamwright validate my_source.
source.yaml
source.yaml holds what every stream shares: the source's inputs, how to sign in, and shared defaults.
kind: source
name: my_source
spec:
config: # non-secret settings, given per run
account_id: { type: string }
region: { type: string, default: us }
secrets: # credentials, never written in the source
token: { type: string }
auth:
provider: restapi # the generic REST connector, or an SDK connector: postgres, s3, google_ads, ...
type: bearer # bearer, oauth2_refresh_token, api_key, basic
token: "{{ secrets.token }}"
http: # shared HTTP defaults for REST sources
base_url: https://api.example.com
paginator: { type: cursor, token_path: next_token, param: cursor }
records: { path: data }
policy:
retry: { codes: [429, 500, 502, 503], max_attempts: 5 }
This source:
- takes one required setting (
account_id), one optional setting (region, defaultus) and one secret (token); - signs in to a REST API with a bearer token (this is the source's connection);
- follows cursor pages and reads records from each response's
datafield; - retries every request on rate limits and server errors, up to 5 attempts (this is the source's default policy).
| Key | What it does |
|---|---|
spec.config | Non-secret inputs. A run gives them with --set, a --config file, or the input's default. Use them as {{ config.NAME }}. Types: string, integer, number, boolean, date, or list (with items). |
spec.secrets | Credentials. A run gives them with STREAMWRIGHT_SECRET_<NAME> environment variables or a --secrets file. Use them as {{ secrets.NAME }}. They are redacted in every log line. |
timezone | Optional. The time zone of today, relative dates (-7d), incremental windows and dates in file paths: an IANA name such as America/New_York, or "{{ config.timezone }}" to take it from a string input, so each client's run sets it with --set timezone=.... Default: UTC. |
auth | Where: the connector (provider) and how to sign in. A REST source picks a type such as bearer or oauth2_refresh_token; an SDK connector such as google_ads, postgres or s3 takes its own keys. |
http | Shared HTTP defaults for REST sources: base_url, paginator, records, headers. See the REST API connector. |
policy | How: the default retry and rate_limit of every request. A stream's own policy: replaces them. With rate_limit.shared_by, every limit of the connector with the same value is one limit, in a run. |
export | Optional. Defaults for every export, such as a file_name template. See Export. |
macros | Optional. .sql files of SQL functions every stream's steps can call, relative to the source's folder. See Macros. |
spec.lookups | Optional. Values fetched when a run starts, for the inputs bound to them. See Inputs from lookups. |
connections | Optional. The databases its lookups query and its state store lives in. |
runtime | Optional. The DuckDB the streams' SQL runs in: threads (default 1) and memory_limit such as 512MB or 4GB (default 1GB); a stream's own runtime replaces them, key by key. state: where the runs keep their bookmarks. See Bookmarks in a state store. |
One source, many clients
Nothing client-specific lives in the source. Each run brings its own settings and secrets, so one source serves every client.
config: # values for spec.config
account_id: "1234567890"
streams: [campaigns, metrics] # optional: which streams to run (default: all)
streamwright run my_source \
--config clients/example.yaml \
--secrets clients/example.secrets.yaml
| Option | What it does |
|---|---|
--config FILE | One client's config values, and optionally the streams to run |
--set NAME=VALUE | One config value; it overrides the same value from --config |
--secrets FILE | Values for spec.secrets; they override STREAMWRIGHT_SECRET_<NAME> variables |
--stream NAME | Run only this stream or export; it replaces the file's streams list |
The same split lets one pipeline run across many ad networks. See shared vocabulary.
Inputs from lookups
An input can get its value from a database, a command or AWS Secrets Manager, as in a
DuckDB job. A value given with --set, --config or --secrets wins over the lookup.
spec:
config:
account_id: { type: string }
secrets:
db_password: { type: string }
token: { type: string, lookup: { from: creds, field: token } }
lookups:
creds:
type: database
connection: creds_db
query: SELECT token_enc FROM accounts WHERE account_id = :account
params: { account: "{{ config.account_id }}" }
transforms: # decrypt the column; a command or function needs --allow-lookup-exec
token: { type: command, command: [decrypt-token], stdin: "{{ row.token_enc }}" }
connections:
creds_db: { provider: postgres, host: db.internal, database: creds, user: reader, password: "{{ secrets.db_password }}" }
Bookmarks in a state store
By default a run keeps its bookmarks in a file (--state FILE, state.json beside file outputs). With
runtime.state in source.yaml, runs keep them in a state store instead, the same one DuckDB jobs use: SQLite for
development, PostgreSQL or MySQL in production.
runtime:
state:
sqlite: state.db # or: connection: state_db (a postgres or mysql connection), schema: ...
scope: "account:{{ config.account_id }}" # each account resumes from its own bookmarks
Each run resumes from the last completed run's bookmarks, one run per scope at a time, and shows in
streamwright state runs and the console, with its log (Log tab)
when it runs with --log-dir. While the SQLite file is not there, runs keep their bookmarks
in a file as before; --apply-state-migrations creates it.