Pipes¶
A pipe is a collection of one or more SQL queries. Each query is called a node.
Use Pipes to build features over your data. For example, you can write SQL that joins, aggregates, or otherwise transforms your data. Pipes may be internal, that is, just referenced in your project, or they can have different outputs such as API Endpoints, Sinks, Materialized Views, and Copy Jobs.
Nodes¶
A node is a container for a single SQL SELECT statement. Nodes live within pipes, and you can have many sequential nodes inside the same pipe. They allow you to break your query logic down into multiple smaller queries. You can then chain nodes together to build the logic incrementally.
A query in a node can read data from a data source, other nodes inside the same pipe, or from endpoint nodes in other pipes. Each node can be developed and tested individually. This makes it much easier to build complex query logic in Tinybird as you avoid creating large monolithic queries with many subqueries.
Pipes are defined with .pipe files in regular projects, in .ts files with the TypeScript SDK, or in .py files with the Python SDK.
SQL nodes can use Tinybird's templating language for typed parameters, conditional SQL, and environment-specific values.
pipes/events_by_path.pipe
DESCRIPTION >
Count events by path for a date range
NODE recent_events
SQL >
%
SELECT timestamp, pathname
FROM events
WHERE timestamp >= {{DateTime(start_date)}}
AND timestamp <= {{DateTime(end_date)}}
NODE aggregation
SQL >
SELECT pathname, count() AS events
FROM recent_events
GROUP BY pathname
ORDER BY events DESC
See all syntax options in the Pipe files reference, TypeScript SDK reference, and Python SDK reference.
Create generic pipes¶
Generic pipes are internal pipes that you use from other pipes or endpoints. The examples above create generic pipes because they don't declare an output type such as Endpoint, Materialized View, Copy Job, or Sink.
Use generic pipes to split complex SQL into reusable steps or to replace include-file patterns from Classic projects. To publish the result as an API endpoint, see Endpoints.
Next steps¶
- Learn about Endpoints.
- Learn about Copy pipes.
- Learn about Materialized views.