Skip to content

Installation & Quick Start

This guide takes you from zero to a running Kirak API in about five minutes. By the end, you will have a project with CRUD endpoints, JWT authentication, and a working database migration.


  • Python 3.11+ (tested on Python 3.11 through 3.13)
  • pip (bundled with Python)
  • A database of your choice:
    • SQLite: Built into Python, needs no database server (fastest way to get started).
    • PostgreSQL 13+ or MySQL 8.0.13+: For client-server production databases.

Always use an isolated virtual environment to prevent package conflicts and avoid externally-managed-environment errors on modern operating systems:

macOS / Linux:

Terminal window
python3 -m venv .venv
source .venv/bin/activate

Windows (PowerShell):

Terminal window
python -m venv .venv
.venv\Scripts\Activate.ps1

Windows (Command Prompt):

Terminal window
python -m venv .venv
.venv\Scripts\activate.bat

Kirak includes FastAPI, JWT authentication, GraphQL, and the CLI out of the box. Database drivers are optional extras so you only install what you need.

Run one of the following commands based on your chosen database:

For SQLite (Zero setup / local file):

Terminal window
pip install kirak

— or —

For PostgreSQL (Production):

Terminal window
pip install "kirak[postgres]"

— or —

For MySQL (Production):

Terminal window
pip install "kirak[mysql]"

— or —

For All Database Drivers (CI / Testing):

Terminal window
pip install "kirak[all-databases]"

Verify your installation:

Terminal window
kirak --help

[!IMPORTANT] Database Drivers Are Not Bundled by Plain pip install kirak (Except SQLite)

Running a plain pip install kirak installs the core framework and CLI, but does not bundle network database drivers.

  • SQLite is the only database that works out of the box with plain pip install kirak (its driver is built into the Python standard library).
  • For PostgreSQL or MySQL, you MUST explicitly install your preferred database driver. If you run a plain pip install kirak, you must explicitly install the corresponding driver extra (pip install "kirak[postgres]" or pip install "kirak[mysql]") before running migrations or connecting to your database. Otherwise, Kirak halts with database_driver_not_installed.

The kirak new command scaffolds a complete project directory. Specify your target database engine with --database:

SQLite:

Terminal window
kirak new my-api --database sqlite
cd my-api
pip install -e .

PostgreSQL:

Terminal window
kirak new my-api --database postgres
cd my-api
pip install -e .

MySQL:

Terminal window
kirak new my-api --database mysql
cd my-api
pip install -e .

The scaffold creates the following structure:

my-api/
+-- main.py # Application entry point
+-- kirak.json # Project manifest (modules, database, CORS)
+-- .env.example # Template of secrets required by your manifest
+-- .gitignore
+-- pyproject.toml # Project metadata
+-- AGENTS.md # Guide for AI coding agents
+-- KIRAK.md # Project doc for AI coding agents
+-- CLAUDE.md # Imports AGENTS.md and KIRAK.md for Claude Code
+-- GEMINI.md # Imports AGENTS.md and KIRAK.md for Gemini CLI
+-- .kirak/ # JSON Schemas for editor validation and autocompletion
+-- .vscode/
| +-- settings.json # VS Code schema mappings
+-- models/
| +-- posts.json # Starter data model (one model per JSON file)
+-- src/ # Your Python: hooks, agent tools, routes, tasks, providers
| +-- __init__.py # register(kirak), run by main.py once Kirak is ready
| +-- hooks.py # Lifecycle hooks for custom business logic
+-- migrations/ # Auto-generated SQL migrations

4. Understand the Project Manifest (kirak.json)

Section titled “4. Understand the Project Manifest (kirak.json)”

kirak.json is your application’s control plane. It configures the runtime environment, enabled modules, network security, authentication behavior, and database connection settings.

Open kirak.json in your project root:

