Introduction

The Tinybird platform provides you with an easy way to ingest and query large amounts of data in real time, as well as to automatically create an API out of it. This makes it extremely easy to build fast and scalable applications that query your data; no back-end needed!

Tinybird works with CSV files, especially those that are too big for Excel. If you have one around, you can grab it (it can be hosted online or in your local drive) and import it to your account directly through Tinybird’s UI or using our APIs. And if you don’t have any .CSV file around, you might want to try with a few million Taxi rides from the NYC Taxi Data or with hundreds of thousands of trees from the NYC Tree Atlas.

As an example, the code below illustrates how you can quickly build a simple frontend application which runs a query against a few million rows using Tinybird.js.

local file with events data
$ cat local_file.csv
id,date,event,created_at,updated_at,user_id
3,2011-12-17 20:51:17,work_start,2011-12-17 20:11:45.746993+00,2011-12-17 20:11:45.746993+00,test
4,2011-12-17 22:13:10,started,2011-12-17 20:11:45.746993+00,2011-12-17 20:11:45.746993+00,1234
5,2011-12-17 22:13:21,work_start,2011-12-17 20:11:45.746993+00,2011-12-17 20:11:45.746993+00,4567
6,2011-12-18 22:13:31,button_a,2011-12-17 20:11:45.746993+00,2011-12-17 20:11:45.746993+00,897
7,2011-12-19 22:13:38,button_b,2011-12-17 20:11:45.746993+00,2011-12-17 20:11:45.746993+00,12332
create a datasource with that file
$ curl -F "csv=@local_file.csv" \
  -H 'Authorization: Bearer TOKEN' \
  https://api.tinybird.co/v0/datasources?name=events

At this point your data is loaded into a Tinybird datasource called ‘events’. And when you create a datasource in Tinybird, a transformation pipeline (or a pipe) will be created for you as well.

A pipe is essentially a sequence of one or more SQL queries (transformations) applied to your datasource; you can publish the final transformation of any given pipe as an API endpoint. You can then query it through HTTP and get the result in different formats (CSV, JSON or other).

This gives you the ability to transform that intial raw CSV data into something that you can publish and use in another app with very little effort.

Let’s query the pipe you just created when importing your datasource; by default, Tinybird will name the pipe like the datasource plus a ‘_pipe’ suffix, so yours will be ‘events_pipe’.

get information about the pipe itself
$ curl -H 'Authorization: Bearer TOKEN' \
  https://api.tinybird.co/v0/pipes/events_pipe
  {
    "id": "t_7ab61a8ee1744744bd4b5ca90138126b",
    "name": "events_pipe",
    "published_version": "t_9ce53dda15fc44b69b306a346549de9e",
    "published_date": "2019-06-25 05:36:46.463167",
    "nodes": [
      {
        "name": "events_pipe",
        "description": null,
        "sql": "select * from events",
        "id": "t_9ce53dda15fc44b69b306a346549de9e",
        "dependencies": [
          "events"
        ],
        "materialized": false,
        "created_at": "2019-06-25 05:43:40.722085"
      }
    ]
  }

As you can see, there is only one transformation node in the pipe at first, which by default is a simple query against your datasource.

Let’s now add a transformation to get the number of events per day.

adds a transformation to get number of events per day
$ curl \
  -d 'SELECT toDate(date) date, count() nevents FROM events GROUP BY date' \
  -H 'Authorization: Bearer TOKEN' \
  https://api.tinybird.co/v0/pipe/events_pipe/append
  {
    "name": "events_pipe_1",
    "description": null,
    "sql": "SELECT toDate(date) date, count() nevents FROM events GROUP BY date",
    "id": "t_29e39e497f3e4f5ebc5f70af26b15d43",
    "dependencies": [
      "events"
    ],
    "materialized": false,
    "created_at": "2019-06-25 08:03:43.365141"
  }

Notice how the query in the transformation aims at ‘events’ (the datasource), but it would also be perfectly fine to do it against the result of a transformation node.

You can now get the result of the transformation directly by issuing a GET request to the pipe.

get the data as a regular API
$ curl -H 'Authorization: Bearer TOKEN' \
  https://api.tinybird.co/v0/pipe/events_pipe.json
  {
      "data": [
          { "date": "2011-12-17", "nevents": 3 },
          { "date": "2011-12-18", "nevents": 1 },
          { "date": "2011-12-19", "nevents": 1 },
      ]
  }
or with javascript
//norun
let t = tinybird('token').pipe('events_pipe')
var res = await t.query(`select * from _`)
console.log(`event on 2011-12-17 -> {res.data['2011-12-17'}`)
Simple tinybird.js application
<!doctype html>
<html lang="en">

  <head>
    <meta charset="utf-8">
    <title>Simple tinybird application</title>
    <script src='https://cdn.tinybird.co/v1/tinybird.js'></script>
  </head>

  <body>
    <script>
      let t = tinybird('<token>').pipe('<pipe>')
      var count = await t.single(`select count() from _`)
      console.log(`your table has ${count} elements`)
    </script>
  </body>

</html>

Everything you will find in the documentation is designed in a way that makes Tinybird:

  • Easy to use (no backend needed).

  • Fast in performing analytical workloads.

  • Secure.

  • Autoscalable.

When building applications, you can always use our REST API, but we highly recommend you use our official JS API library. If you are new here or coding is not your thing, we recommend you use the Console UI to import your data.

If you are already loged in, the documentation will be specifically generated for you therefore your data and tokens, when shown, will be displayed just to you (this will save you tons of time when testing things!).

Next steps

Now that you know enough to create your first application with Tinybird, learn more about how to run queries using Tinybird.js or how to import your data with our REST API.