Skip to main content

Python SDK for Fastly Compute

Project description

Fastly Compute Python SDK

Experimental Python SDK for Fastly Compute services.

Highlights

  • Support for WSGI Frameworks. Flask and Bottle examples are included for reference.
  • Access from Python to Fastly's API
  • Full type hints and IDE support

Quick Start

Install Dependencies

To work with fastly-compute in Python, you must install two system dependencies:

  1. The Fastly CLI.
  2. The uv Python package manager.

Additional dependencies, including the Python SDK for compute and build tooling, will be installed and managed by uv in an isolated environment.

Set Up Your Project

For this basic project, we'll use the Flask microframework. We will create our project and add the SDK and build tooling by adding fastly-compute and flask:

$ uv init my-compute-service
...
$ cd my-compute-service
$ uv add fastly-compute flask
...

Write Your Service

uv init automatically creates a main.py file in your project directory. Replace its contents with the following Flask application code:

import platform
from flask import Flask
from fastly_compute.wsgi import WsgiHttpIncoming

app = Flask(__name__)


@app.route("/")
def index():
    version = platform.python_version()
    return f"Hello from Python {version} on Fastly Compute!"

HttpIncoming = WsgiHttpIncoming(app)

Configure Compute Service Entry Point

The fastly-compute-py build tool, provided as part of the fastly-compute package, needs to be told about the module containing the compute service we just created. We can do this by modifying the pyproject.toml as follows:

# Add to end of pyproject.toml
[tool.fastly-compute]
entry = "main"

Then, let's do a quick test to make sure we are able to build a WebAssembly (Wasm) component:

$ uv run fastly-compute-py build
Building Python application for Fastly Compute...
  Entry point: main
  Output: bin/main.wasm
  Resolving Python dependencies...
  Componentizing Python application...
  Composing final WebAssembly module...
  Injecting Fastly metadata...
✓ Build complete: bin/main.wasm

Test and Deploy Your Service Using the Fastly CLI

Now that we have the skeleton of our service, let's test it using the Fastly CLI.

  1. Run fastly compute init

  2. Say yes when warned "The current directory isn't empty." Answer "Other" when it asks for Language.

  3. Add this to the bottom of fastly.toml:

    [scripts]
    build = "uv run fastly-compute-py build"
    

With that in place, we can now run fastly compute serve to test our service locally. When you're ready, you can use the Fastly CLI to deploy the service to the production fleet and perform other actions.

See the examples/ directory for more examples.

Run Some Examples on Your Own Machine

We ship a few simple examples you can run locally to get a taste of what's possible.

Status

Currently supports...

  • Building pure Python into WebAssembly components
  • Creating Python bindings from Fastly's WIT files
  • Hosting web frameworks by adapting Fastly's API to WSGI
  • Hosting non-WSGI applications by writing directly against Fastly's API

Caveats

  • So our memory-snapshotting build process can retain them, all the packages needed at runtime must get imported when your entrypoint (e.g. flask-app.py) is imported. This can happen transitively. But beware of deferred imports like non-top-level ones; if they aren't triggered by importing your entrypoint, they will fail at runtime. (If you have third-party code that uses non-top-level imports, you can ensure they work by importing them at the top level in your own code.)
  • Third-party C extension modules are not yet supported.
  • Our in-Python API may change backward-incompatibly during this beta period.

Contributing

See CONTRIBUTING.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastly_compute-0.1.1.tar.gz (114.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_x86_64.whl (18.7 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ x86-64

fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_aarch64.whl (18.3 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.28+ ARM64

fastly_compute-0.1.1-cp312-abi3-macosx_11_0_arm64.whl (17.0 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

fastly_compute-0.1.1-cp312-abi3-macosx_10_15_x86_64.whl (17.9 MB view details)

Uploaded CPython 3.12+macOS 10.15+ x86-64

File details

Details for the file fastly_compute-0.1.1.tar.gz.

File metadata

  • Download URL: fastly_compute-0.1.1.tar.gz
  • Upload date:
  • Size: 114.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for fastly_compute-0.1.1.tar.gz
Algorithm Hash digest
SHA256 78fa16162dc6975d410ffc0638b5fcf381c341e4a376c5debe2f7b9ce5387a9a
MD5 f7e834591ffc9faab9659bd79c1a1a0a
BLAKE2b-256 a63b745a11a3e661b4bd51f5e23c6c62cd5684505518922067572fde69fc8f0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.1.tar.gz:

Publisher: publish.yml on fastly/compute-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 235fed2ea9b3e9db8865e00364f6b87636ed2bd3e184470f69c1de9b3863ba6a
MD5 0a4ebf256a6ec866aaf280e42c0893bf
BLAKE2b-256 c97ccddd82685aa543cb17cdde5c2778519b0bd3332f9333a19b2dbbcbc249e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on fastly/compute-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6c8db572c0f65bb6dbab2d80b2fdb5e3c4ef30ae4c0dce2bb73d9eb6541a4a9e
MD5 9e89a5b071ba5db466e235e60c1d58b1
BLAKE2b-256 ce434bc242b9864599a297b9998140b2d995e1f1f84822099c3e354e20a90655

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.1-cp312-abi3-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on fastly/compute-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastly_compute-0.1.1-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.1-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 068f5f6e808f666a858aa50ee3edb2aed0a29357962bba0b33b8237b5f0e957e
MD5 74045c31c1973b4190aa68977a1cdb8b
BLAKE2b-256 4a8c180e16b6c307367414389e5b03f19da886208354342773b132ba8c2cb5cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.1-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on fastly/compute-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastly_compute-0.1.1-cp312-abi3-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.1-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 587d0b0a67cd8ba0b893c966214bd091f32ac2137de45e949b39280fd4557e84
MD5 a04dbb708d61033dd4d48ec10938a16d
BLAKE2b-256 0bf2f2ba6f43e068cf8b432202421445024a28102cade6735f1d5c25e7caa691

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.1-cp312-abi3-macosx_10_15_x86_64.whl:

Publisher: publish.yml on fastly/compute-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page