Skip to main content

WP Engine API SDK for Python

Project description

WP Engine API Python SDK

A Python SDK for interacting with the WP Engine API, enabling Python developers to programmatically interact with WP Engine services.

Note: This SDK is maintained by Jeremy Pollock (jeremy.pollock@wpengine.com) and is not affiliated with or supported by WP Engine.

Installation

pip install wp-engine-api

Authentication

The SDK supports two methods of authentication:

1. Direct Username/Password

from wp_engine_api import WPEngineAPI

# Initialize with credentials directly
client = WPEngineAPI(
    username="your-username",
    password="your-password"
)

2. Environment Variables

Create a .env file in your project root:

WP_ENGINE_API_USERNAME=your-username
WP_ENGINE_API_PASSWORD=your-password

Or set environment variables directly:

export WP_ENGINE_API_USERNAME=your-username
export WP_ENGINE_API_PASSWORD=your-password

Then initialize the client:

from wp_engine_api import WPEngineAPI

# Initialize using environment variables
client = WPEngineAPI()

Quick Start

from wp_engine_api import WPEngineAPI

# Initialize the client
client = WPEngineAPI(
    username="your-username",
    password="your-password"
)

# List all sites
sites = client.sites.list()
for site in sites:
    print(f"Site: {site.name} ({site.id})")

# Get a specific site
site = client.sites.get("site_id")

# Create a backup
backup = client.backups.create(
    "site_id",
    {
        "description": "Pre-deployment backup",
        "notification_emails": ["admin@example.com"]
    }
)

Features

  • Full coverage of the WP Engine API
  • Type hints for better IDE support
  • Automatic rate limiting
  • Request validation
  • Comprehensive error handling
  • Environment variable support
  • .env file support

Examples

Site Management

# List all sites
sites = client.sites.list()

# Get a specific site
site = client.sites.get("site_id")

# Update a site
updated_site = client.sites.update(
    "site_id",
    {"name": "New Site Name"}
)

Backup Management

# Create a backup
backup = client.backups.create(
    "site_id",
    {
        "description": "Pre-deployment backup",
        "notification_emails": ["admin@example.com"]
    }
)

# List backups
backups = client.backups.list("site_id")

# Get backup status
backup_status = client.backups.get("site_id", "backup_id")

Error Handling

from wp_engine_api.exceptions import (
    AuthenticationError,
    ValidationError,
    ResourceNotFoundError,
    RateLimitError
)

try:
    sites = client.sites.list()
except AuthenticationError:
    print("Invalid credentials")
except ResourceNotFoundError:
    print("Resource not found")
except RateLimitError as e:
    print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
except ValidationError as e:
    print(f"Invalid request: {e}")

Rate Limiting

The SDK includes automatic rate limiting to help you stay within the API's limits. You can configure the rate limiting behavior:

client = WPEngineAPI(
    username="your-username",
    password="your-password",
    max_retries=3,
    retry_delay=1.0
)

Development

Setup Development Environment

  1. Clone the repository:
git clone https://github.com/wpengine/wp-engine-api-python.git
cd wp-engine-api-python
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install development dependencies:
pip install -r requirements.txt

Running Tests

pytest

Generating API Client

The SDK uses OpenAPI Generator to generate the base API client code. To regenerate the client:

python scripts/generate_client.py

License

This project is licensed under the MIT License - see the LICENSE file for details.

Maintainer

This SDK is maintained by Jeremy Pollock (jeremy.pollock@wpengine.com). For any questions, issues, or contributions, please reach out directly.

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

wp_engine_api_python-0.0.2.tar.gz (53.2 kB view details)

Uploaded Source

Built Distribution

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

wp_engine_api_python-0.0.2-py3-none-any.whl (126.8 kB view details)

Uploaded Python 3

File details

Details for the file wp_engine_api_python-0.0.2.tar.gz.

File metadata

  • Download URL: wp_engine_api_python-0.0.2.tar.gz
  • Upload date:
  • Size: 53.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.1

File hashes

Hashes for wp_engine_api_python-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4541990a166b1cac456be5610460e52ec09a58b6bbe0bbeb80afa274fe86d7cb
MD5 929b2d4683bf8587f271bafa6204bc39
BLAKE2b-256 b925579e546cc697ae997fc3b2dd70a167893e7353a790aebe6ed03f35695c67

See more details on using hashes here.

File details

Details for the file wp_engine_api_python-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for wp_engine_api_python-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e16938ec0d1ac8546c7d54976f1998ebc58f22022ecbdadf631a902a6822a47f
MD5 583968edc59fa89c6db3ba67e5f557da
BLAKE2b-256 6e5e774c23a056fec3c23820ac6002c62f5ddc2ef0a859279ede2100ce89dfa4

See more details on using hashes here.

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