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.2.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.2-cp312-abi3-win_amd64.whl (16.3 MB view details)

Uploaded CPython 3.12+Windows x86-64

fastly_compute-0.1.2-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.2-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.2-cp312-abi3-macosx_11_0_arm64.whl (17.0 MB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

fastly_compute-0.1.2-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.2.tar.gz.

File metadata

  • Download URL: fastly_compute-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 0e0bc8dc04a74ff194332d11700776b2d9dfad2ec037871e899654c69d52d019
MD5 839a9b28e9ed66c2b02b530506de6d05
BLAKE2b-256 7f42a8888d6d2b29cd97efe921a07b4c73f101692bcb5f881caa216717c0328a

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.2.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.2-cp312-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.2-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5e0cb6ecdb2b84b0936946e232a131851134ba7892e6ba796a296ec0d2aafff6
MD5 704f01772f3e2da734d737f9a56eb7d1
BLAKE2b-256 f7770b75c814fec3b32d022497283af909709e3477fdcc257e2d9784d0bf4de1

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.2-cp312-abi3-win_amd64.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.2-cp312-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.2-cp312-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 54d961dcec75c7d5b3617cf76b82d9a1b7658695c390edb76870a6cb5c738539
MD5 7895d48a31bad752cf302cbd92dd1d04
BLAKE2b-256 675cd181e4aae7c77b6497df736d161c5759b29b2c5264fed27438663249d1de

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.2-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.2-cp312-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.2-cp312-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 526b81667ef4daa2ab63fd6852e208b8228074a938eb34b2466492788e572359
MD5 3577ac1708da0bc9e22cf14826851045
BLAKE2b-256 6240cc864be3c5c87c0fceeaf2c13943bc9b806e5a7dcaf14f4eb7e75b453fc7

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.2-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.2-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.2-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 260b89ddbae751acb9a235d6c62cafdd61c03a482a1312b21e44c7c746631cb4
MD5 90a038885afcd8033a34606fe8073212
BLAKE2b-256 7f1cd90fd8095f145475d17b2173a2efae8edfb11dfc0cec26ccbe89999099e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.2-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.2-cp312-abi3-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fastly_compute-0.1.2-cp312-abi3-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2a90f472d18f73bb20e548716f8d07dcee1b88bb9359b1a810d00aece687c71e
MD5 115094be7916b99a0c9b04190f453c94
BLAKE2b-256 2f072cc9d207d4a77c6fdccaa6db66a24a71d6fb5450c253a890c46cc45efcf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastly_compute-0.1.2-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