If you like Klotho, give it a star on GitHub!

Klotho 2.0

Terraform/CDK alternative designed for developers

Describe what your application needs in the way you think about it, Klotho does the rest

CLI Version Python IaC SDK

Think like an application architect

Describe how your application needs to work, not how it should be implemented

Think

I want my profile service to run in a container, that reads data from a Postgres database and is exposed as an API.

Write

How to think like an architect

Get

How to think like an architect

High-level building blocks and interactions

lambda_functions.py

1
# Define a Lambda function for handling profiles
2
profile_lambda = Compute.Function(
3
name="profile_lambda",
4
handler="apps/profile.handler",
5
)
6
# Create a PostgreSQL database for storing profiles
7
profiles_database = Databases.Postgres(name="profiles_db")
8
9
# Grant the profile Lambda read access to the profiles database
10
profile_lambda.reads_from(profiles_database)

Out-of-the-box open source frameworks built-in

Use Next.js, Django, Svelte, Astro with zero config, and easily add your own

infra.py

1
# Next.js service
2
nextjs_service = Frameworks.NextJS(
3
name="nextjs-app",
4
context="./nextjs-app"
5
)

Mix serverless and serverful technologies freely

lambda_functions.py

1
# Define a Lambda function for handling profiles
2
profile_lambda = Compute.Function(
3
name="profile_lambda",
4
handler="apps/profile.handler",
5
)
6
# Create a PostgreSQL database for storing profiles
7
profiles_database = Databases.Postgres(name="profiles_db")
8
9
# Grant the profile Lambda read access to the profiles database
10
profile_lambda.reads_from(profiles_database)

Easy domain and API routing

api_config.py

1
# Create a new API
2
mysite_api = API(name="mysite-api")
3
4
# Attach the profile Lambda function to the "/api/profiles" route
5
mysite_api.attach_service(profile_lambda, route="/api/profiles")
6
7
# Attach the OCR service to the "/api/ocr" route
8
mysite_api.attach_service(ocr, route="/api/ocr")
9
10
# Expose the API on this domain
11
domain = Domain(name="mysite.com", exposes=mysite_api)

Multi-repo support

github.com/kentoso/invoices-service/infra.py

1
# 'kentoso' is the global the project name
2
klotho.Application("billing-service", project="kentoso")
3
4
# Define a Lambda function for handling profiles
5
Compute.Function(
6
name="invoice_lambda",
7
handler="src/invoice.handler",
8
)

github.com/kentoso/billing-service/infra.py

1
# The same 'kentoso' project
2
klotho.Application("billing-service", project="kentoso")
3
4
# Import invoice lambda from github.com/kentoso/invoices-service
5
invoice_lambda = Compute.Function(from_project=True, name="invoice_lambda")
6
7
# This container is defined in the current repo
8
billing_service = Compute.Container(context="./billing-service")
9
10
# The container we defined in this repo calls the lambda from the other repo
11
billing_service.calls(invoice_lambda, protocol="https")

Use Klotho's runtime SDK

app.py

1
# Import the Klotho SDK
2
import klotho
3
import psycopg2
4
5
# Get the connection details from Klotho's config store
6
users_db = klotho.config.datastores.get("users_db")
7
8
# Use the connection details to connect to the database
9
conn = psycopg2.connect(
10
host=users_db.host,
11
port=users_db.port,
12
dbname=users_db.name,
13
user=users_db.user,
14
password=users_db.password
15
)

Deploy your infrastructure

Deploy your infrastructure

Join our community

1.1K+
Github stars
595+
Discord members
8K+
Subscribers

Our team will support you from POC to Production

Ready to build quickly on AWS?

Start Here