Webflow Python SDK
The Webflow Python Library provides convenient access to the Webflow Data API from applications written in Python. It includes type definitions for all request and response fields, and offers both synchronous and asynchronous clients powered by `httpx`. The library is actively maintained, with regular updates through Fern regeneration, and is currently at version 2.0.0.
Common errors
-
ModuleNotFoundError: No module named 'webflow'
cause The `webflow` library is not installed in the current Python environment.fixRun `pip install webflow` to install the library. -
webflow.core.api_error.ApiError: Invalid API Key
cause The `access_token` provided to the `Webflow` client is invalid, expired, or lacks the necessary permissions.fixVerify that your `WEBFLOW_ACCESS_TOKEN` environment variable or hardcoded token is correct and active. Check the permissions associated with your API token in the Webflow dashboard. Some endpoints require Workspace Tokens, while others require Site Tokens. -
AttributeError: 'Webflow' object has no attribute 'non_existent_method'
cause Attempting to call a method or access an attribute on the `Webflow` client that does not exist or has been renamed due to API changes or SDK regeneration.fixConsult the latest Webflow Python SDK documentation or API reference to ensure you are using the correct method names and object structures, especially after upgrading the library. Refer to the `webflow-python` GitHub README for current usage patterns.
Warnings
- breaking Major version bump to v2.0.0 due to 'Fern Regeneration' may introduce breaking changes in API method signatures, response object structures, or enum values. Review the Webflow API reference documentation for specific changes if upgrading from v1.x.
- breaking In v1.2.0, the return type of `assets.list` was changed from an array (`Asset[]`) to an object. Code expecting an array for this endpoint will break.
- gotcha The SDK relies on `httpcore` for HTTP client functionality. Versions `2.0.0b2` and `2.0.0` included a patch to address a `httpcore` vulnerability. Ensure your environment has the latest patch if you pin `httpcore` or `httpx` versions manually.
- gotcha Incorrect OAuth 2.0 configuration, such as misconfigured `redirect_uri`, `client_id`, or `client_secret`, can lead to authentication failures.
Install
-
pip install webflow
Imports
- Webflow
from webflow.client import Webflow
- AsyncWebflow
from webflow.client import AsyncWebflow
Quickstart
import os
from webflow.client import Webflow
# It's recommended to store your API token securely, e.g., in an environment variable
WEBFLOW_ACCESS_TOKEN = os.environ.get('WEBFLOW_ACCESS_TOKEN', 'YOUR_WEBFLOW_ACCESS_TOKEN')
if not WEBFLOW_ACCESS_TOKEN or WEBFLOW_ACCESS_TOKEN == 'YOUR_WEBFLOW_ACCESS_TOKEN':
print("Warning: Please set the WEBFLOW_ACCESS_TOKEN environment variable or replace 'YOUR_WEBFLOW_ACCESS_TOKEN' with your actual token.")
else:
try:
client = Webflow(access_token=WEBFLOW_ACCESS_TOKEN)
# Example: List all sites
sites_response = client.sites.list()
if sites_response.sites:
print(f"Found {len(sites_response.sites)} site(s):")
for site in sites_response.sites:
print(f"- Site Name: {site.display_name}, ID: {site.id}")
else:
print("No sites found or token lacks sufficient permissions.")
except Exception as e:
print(f"An error occurred: {e}")