This example demonstrates the basics of using the tinybird-sdk-php library. It's a simple command-line script that:
- Connects to the Tinybird API
- Lists existing Data Sources
- Sends events to a Data Source
- Queries the data using SQL
- PHP 8.1 or higher
- Composer
- Tinybird Account with an API Token
- A Data Source to send events to
Navigate to this directory and install the required packages using Composer:
cd examples/quick-start
composer installCreate a .env file by copying the example file:
cp env.example .envOpen the .env file and add your Tinybird token and Data Source name:
TINYBIRD_TOKEN="p.your_token_here"
TINYBIRD_DATASOURCE="events"If you don't have a Data Source yet, you can create one in the Tinybird UI or use the CLI:
tb datasource create events --schema "timestamp DateTime, event String, user_id String, page String"Execute the script from your terminal:
php index.phpOr use the composer script:
composer startThe script will:
- Connect to your Tinybird workspace
- List existing Data Sources
- Send sample events to your Data Source
- Query and display event counts grouped by type