Fastly Python API Client
raw JSON → 13.1.0 verified Fri May 01 auth: no python
Official Python client for the Fastly API. Version 13.1.0 supports all Fastly services (CDN, compute, logging, etc). Requires Python >=3.6. Actively maintained with monthly releases.
pip install fastly Common errors
error TypeError: __init__() takes 1 positional argument but 2 were given ↓
cause Using positional argument for api_token instead of keyword argument in Fastly constructor (v12+).
fix
Fastly(api_token='your_token')
error fastly.exceptions.FastlyError: Missing required parameter 'service_id' ↓
cause Service ID not provided when calling an endpoint that requires it.
fix
Pass service_id as keyword argument: client.service.get(service_id='your_id')
Warnings
breaking In v12+, the client no longer accepts positional arguments for api_token; must use keyword argument. ↓
fix Use Fastly(api_token='your_token') instead of Fastly('your_token').
gotcha API token must be set via environment variable FASTLY_API_TOKEN or passed directly; if neither, client issues unauthenticated requests. ↓
fix Always provide api_token either via env var or constructor arg.
deprecated The method _request() is deprecated since v11; use client.request() instead. ↓
fix Replace client._request(...) with client.request(...).
Imports
- Fastly wrong
import fastlycorrectfrom fastly import Fastly - Service wrong
from fastly import Servicecorrectfrom fastly.services import Service
Quickstart
from fastly import Fastly
api_token = os.environ.get('FASTLY_API_TOKEN', '')
client = Fastly(api_token=api_token)
print(client.services.list())