
Loading...
Official SDK for integrating DataChonk into your applications and workflows
Full-featured SDK with TypeScript support
Native Python SDK with async support
Direct API access for any language
npm install @datachonk/sdkCreate a client instance with your API key. You can find your API key in your account settings.
import { DataChonk } from '@datachonk/sdk';
const client = new DataChonk({
apiKey: process.env.DATACHONK_API_KEY,
});Security tip: Never commit your API key to version control. Use environment variables or a secrets manager.
// List all projects
const projects = await client.projects.list();
for (const project of projects) {
console.log(`${project.name} - ${project.chonks.length} chonks`);
}// Create a new project
const project = await client.projects.create({
name: "E-commerce Analytics",
description: "Analytics for our online store",
warehouse: {
type: "snowflake",
account: "abc123.us-east-1",
database: "ANALYTICS",
schema: "DBT_PROD",
},
});
console.log(`Created project: ${project.id}`);Scan your data warehouse to discover tables and automatically generate chonks.
// Start a warehouse scan
const scan = await client.scans.start({
projectId: project.id,
schemas: ["RAW", "STAGING"],
options: {
sampleRows: 1000,
inferTypes: true,
detectRelationships: true,
},
});
// Wait for scan to complete
const result = await scan.wait();
console.log(`Found ${result.tables.length} tables`);
console.log(`Generated ${result.chonks.length} chonks`);Generate production-ready dbt models from your chonks.
// Generate dbt models from chonks
const models = await client.generate.models({
projectId: project.id,
chonkIds: ["chonk_123", "chonk_456"],
options: {
materialization: "incremental",
includeTests: true,
includeDocs: true,
},
});
for (const model of models) {
console.log(`Generated: ${model.name}`);
console.log(model.sql);
}Use natural language to generate dbt code with Chonk.
// Chat with Chonk
const response = await client.chonk.chat({
projectId: project.id,
message: "Create a staging model for the raw_orders table",
});
console.log(response.message);
// Get generated code
if (response.generatedCode) {
console.log(response.generatedCode.sql);
}Push generated models directly to your GitHub repository.
// Push generated models to GitHub
const push = await client.github.push({
projectId: project.id,
repository: "acme/dbt-analytics",
branch: "feature/new-models",
commitMessage: "Add order staging models",
createPR: true,
});
console.log(`PR created: ${push.pullRequestUrl}`);Receive real-time notifications when events occur in your projects.
// Create a webhook
const webhook = await client.webhooks.create({
projectId: project.id,
url: "https://your-app.com/webhooks/datachonk",
events: ["scan.completed", "models.generated", "github.pushed"],
secret: "your-webhook-secret",
});
// List webhooks
const webhooks = await client.webhooks.list({ projectId: project.id });import { DataChonk, DataChonkError, RateLimitError } from '@datachonk/sdk';
try {
const project = await client.projects.get("invalid-id");
} catch (error) {
if (error instanceof RateLimitError) {
console.log(`Rate limited. Retry after: ${error.retryAfter}s`);
} else if (error instanceof DataChonkError) {
console.log(`API error: ${error.message}`);
console.log(`Status: ${error.status}`);
} else {
throw error;
}
}Full TypeScript type definitions are included in the SDK.
// Key types
interface Project {
id: string;
name: string;
description?: string;
warehouseType: 'snowflake' | 'bigquery' | 'redshift' | 'databricks' | 'postgresql';
chonks: Chonk[];
createdAt: Date;
updatedAt: Date;
}
interface Chonk {
id: string;
projectId: string;
name: string;
type: 'source' | 'staging' | 'entity' | 'fact' | 'metric';
schema: string;
table?: string;
columns: Column[];
relationships: Relationship[];
tests: Test[];
}
interface GeneratedModel {
name: string;
sql: string;
yaml?: string;
path: string;
tests: string[];
}