{
"$schema": ".kirak/manifest.schema.json",
"version": "1.0.0",
"title": "my-api",
"description": "API built with Kirak Runtime",
"project_name": "my-api",
"base_url": "http://localhost:8000",
"log_level": "INFO",
"modules": [],
"database": {
"type": "sqlite",
"name": "my_api.db"
},
"cors": {
"enabled": true,
"allow_credentials": true,
"allow_methods": ["*"],
"allow_headers": ["*"],
"origins": [
"http://localhost:3000",
"http://localhost:5173"
]
},
"auth": {
"jwt_algorithm": "HS256",
"access_token_expire_minutes": 15,
"refresh_token_expire_days": 14,
"social_providers": []
},
"rate_limit": {
"enabled": true,
"default_max_requests": 100,
"default_window_seconds": 60
}
}
Section Purpose Common Customizations
Root Metadata Application identity and logging Change API title, version, base_url, log_level, or set project_name (shown in authenticator apps and SMS texts).
modules Pluggable module activation Opt into built-in features by listing them: ["storage", "notifications", "payments", "scheduler", "ai", "integrations", "vector", "mcp"].
database Engine and connection pool settings Switch between sqlite, postgres, or mysql; adjust pool_min and pool_max (passwords stay in .env as DB_PASSWORD).
cors Cross-Origin Resource Sharing Whitelist frontend client origins (Next.js, Vite, React, Vue, mobile apps) in origins, or match subdomains using allow_origin_regex.
auth Token lifecycles and login features Tune access token expiration (access_token_expire_hours or minutes), refresh token rotation, cookie settings, and enable social OAuth logins (social_providers).
rate_limit Global API traffic throttling Adjust default request quotas (e.g. 100 requests per 60s per IP) and declare trusted_proxy_ips for reverse proxies (Nginx, Cloudflare, AWS ALB).
  1. Activate Production Features Without Boilerplate: Want cloud file storage, background jobs, or AI chat? Add "storage", "scheduler", or "ai" to "modules": []. Kirak automatically mounts their endpoints, runs required internal migrations, and exposes their Python SDK methods.
  2. Control Security & Access Centrally: Keep all non-secret security rules in one place: CORS whitelists, rate-limit thresholds, and JWT expiration windows. No scattered middleware files to maintain.
  3. Customize URL Routes: Add a "routes" block to prefix all CRUD endpoints (e.g. "crud_prefix": "/api/v1"), rebrand auth endpoints ("auth_prefix": "/auth"), or remap module paths (e.g. "module_prefixes": {"payments": "/billing"}).
  4. Environment Overrides with kirak.local.json: kirak.json is committed to version control and shared across your team. For settings that differ on your local machine (such as a local database port or frontend test URL), create an optional kirak.local.json next to it. Kirak merges kirak.local.json over kirak.json at startup.

Validate your manifest anytime with:

Terminal window
kirak validate manifest

For the complete schema specification, see the Configuration Reference.


Kirak enforces a strict separation between configuration and secrets:

  • Configuration (table names, CORS origins, ports, rate limits) belongs in kirak.json.
  • Secrets (passwords, JWT keys, encryption keys) belong in .env.

Copy the example environment file:

macOS / Linux:

Terminal window
cp .env.example .env

Windows (PowerShell):

Terminal window
Copy-Item .env.example .env

Windows (Command Prompt):

Terminal window
copy .env.example .env

Open .env in your editor and configure your secrets:

# Database password (not needed for SQLite)
DB_PASSWORD=your-database-password
# Auth JWT Secret -- required; startup fails fast if missing or shorter than 32 bytes
KIRAK_AUTH_JWT_SECRET_KEY=replace-this-with-a-32-byte-or-longer-secret-key
# Optional: Dedicated key for signing refresh tokens (defaults to the key above)
# KIRAK_AUTH_JWT_REFRESH_SECRET_KEY=another-32-byte-secret-for-production
# Email verification and password reset encryption key -- required for auth
KIRAK_AUTH_VERIFICATION_KEY=your-fernet-key-here

Generate a secure Fernet key with this one-liner:

Terminal window
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

Tip (Using SQLite): If you selected SQLite, the database file is managed locally. You can leave DB_PASSWORD blank or omit it entirely; SQLite only requires KIRAK_AUTH_JWT_SECRET_KEY and KIRAK_AUTH_VERIFICATION_KEY.

Run the built-in environment validator to confirm all required secrets are configured properly:

Terminal window
kirak env

kirak env checks your .env against the requirements declared in kirak.json and tells you whether any required secret is missing.


Open models/posts.json. Kirak scaffolds a starter posts model:

