Quick Start
Viewing typescript
switch to python
- Docker (opens in a new tab)
- macOS or Linux (Windows is not supported at this time, but may work using WSL Windows Subsystem for Linux)
Check if these dependencies are installed:
git --version && node --version && docker --version
git --version && python3 --version && docker --version
First, initialize your Moose project
Install the Moose CLI
Moose is installed as a Python package, so you can install it using pip:
pip install moose-cli
Initialize a New Moose Project via the CLI
moose-cli init my-moose-app python
Don't forget to include the python
flag when initializing your project.
Run create-moose-app
in your terminal
npx create-moose-app@latest my-moose-app ts
This will automatically create a new project folder and initialize a skeleton Moose app with the entire project structure you need to get started.
Navigate to your project directory and install project dependencies
cd my-moose-app && npm install
cd my-moose-app && pip install -e .
Spin up your Moose local development server
Run docker info
to check.
npx moose-cli dev
moose-cli dev
The dev server dynamically configures and updates the infrastructure for your application, including a web server for data ingestion and consumption, a Redpanda platform for data buffering, and a Clickhouse database for data storage and querying.
Check that the infrastructure is set up correctly
Make sure to cd
into your Moose project directory before running the command.
npx moose-cli ls
moose-cli ls
You should see the following ouput, which shows the ingestion points and tables that have been created for your project:
Next, view and test your data models
Open Project in IDE
When you open your project, you'll be prompted to install the SQLTools (opens in a new tab) and SQLTools ClickHouse Driver (opens in a new tab) extensions. Moose auto-configures these for your local Clickhouse database, enabling you to explore and query your data immediately.
Open models.ts
and inspect the data models (located in /app/datamodels
)
Open models.py
and inspect the data models (located in /app/datamodels
)
import { Key } from "@514labs/moose-lib";
export interface UserActivity {
eventId: Key<string>;
timestamp: string;
userId: string;
activity: string;
}
export interface ParsedActivity {
eventId: Key<string>;
timestamp: Date;
userId: string;
activity: string;
}
from moose_lib import Key, moose_data_model
from dataclasses import dataclass
from datetime import datetime
@moose_data_model
@dataclass
class UserActivity:
eventId: Key[str]
timestamp: str
userId: str
activity: str
@moose_data_model
@dataclass
class ParsedActivity:
eventId: Key[str]
timestamp: datetime
userId: str
activity: str
The file defines UserActivity
and ParsedActivity
data models, which structure data for ingestion into your Moose infrastructure.
Moose automatically created database tables and ingestion points for these models, as seen in the moose-ls
output.
Finally, ingest data into your application infrastructure
Send sample UserActivity
data to the /ingest/UserActivity
API endpoint on your local dev server (running on localhost:4000
):
curl -X POST \
-H "Content-Type: application/json" \
-d '{"eventId": "1234567890", "timestamp": "2019-01-01 00:00:01", "userId": "123456", "activity": "click"}' \
http://localhost:4000/ingest/UserActivity
Check for confirmation messages in the CLI that the API endpoint received the data
POST /ingest/UserActivity/0.0
SUCCESS /ingest/UserActivity/0.0
Navigate to your preferred database explorer and connect to the Clickhouse database:
- Click the SQLTools database icon in your extensions tab.
- You should see the Clickhouse icon followed by the connection details for the database running on your local dev server:
panda@localhost:18123/local
. - To create and run a new query, click the
New SQL File
icon.
Query your database to confirm the data landed
Navigate to your preferred database explorer tool and run the following query:
SELECT * FROM local.UserActivity_0_0
You should see the data you ingested in the UserActivity
table.
Next Steps
You've successfully set up a Moose project, ingested data, and confirmed that it landed in your database. You're now ready to dive deeper and explore all the exciting capabilities that Moose has to offer. Here are some suggested next steps:
Learn Other Moose Primitives
Process Data with Streaming Functions
Learn how to process UserActivity data into ParsedActivity data using Streaming Functions