Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .fastlyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__pycache__/
.venv/
.ruff_cache/
/bin
/pkg
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @fastly/developer-relations
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: pip
directory: "/"
schedule:
interval: weekly

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test

on:
pull_request:

defaults:
run:
shell: bash

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository contents
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Format
run: uvx ruff format --check .

- name: Lint
run: uvx ruff check .

- name: Install Fastly CLI
uses: fastly/compute-actions/setup@v13
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Build (using CLI)
uses: fastly/compute-actions/build@v13

- name: Upload WASM package as an artifact
uses: actions/upload-artifact@v7
with:
name: wasm-package
path: bin/main.wasm
if-no-files-found: error
compression-level: 0
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Environments
.venv/
env/
venv/

# Ruff/linters cache
.ruff_cache/

# Fastly Compute build artifacts
/bin/
/pkg/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Fastly

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 0 additions & 2 deletions PLACEHOLDER.md

This file was deleted.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Default Starter Kit for Python

[![Deploy to Fastly](https://deploy.edgecompute.app/button)](https://deploy.edgecompute.app/deploy)

Get to know the Fastly Compute environment with a basic starter that demonstrates routing, simple synthetic responses and code comments that cover common patterns.

**For more details about this and other starter kits for Compute, see the [Fastly Documentation Hub](https://www.fastly.com/documentation/solutions/starters/)**.

## Features

- Shows use of [WSGI][wsgi] to handle requests
- Shows dependency management with [`uv`][uv] via `pyproject.toml`
- Uses [Flask][flask] from [PyPI][pypi] for basic request routing and handling
- Build synthetic responses at the edge

## Understanding the code

This starter kit is intentionally fairly minimal; while Flask is included as a dependency alongside the [Fastly Compute SDK for Python][compute-sdk-python], this is meant primarily as a demonstration of use of a lightweight framework that implements the [WSGI][wsgi] interface. [Bottle][bottle] is another popular microframework which may be used. Python services may also be written without any additional framework dependencies.

The starter doesn't require the use of any backends. Once deployed, you will have a Fastly service running on Compute that can generate synthetic responses at the edge.

## Security issues

Please see [SECURITY.md](SECURITY.md) for guidance on reporting security-related issues.

[wsgi]: https://peps.python.org/pep-3333/
[bottle]: https://bottlepy.org/docs/dev/
[uv]: https://docs.astral.sh/uv/
[pypi]: https://pypi.org/
[flask]: https://flask.palletsprojects.com/en/stable/
9 changes: 9 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Report a security issue

The project team welcomes security reports and is committed to providing prompt attention to security issues. Security issues should be reported privately via [Fastly’s security issue reporting process](https://www.fastly.com/security/report-security-issue).

## Security advisories

Remediation of security vulnerabilities is prioritized by the project team. The project team endeavors to coordinate remediation with third-party stakeholders, and is committed to transparency in the disclosure process. The team announces security issues via the [Fastly Developer Hub Starter Kits](https://developer.fastly.com/solutions/starters/) site on a best-effort basis.

Note that communications related to security issues in Fastly-maintained OSS as described here are distinct from [Fastly Security Advisories](https://www.fastly.com/security-advisories).
11 changes: 11 additions & 0 deletions fastly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file describes a Fastly Compute package. To learn more visit:
# https://www.fastly.com/documentation/reference/compute/fastly-toml

authors = []
description = "A basic starter kit that demonstrates routing and simple responses in Python."
language = "python"
manifest_version = 3
name = "fastly-compute-python-app"

[scripts]
build = "uv run fastly-compute-py build"
69 changes: 69 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import os
import pathlib
from flask import Flask
from fastly_compute.wsgi import WsgiHttpIncoming

app = Flask(__name__)

# Module-level functionality executes at build-time as part of
# memory snapshotting; the filesystem is not available at runtime; instead
# execution of the code resumes from this snapshot when an incoming
# request is received, greatly reducing startup costs.
welcome_page_path = pathlib.Path(__file__).parent / "welcome-to-compute.html"
welcome_page = welcome_page_path.read_text(encoding="utf-8")


@app.before_request
def log_service_version():
# Log service version
print(f"FASTLY_SERVICE_VERSION: {os.environ.get('FASTLY_SERVICE_VERSION', '')}")


@app.route("/", methods=["GET"])
def index():
# Below are some common patterns for Compute services using Python.
# Head to https://www.fastly.com/documentation/guides/compute/developer-guides/python/ to discover more.

# 1. Sending HTTP Requests (via requests facade)
# The Fastly SDK for Python provides a requests-compatible facade.
# Outgoing requests can use dynamic backends (by passing a full URL)
# or static backends (by specifying `fastly_backend`).
#
# Example:
# from fastly_compute import requests
#
# # Using dynamic backends:
# resp = requests.get("https://http-me.fastly.dev/get")
#
# # Using a static backend named "example-backend":
# resp = requests.get(
# "https://example.com/api/data",
# headers={"X-Custom-Header": "Welcome!"},
# fastly_backend="example-backend"
# )

# 2. Real-Time Log Streaming (Logging)
# The SDK provides direct integration with Fastly's Real-Time Log Streaming endpoints,
# both via direct endpoint writing and standard Python library logging.
#
# Example 1: Direct endpoint logging
# from fastly_compute.log import LogEndpoint
#
# with LogEndpoint.open("my-log-endpoint") as endpoint:
# endpoint.write("Hello from the edge!")
#
# Example 2: Integration with Python standard library `logging`
# import logging
# from fastly_compute.log import FastlyLogHandler
#
# handler = FastlyLogHandler(default_endpoint="my-log-endpoint")
# logger = logging.getLogger("my-app")
# logger.addHandler(handler)
# logger.info("This is an info-level log message")

return welcome_page, 200, {"Content-Type": "text/html; charset=utf-8"}


# Create the HTTP handler using WSGI; this adapts the Fastly Compute
# platform to the WSGI standard for use with a variety of frameworks.
HttpIncoming = WsgiHttpIncoming(app)
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "fastly-compute-python-app"
version = "0.1.0"
description = "A basic starter kit for Python on Fastly Compute"
requires-python = ">=3.12"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to start with 3.14?

@posborne posborne Jun 16, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll always bundle a WASI CPython 3.14 currently, but this constraint will apply to the developer machine. To a degree, I think we could even relax this further as we only minimally depend on the host setup.

So, this tries to balance:

  • Going to 3.14 will just cause pain for a lot of devs as their host OS doesn't ship with a new enough python.
  • Going older could pick up versions of libs that might not work well on 3.14 (though I haven't concretely proven this).

Python 3.12 is what ships with Ubuntu 24.04 which I did not want to have be broken out of the box as it will still likely be a common developer and CI python version for awhile longer.

dependencies = [
"flask>=3.1.3",
"fastly-compute>=0.1.2",
]

[tool.fastly-compute]
entry = "main"
30 changes: 30 additions & 0 deletions welcome-to-compute.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<title>Welcome to Fastly Compute</title>
<link
rel="icon"
href="https://developer.fastly.com/favicon-32x32.png"
type="image/png"
/>
</head>
<body>
<iframe
src="https://developer.fastly.com/compute-welcome"
style="
border: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
"
></iframe>
</body>
</html>
Loading