{
"$schema": "../.kirak/model.schema.json",
"table": "posts",
"soft_delete": true,
"schema": {
"title": { "type": "string", "required": true },
"content": { "type": "text" },
"user_id": { "type": "integer", "required": true }
},
"access": {
"fetch": [{ "role": "user", "condition": "user_id = {user_id}" }, { "role": "admin" }],
"search": [{ "role": "user", "condition": "user_id = {user_id}" }, { "role": "admin" }],
"count": [{ "role": "user", "condition": "user_id = {user_id}" }, { "role": "admin" }],
"exists": [{ "role": "user", "condition": "user_id = {user_id}" }, { "role": "admin" }],
"create": [{ "role": "user", "condition": "user_id = {user_id}" }, { "role": "admin" }],
"update": [{ "role": "user", "condition": "user_id = {user_id}" }, { "role": "admin" }],
"delete": [{ "role": "user", "condition": "user_id = {user_id}" }, { "role": "admin" }],
"destroy": [{ "role": "admin" }],
"restore": [{ "role": "admin" }]
}
}

Kirak is a declarative runtime, not a code generator. You describe your models and permissions in JSON, and Kirak mounts the entire API dynamically:

flowchart LR
subgraph Repo["Your Repository"]
M["models/*.json<br/>(Schema & Access)"]
K["kirak.json<br/>(Config & Modules)"]
H["src/*.py<br/>(Custom Logic)"]
end
subgraph Runtime["Kirak Engine (FastAPI)"]
E["CRUD & GraphQL Engine"]
A["Built-in Auth System"]
R["Row-Level Security (RLS)"]
end
subgraph Output["Auto-Served API"]
API["REST Endpoints<br/>(/fetch, /create, etc.)"]
DOCS["GET /docs & /openapi.json"]
end
Repo --> Runtime
Runtime --> Output
  1. Runtime-Managed Fields: Never define id, created_at, updated_at, or deleted_at. Kirak automatically creates and maintains these columns on every table.
  2. Built-in Auth Tables: users, auth_tokens, auth_social, and auth_mfa are managed by Kirak Core. You do not define them in models/.
  3. Data Schema vs. Access Policy:
    • "schema" declares data types and constraints.
    • "access" declares granular role-based permissions and row-level security (RLS).
  4. Ownership Injection: Notice "condition": "user_id = {user_id}" on create. Kirak automatically reads user_id from the caller’s verified JWT and injects it into the insert statement, preventing callers from spoofing other users’ IDs.

Validate your models anytime with:

Terminal window
kirak validate models

kirak db init generates and applies SQL tables, but on client-server databases the database itself must exist first:

  • SQLite: No setup required. SQLite creates the database file automatically when the migration runs.
  • PostgreSQL: Create the database named in kirak.json (database.name, default my_api):
    Terminal window
    createdb my_api
    # Or in psql: CREATE DATABASE my_api;
  • MySQL: Create the database named in kirak.json (database.name, default my_api):
    Terminal window
    mysql -u root -p -e "CREATE DATABASE my_api CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
    kirak new writes the app user my_api_app into database.user. Create it with rights on that database only, and put its password in .env as DB_PASSWORD:
    Terminal window
    mysql -u root -p -e "CREATE USER 'my_api_app'@'%' IDENTIFIED BY 'choose-a-password'; GRANT ALL PRIVILEGES ON my_api.* TO 'my_api_app'@'%';"
Terminal window
kirak db init

Output:

Created: migrations/20260801100000_initial.sql
Snapshot: migrations/models_snapshot.json
Applying migration...
Done -- 1 applied, 0 already applied.

The migration generates DDL sections for MySQL, PostgreSQL, and SQLite; Kirak automatically runs only the section matching your configured database.type.


The generated main.py is minimal:

from dotenv import load_dotenv
load_dotenv()
from kirak import create_kirak_app
from src import register
app = create_kirak_app(
models_path="./models/",
on_kirak_ready=register,
)

register (in src/__init__.py) registers the project’s hooks, tools, routes and tasks once Kirak is ready.

Start the application with Uvicorn:

Terminal window
kirak run

The server starts on http://localhost:8000 with hot-reload enabled.


  • http://localhost:8000/docs: Describes the running API in Markdown (tailored for AI coding agents and human inspection).
  • http://localhost:8000/openapi.json: Standard OpenAPI 3.0 specification for API clients (Postman, Bruno, Insomnia).

