Skip to content

Commit 7c60806

Browse files
committed
docs: Add Shuttle Python documentation
1 parent 9affbbf commit 7c60806

File tree

10 files changed

+1648
-168
lines changed

10 files changed

+1648
-168
lines changed

docs.json

Lines changed: 249 additions & 168 deletions
Large diffs are not rendered by default.
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
title: "Shuttle Architecture"
3+
description: "Understand how Shuttle's infrastructure-from-code platform works under the hood"
4+
icon: "building"
5+
---
6+
7+
## Overview
8+
9+
Shuttle is designed around a fundamental principle: **Infrastructure from Code**. Unlike traditional platforms where you configure infrastructure separately from your application code, Shuttle provisions and manages infrastructure directly from your Python code using type hints and decorators.
10+
11+
## Core Architecture
12+
13+
### The Shuttle Runtime
14+
15+
At the heart of Shuttle is how your application's entrypoint is handled, typically using `shuttle_runtime.main(your_function)` or a decorated function like `@shuttle_task.cron`. This approach:
16+
17+
- **Analyzes your code** to understand what resources you need
18+
- **Provisions infrastructure** automatically based on your type hints and resource options
19+
- **Handles deployment lifecycle** including startup, shutdown, and health checks
20+
- **Manages resource connections** and provides them to your application
21+
22+
```python
23+
import shuttle_runtime
24+
import shuttle_task
25+
from shuttle_aws.s3 import Bucket, BucketOptions
26+
from shuttle_aws.rds import RdsPostgres, RdsPostgresOptions
27+
from typing import Annotated
28+
29+
@shuttle_task.cron(schedule="0 3 * * ? *")
30+
async def run(
31+
bucket: Bucket: Annotated[
32+
Bucket, BucketOptions(bucket_name="my-bucket", policies=[])
33+
],
34+
db: Annotated[RdsPostgres, RdsPostgresOptions()],
35+
):
36+
# Your app code here - infrastructure is ready
37+
pass
38+
```
39+
40+
### Resource Provisioning System
41+
42+
Shuttle's resource system works through a combination of:
43+
44+
1. **Code Analysis**: Shuttle scans your code for type hints and resource options
45+
2. **Infrastructure Planning**: The platform determines what resources to provision
46+
3. **Automatic Provisioning**: Resources are created and configured
47+
4. **Runtime Injection**: Live connections are provided to your application
48+
49+
This approach eliminates the need for:
50+
51+
- Manual infrastructure configuration
52+
- Environment-specific connection strings
53+
- Complex deployment scripts
54+
- Infrastructure-as-code templates
55+
56+
### Deployment Pipeline
57+
58+
When you run `shuttle deploy`, here's what happens:
59+
60+
1. **Code Archive**: Your project is bundled and uploaded
61+
2. **Build Phase**: Dependencies are installed and code is prepared in a secure build environment
62+
3. **Resource Analysis**: The runtime analyzes required resources
63+
4. **Infrastructure Provisioning**: Resources are created or updated
64+
5. **Container Deployment**: Your app is deployed to AWS ECS (Fargate)
65+
6. **Health Checks**: The platform verifies deployment success
66+
67+
### Isolation and Security
68+
69+
Each Shuttle project runs in its own:
70+
71+
- **ECS Service**: Dedicated compute isolation
72+
- **Resource Namespace**: Logical separation of databases, secrets, etc.
73+
- **Network Context**: Isolated networking and security groups
74+
75+
## Design Principles
76+
77+
### Developer Experience First
78+
79+
Shuttle prioritizes developer productivity by:
80+
81+
- Reducing boilerplate and configuration
82+
- Providing immediate feedback during development
83+
- Abstracting infrastructure complexity
84+
- Maintaining familiar Python development patterns
85+
86+
### Infrastructure Transparency
87+
88+
While Shuttle abstracts infrastructure management, it maintains transparency by:
89+
90+
- Providing clear resource information in the console
91+
- Offering detailed deployment logs
92+
- Supporting custom resource configurations when needed
93+
- Maintaining compatibility with standard Python libraries and frameworks
94+
95+
### Scalability by Design
96+
97+
The architecture supports growth through:
98+
99+
- Automatic resource scaling based on usage
100+
- Support for custom resource configurations
101+
- Integration with external services and databases
102+
- Multi-region deployment capabilities (Enterprise)
103+
104+
## Comparison with Traditional Approaches
105+
106+
### Traditional Deployment
107+
108+
```
109+
Code → Docker Image → Kubernetes/Docker Compose → Infrastructure Config → Deploy
110+
```
111+
112+
### Shuttle Approach
113+
114+
```
115+
Annotated Code → shuttle deploy → Running Application
116+
```
117+
118+
This simplified flow reduces complexity while maintaining full control over your application logic.
119+
120+
## Resource Lifecycle
121+
122+
Resources in Shuttle follow a managed lifecycle:
123+
124+
1. **Declaration**: Resources are declared via type hints and decorators in your code
125+
2. **Provisioning**: First deployment creates the resource
126+
3. **Persistence**: Resources persist across deployments
127+
4. **Management**: Resources can be managed via CLI or console
128+
5. **Cleanup**: Resources are cleaned up when projects are deleted
129+
130+
This lifecycle ensures that your data persists while your application code evolves.
131+
132+
## Understanding the Platform Benefits
133+
134+
Shuttle's architecture provides several key advantages:
135+
136+
- **Faster Development**: No infrastructure setup time
137+
- **Reduced Complexity**: Infrastructure and application code in one place
138+
- **Better Reliability**: Managed infrastructure with automatic scaling
139+
- **Cost Efficiency**: Pay only for what you use, automatic optimization
140+
- **Security**: Built-in best practices and managed updates
141+
142+
Understanding these architectural principles helps you make the most of Shuttle's capabilities and design applications that leverage the platform's strengths.
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
---
2+
title: "Infrastructure from Code"
3+
description: "Deep dive into Shuttle's Infrastructure from Code philosophy and how it differs from traditional approaches"
4+
icon: "code"
5+
---
6+
7+
## What is Infrastructure from Code?
8+
9+
Infrastructure from Code (IfC) is Shuttle's foundational approach where infrastructure requirements are expressed directly in your application code through language-native constructs like type hints, attributes, or decorators, rather than in separate configuration files or management consoles.
10+
11+
## The Philosophy
12+
13+
Traditional cloud development often separates concerns:
14+
15+
- **Application Logic**: Your business code
16+
- **Infrastructure Configuration**: YAML files, Terraform, CloudFormation
17+
- **Deployment Scripts**: CI/CD pipelines, Docker configurations
18+
19+
This separation, while architecturally sound, can introduce friction:
20+
21+
- Context switching between code and infrastructure definitions.
22+
- Synchronization challenges between different environments.
23+
- Complex dependency management.
24+
- A higher barrier to entry for new developers.
25+
26+
Shuttle's Infrastructure from Code collapses this complexity by enabling you to express infrastructure needs directly alongside where they are used in your application code.
27+
28+
## How Shuttle's IfC Works
29+
30+
At its core, IfC means that your application code becomes the single source of truth for both your business logic and your infrastructure requirements.
31+
32+
### 1. Declarative Resource Requirements
33+
34+
You declare the resources your application needs directly in your code, typically as function parameters or class members, using language-native features. Shuttle then interprets these declarations to provision the necessary cloud infrastructure.
35+
36+
For example, you might declare a database, a storage bucket, or a secret manager entry. Shuttle understands these declarations and handles the provisioning, configuration, and injection of the actual resources into your running application.
37+
38+
### 2. Automatic Lifecycle Management
39+
40+
When you deploy your application with Shuttle:
41+
42+
- **Provisioning**: Required resources are automatically created on first deployment.
43+
- **Persistence**: Resources like databases or storage buckets persist across deployments, maintaining their state.
44+
- **Management**: Shuttle manages updates, backups, and scaling of these resources where applicable.
45+
- **Cleanup**: Resources are automatically torn down when they are no longer declared in your code, preventing orphaned infrastructure.
46+
47+
## IfC vs. Traditional Infrastructure Provisioning
48+
49+
To illustrate the difference, consider provisioning a PostgreSQL database for your application:
50+
51+
### Traditional Approach Example
52+
53+
With traditional methods, you'd define your infrastructure in separate files and manage environment variables:
54+
55+
```yaml
56+
# docker-compose.yml or similar IaC tool
57+
services:
58+
database:
59+
image: postgres:13
60+
environment:
61+
POSTGRES_DB: myapp
62+
POSTGRES_USER: user
63+
POSTGRES_PASSWORD: password
64+
65+
app:
66+
build: .
67+
depends_on:
68+
- database
69+
environment:
70+
DATABASE_URL: postgres://user:password@database:5432/myapp
71+
```
72+
73+
And your application code would retrieve the connection string from environment variables:
74+
75+
```python
76+
# Your app code
77+
import os
78+
import psycopg
79+
from psycopg_pool import ConnectionPool
80+
81+
DATABASE_URL = os.environ.get("DATABASE_URL")
82+
if not DATABASE_URL:
83+
raise ValueError("DATABASE_URL environment variable is not set")
84+
85+
pool = ConnectionPool(DATABASE_URL)
86+
# ... use pool to interact with the database ...
87+
```
88+
89+
This approach requires manual synchronization between the infrastructure definition and the application's environment variable consumption.
90+
91+
### Infrastructure from Code in Python Example
92+
93+
With Shuttle's IfC in Python, the database requirement is expressed directly in your application code:
94+
95+
```python
96+
from typing import Annotated
97+
98+
import shuttle_runtime
99+
import shuttle_task
100+
from shuttle_aws.s3 import Bucket, BucketOptions, AllowWrite
101+
from shuttle_aws.rds import RdsPostgres, RdsPostgresOptions
102+
from shuttle_runtime import Secrets
103+
104+
@shuttle_task.cron(schedule="0 3 * * ? *")
105+
async def run(
106+
# Dedicated AWS RDS Postgres with custom options
107+
production_db: Annotated[
108+
RdsPostgres,
109+
RdsPostgresOptions(
110+
database_name="prod_metrics",
111+
allocated_storage_gb=20,
112+
),
113+
],
114+
# Dedicated AWS S3 Bucket with write permissions
115+
data_bucket: Annotated[Bucket,
116+
BucketOptions(
117+
bucket_name="my-app-data-bucket-unique", # Must be globally unique
118+
policies=[
119+
AllowWrite(
120+
account_id="123456789012", # Example AWS account ID
121+
role_name="MyExternalServiceRole",
122+
),
123+
],
124+
),
125+
],
126+
# A secret automatically managed by Shuttle
127+
secrets: Secrets,
128+
):
129+
# All resources are ready to use as function arguments
130+
print(f"Connected to production DB host: {production_db.get_connection().dsn}")
131+
print(f"Data bucket name: {data_bucket.options.bucket_name}")
132+
print(f"Secrets available: {secrets.get('MY_SECRET')}")
133+
```
134+
135+
In this Python example, `RdsPostgres` and `Bucket` are type hints that tell Shuttle what resources are needed. The `Annotated` type allows for additional configuration (e.g., `RdsPostgresOptions`). Shuttle automatically provisions these resources and injects fully configured, ready-to-use instances into your function at runtime.
136+
137+
## Developer Experience & Efficiency
138+
139+
### Unified Codebase for App & Infra
140+
141+
Infrastructure requirements are defined directly within your application code using type hints and decorators. This creates a single source of truth, eliminating the need for separate configuration files (like Terraform or CloudFormation) and reducing context switching.
142+
143+
- **Version Control**: Since infrastructure is code, all changes to your application and its underlying resources are tracked together in version control, simplifying collaboration, code reviews, and rollbacks.
144+
145+
With commands like `shuttle deploy`, `shuttle logs`, and `shuttle destroy`, the platform automatically provisions, updates, and tears down resources. The CLI provides immediate, human-readable feedback (diffs) on planned infrastructure changes, ensuring consistency and reproducibility across environments.
146+
147+
### Enhanced Local Development
148+
149+
## Limitations and Considerations
150+
151+
### When IfC Might Not Be Ideal and Working Within Constraints
152+
153+
Infrastructure from Code may not be ideal in scenarios such as complex multi-service architectures not fully managed by Shuttle, strict compliance requirements that demand external auditing of infrastructure, legacy system integration, or highly diverse multi-language environments where a common IaC tool might be preferred. In these cases, consider:
154+
155+
- **Hybrid Approaches**: Integrating Shuttle-managed parts with external infrastructure definitions managed by traditional IaC tools.
156+
- **Custom Resources**: For complex infrastructure needs not directly supported by Shuttle's built-in types, you might define them externally and integrate them into your Shuttle project.
157+
- **Traditional IaC**: Combining Shuttle with traditional Infrastructure as Code tools for legacy components or highly specialized requirements that fall outside Shuttle's immediate scope.
158+
159+
## The Future of Infrastructure from Code
160+
161+
As AI and machine learning technologies advance, they are poised to revolutionize Infrastructure from Code by making it even more approachable and efficient. AI tools combined with succinct syntax will lower the barrier to entry for developers, making it easier to manage infrastructure through code.
162+
163+
- **AI-Enhanced Tooling**: AI will enable more intuitive interaction with infrastructure, allowing developers to focus on application logic rather than complex configurations.
164+
- **Streamlined Orchestration**: With AI-driven command-line tools, orchestrating infrastructure provisioning will become more streamlined, reducing the need for verbose commands.
165+
- **Short Context Prompting**: AI will enhance the accuracy of infrastructure management tasks by understanding short context prompts, improving over verbose and error-prone infrastructure tools.
166+
167+
Understanding Infrastructure from Code helps you leverage Shuttle's full potential and design applications that are both powerful and maintainable.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "CLI Installation"
3+
description: "How to install the Python-based Shuttle Command Line Interface (CLI) using uv"
4+
icon: "download"
5+
---
6+
7+
## <span style={{ fontWeight: 600 }}>Using Shuttle within your projects</span>
8+
9+
<span style={{ fontSize: '1.1em', fontWeight: 500 }}>
10+
For managing dependencies and running Shuttle commands within your projects, it is recommended to use `uv` directly.
11+
</span>
12+
13+
1. <b>Create a Virtual Environment</b>
14+
15+
Navigate to your project directory and create a virtual environment with `uv`.
16+
17+
<CodeBlock language="bash" expanded>
18+
uv venv
19+
source .venv/bin/activate
20+
</CodeBlock>
21+
22+
2. <b>Add Shuttle Dependency</b>
23+
24+
Add the `shuttle` package to your project's dependencies.
25+
26+
<CodeBlock language="bash" expanded>
27+
uv init
28+
uv add shuttle-python
29+
</CodeBlock>
30+
31+
3. <b>Run Shuttle Commands</b>
32+
33+
Execute Shuttle commands using `uv run -m shuttle` to ensure they run within your project's isolated environment.
34+
35+
<CodeBlock language="bash" expanded>
36+
uv run -m shuttle deploy
37+
uv run -m shuttle logs
38+
uv run -m shuttle local
39+
</CodeBlock>
40+
41+
Alternatively, if you are activated in your virtual environment, you can use the `shuttle` script.
42+
43+
<CodeBlock language="bash" expanded>
44+
shuttle deploy
45+
shuttle logs
46+
shuttle local
47+
</CodeBlock>
48+

0 commit comments

Comments
 (0)