Basilica
Python SDK

Deployments

Using the Decorator

import basilica

@basilica.deployment(name="hello", port=8000)
def serve():
    from http.server import HTTPServer, BaseHTTPRequestHandler

    class Handler(BaseHTTPRequestHandler):
        def do_GET(self):
            self.send_response(200)
            self.end_headers()
            self.wfile.write(b'Hello!')

    HTTPServer(('', 8000), Handler).serve_forever()

deployment = serve()
print(f"Live at: {deployment.url}")

Parameters

ParameterTypeDefaultDescription
namestrrequiredDeployment name (DNS-safe)
imagestr"python:3.11-slim"Container image
portint8000Port your app listens on
cpustr"500m"CPU allocation
memorystr"512Mi"Memory allocation
envDict[str, str]NoneEnvironment variables
pip_packagesList[str]NonePip dependencies
replicasint1Number of instances
ttl_secondsintNoneAuto-delete timer
timeoutint300Deploy timeout (seconds)

For GPU options, see GPU Workloads. For persistent storage, see Storage.

DeployedFunction API

serve.spec        # DeploymentSpec configuration
serve.deployment  # Current Deployment (after deploy)
serve()           # Deploy (shorthand for .deploy())
serve.deploy()    # Deploy with default client
serve.local()     # Run locally for testing

Local Testing

@basilica.deployment(name="app", port=8000)
def serve():
    print("Starting server...")

serve.local()  # Runs locally, doesn't deploy

Using client.deploy()

Use for existing files, pre-built images, or dynamic scenarios.

from basilica import BasilicaClient

client = BasilicaClient()

deployment = client.deploy(
    name="my-app",
    source="app.py",
    port=8000,
    pip_packages=["fastapi", "uvicorn"],
)

Source Options

# File path
client.deploy(name="app", source="app.py", port=8000)

# Inline code
client.deploy(name="app", source="print('hello')", port=8000)

# Image only (no source)
client.deploy(name="nginx", image="nginx:alpine", port=80)

Deployment Object

Every deployment returns a Deployment object:

PropertyTypeDescription
urlstrPublic URL
namestrDeployment name
statestrCurrent state
namespacestrKubernetes namespace
user_idstrOwner's user ID
created_atdatetimeCreation timestamp

Methods

deployment.status()           # Get detailed status
deployment.logs()             # Get container logs
deployment.logs(tail=50)      # Last 50 lines
deployment.delete()           # Delete deployment
deployment.wait_until_ready() # Wait for ready state

Status Details

status = deployment.status()
print(f"State: {status.state}")
print(f"Ready: {status.replicas_ready}/{status.replicas_desired}")

Status properties: state, phase, replicas_ready, replicas_desired, is_ready, is_failed, is_pending.

Management

# Get deployment by name
deployment = client.get("my-app")

# List all deployments
for d in client.list():
    print(f"{d.name}: {d.state}")

# Delete
deployment.delete()

Next Steps

On this page