Metadata-Version: 2.1
Name: wp-engine-api-python
Version: 0.0.2
Summary: WP Engine API SDK for Python
Home-page: https://github.com/jpollock/wp-engine-api-python
Author: Jeremy Pollock
Author-email: Jeremy Pollock <jeremy.pollock@wpengine.com>
License: MIT
Project-URL: Documentation, https://wpengineapi.com/docs
Project-URL: Source, https://github.com/jpollock/wp-engine-api-python
Project-URL: Bug Reports, https://github.com/jpollock/wp-engine-api-python/issues
Keywords: wpengine,wordpress,api,sdk
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.0
Requires-Dist: python-dateutil>=2.8.0
Requires-Dist: urllib3>=1.26.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: typing-extensions>=4.0.0
Requires-Dist: python-dotenv>=1.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: isort>=5.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"

# 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

```bash
pip install wp-engine-api
```

## Authentication

The SDK supports two methods of authentication:

### 1. Direct Username/Password

```python
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:
```bash
WP_ENGINE_API_USERNAME=your-username
WP_ENGINE_API_PASSWORD=your-password
```

Or set environment variables directly:
```bash
export WP_ENGINE_API_USERNAME=your-username
export WP_ENGINE_API_PASSWORD=your-password
```

Then initialize the client:
```python
from wp_engine_api import WPEngineAPI

# Initialize using environment variables
client = WPEngineAPI()
```

## Quick Start

```python
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

```python
# 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

```python
# 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

```python
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:

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

## Development

### Setup Development Environment

1. Clone the repository:
```bash
git clone https://github.com/wpengine/wp-engine-api-python.git
cd wp-engine-api-python
```

2. Create a virtual environment:
```bash
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
```

3. Install development dependencies:
```bash
pip install -r requirements.txt
```

### Running Tests

```bash
pytest
```

### Generating API Client

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

```bash
python scripts/generate_client.py
```

## License

This project is licensed under the MIT License - see the [LICENSE](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.