In a new terminal window, register a test user:

Terminal window
curl -X POST http://localhost:8000/auth/register \
-H "Content-Type: application/json" \
-d '{"email": "alice@example.com", "password": "Secret!Pass123", "first_name": "Alice", "last_name": "Smith"}'

Important — Check Your Server Terminal Log: Kirak requires email verification before allowing a user to log in (403 EMAIL_NOT_VERIFIED).

In a newly scaffolded project without a cloud notification provider enabled, Kirak automatically prints the verification link to the terminal running Uvicorn:

[kirak] No verification email was sent for alice@example.com. Open this link to verify the account:
http://localhost:8000/auth/verify-email?token=...

Copy and open that link in your browser, then press Verify my email to mark Alice’s account as verified before logging in.


Once verified, log in to obtain JWT access and refresh tokens:

Terminal window
curl -X POST http://localhost:8000/auth/login \
-H "Content-Type: application/json" \
-d '{"email": "alice@example.com", "password": "Secret!Pass123"}'

Response:

{
"statusCode": 200,
"status": "success",
"message": "Login successful",
"data": {
"user": { "user_id": 1, "email": "alice@example.com", "role": "user" },
"accessToken": "eyJhbGciOi...",
"refreshToken": "eyJhbGciOi...",
"expiresIn": 3600
}
}

Save the accessToken to an environment variable in your client terminal:

macOS / Linux (Bash/Zsh):

Terminal window
export TOKEN="your-access-token-here"

Windows (PowerShell):

Terminal window
$TOKEN = "your-access-token-here"

Windows (Command Prompt):

Terminal window
set TOKEN=your-access-token-here

Notice that you do not supply user_id; Kirak injects it from the JWT:

macOS / Linux:

Terminal window
curl -X POST http://localhost:8000/posts/create \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"data": {"title": "Hello Kirak", "content": "My first declared post"}}'

Windows (PowerShell):

Terminal window
curl.exe -X POST "http://localhost:8000/posts/create" `
-H "Authorization: Bearer $TOKEN" `
-H "Content-Type: application/json" `
-d '{"data": {"title": "Hello Kirak", "content": "My first declared post"}}'
Terminal window
curl "http://localhost:8000/posts/fetch?limit=10&page=1" \
-H "Authorization: Bearer $TOKEN"

Search across all fields marked "searchable": true with the search parameter:

Terminal window
curl "http://localhost:8000/posts/search?search=Kirak" \
-H "Authorization: Bearer $TOKEN"

Update a Post (Row-Level Security Enforced)

Section titled “Update a Post (Row-Level Security Enforced)”

A user can only update their own posts:

Terminal window
curl -X PUT http://localhost:8000/posts/update \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"where": {"id": 1}, "data": {"title": "Updated Title"}}'

Sets deleted_at, making the record immediately invisible to all queries:

Terminal window
curl -X DELETE "http://localhost:8000/posts/delete?id=1" \
-H "Authorization: Bearer $TOKEN"

Hooks allow you to execute custom Python code before or after any CRUD or authentication event without modifying framework internals.

Open src/hooks.py and implement an after_create hook:

def register(kirak):
@kirak.on("posts").hook("after_create")
async def after_post_created(result):
# result contains the full response dict
post_id = result["data"]["id"]
print(f"[HOOK] Post {post_id} was successfully created!")
return result # Always return the result to continue the pipeline

main.py already runs it: it passes register from src/__init__.py as on_kirak_ready, and that calls hooks.register(kirak). New modules (agent tools, routes, scheduler tasks) go next to hooks.py and are called from the same register.

Restart the server and create a post. You will see the hook output logged in your terminal.


Kirak modules (Payments, Notifications, Storage, AI, Scheduler) are opt-in. Enable them by listing them in kirak.json:

{
"modules": ["storage", "payments", "notifications"]
}

Install the corresponding package extra for the providers you need. Common examples:

  • Local & S3 Storage: pip install "kirak[storage]"
  • Square Payments: pip install "kirak[payments-square]"
  • OpenAI Integration: pip install "kirak[ai-openai]"
Full Table of Optional Module Extras (33 Providers) — Click to Expand
Module / Provider Install Command
MFA (TOTP Authenticator Apps) pip install "kirak[mfa]"
Notifications (AWS SES Email) pip install "kirak[notifications-ses]"
Notifications (AWS SNS SMS) pip install "kirak[notifications-sns]"
Notifications (Twilio SMS) pip install "kirak[notifications-twilio]"
Notifications (Apple APNs Push) pip install "kirak[notifications-apn]"
Notifications (SendGrid, Mailgun, SMTP, FCM, Slack, Telegram) Built-in, no extra install required
Notifications (All Providers Bundle) pip install "kirak[all-notifications]"
Payments (Razorpay) pip install "kirak[payments-razorpay]"
Payments (Square) pip install "kirak[payments-square]"
Payments (Stripe, Stripe Connect, PayPal, Paddle, Paystack, Flutterwave, Mercado Pago) Built-in, no extra install required
Payments (All Providers Bundle) pip install "kirak[all-payments]"
Storage (Local, AWS S3, Cloudflare R2, DigitalOcean Spaces, Wasabi) pip install "kirak[storage]"
Storage (Google Cloud Storage) pip install "kirak[storage-gcs]"
Storage (Azure Blob Storage) pip install "kirak[storage-azure]"
Storage (All Storage Providers) pip install "kirak[all-storage]"
AI (OpenAI) pip install "kirak[ai-openai]"
AI (Anthropic) pip install "kirak[ai-anthropic]"
AI (Google Gemini) pip install "kirak[ai-google]"
AI (All AI Providers) pip install "kirak[all-ai]"
AI (MCP Servers as Agent Toolsets) pip install "kirak[ai-mcp]"
Vector (Pinecone, OpenAI / Gemini Embeddings) Built-in, no extra install required
Vector (Amazon S3 Vectors) pip install "kirak[vector-s3vectors]"
Vector (All Vector Providers) pip install "kirak[all-vector]"
Scheduler (Redis Queue) pip install "kirak[scheduler-redis]"
Scheduler (RabbitMQ Queue) pip install "kirak[scheduler-rabbitmq]"
Scheduler (All Queue Backends) pip install "kirak[all-scheduler]"
Monitoring (RED Metrics) pip install "kirak[monitoring]"
Redis (Rate Limiting, Session Blacklists, OTP) pip install "kirak[redis]"
MCP Module (Serving MCP Tools) pip install "kirak[mcp]"
Everything Bundle (All extras + both DB drivers) pip install "kirak[all]"

Kirak runs anywhere Python does. To share the API without setting up a server, kirak deploy puts the project on Kirak’s hosting in one command, with no account and no email:

Terminal window
kirak deploy
Deployed: https://<your-app>...
Claim URL: https://...
Run 'kirak deploy claim-code' to retrieve your claim code.

The deploy runs kirak validate first, sends the project’s files (never .env or kirak.local.json) and its secrets from .env, and prints the public URL. It also prints:

  • A claim link. An unclaimed instance is temporary. Open the link, sign in, and enter the 8-character claim code from kirak deploy claim-code to make the instance yours and keep it running. After five wrong codes the claim locks; kirak deploy claim-code --new makes a new code and unlocks it.
  • Custom Python, when the project has Python files other than main.py: until the claim, custom endpoints answer 403 INSTANCE_NOT_CLAIMED, and hooks, tools and tasks do not run. The output gives the file count.
  • When it expires, while it is unclaimed, and anything an unclaimed instance does not run yet.

Run kirak deploy again from the same folder to update the same instance: the CLI keeps its state in .kirak/project.json (commit it) and its credentials in .kirak/deploy.json (never commit it; the CLI adds it to .gitignore). After claiming, kirak login lets you deploy from any machine.

How long an unclaimed instance lives, and what the free tier includes: kirak.io/deploy. Every option of the command: kirak deploy.


Topic Guide
Step-by-step tutorial building a custom Task Manager API First API Tutorial
Field types, relationships, indexes, and custom validation Defining Models
Filters, sorting, pagination, and bulk batch operations CRUD Operations
Role-based access control and row-level ownership rules Access Control
Full lifecycle hooks for operations and authentication Hooks & Events
Configuration keys and environment variables Configuration Reference