Welcome to the examples directory! Each script here is a runnable, real-world demonstration of how to use the atomic-sdk to interact with a specific part of the WP.cloud Atomic API.
The scripts are numbered to suggest a logical order for learning the API, starting from basic checks and moving to more complex operations.
Before running any examples, you must set up your environment.
Ensure you have installed the SDK in editable mode with the [dev] dependencies, which includes python-dotenv. From the project root:
pip install -e ".[dev]"This project uses a .env file to securely manage your API credentials.
- Copy the example file:
cp .env.example .env
- Edit the new
.envfile and add your credentials:# Your main Atomic API Key ATOMIC_API_KEY="key_goes_here" # Your client identifier string (e.g., "myhostingco") ATOMIC_CLIENT_ID="your_client_id_goes_here" # The domain name you will use for testing the site examples SITE_DOMAIN="sdk-test.yourdomain.com"
All example scripts will automatically load these variables.
Here is a recommended workflow for using the SDK, following the numbered example scripts.
- Goal: Confirm your API key is valid and you can reach the platform.
- Run:
python examples/utility/01_test_api_connectivity.py - Shows:
- How to initialize the
AtomicClient. - Using the
client.utility.test_status()endpoint for a basic success (200 OK) check.
- How to initialize the
- Goal: Set up account-wide configurations, such as a webhook URL for receiving notifications.
- Run:
python examples/client/01_manage_client_meta.py - Shows:
- Getting a client-level metadata value using
client.client.get_meta(). - Handling the expected
NotFoundErrorif the key has never been set. - Setting up webhook via
client.client.set_meta(). - Verifying the change and optional prompt for cleaning it up via
client.client.remove_meta().
- Getting a client-level metadata value using
- Goal: Before creating a site, ensure the domain is available and find out which IPs to point your DNS to.
- Run:
python examples/sites/00_check_can_host_domain.py - Shows:
- Checking if a domain is already in use on the platform with
client.sites.check_can_host_domain(). - Retrieving the target IP addresses for your DNS A records using
client.sites.get_ips(). - Comparing the required IPs with the domain's current DNS records.
- Checking if a domain is already in use on the platform with
- Goal: Provision a new site for testing and confirm its settings were applied correctly.
- Run:
python examples/sites/01_create_and_get_site.py - Shows:
- Checking if a site already exists with
client.sites.get()to prevent errors. - Creating a new site with
client.sites.create(), specifying parameters likephp_version,space_quota, and custommetadata. - Using a helper function to poll the returned
Jobobject until the creation is successful. - Retrieving the full site details with
client.sites.get(extra=True)and verifying all settings.
- Checking if a site already exists with
Once your site exists, you can perform various management tasks.
- Run:
python examples/sites/02_manage_software.py - Shows:
- Defining a dictionary of software actions (e.g., install a theme, install a plugin).
- Executing the changes with
client.sites.manage_software()and waiting for the job to complete. - Running a subsequent job to activate the newly installed software.
- Run:
python examples/sites/03_manage_aliases.py - Shows:
- Adding a secondary domain to a site with
client.sites.add_alias(). - Verifying the addition by retrieving all aliases with
client.sites.list_aliases(). - Removing the alias with
client.sites.remove_alias()and verifying the removal.
- Adding a secondary domain to a site with
- Run:
python examples/sites/04_manage_metadata.py - Shows:
- Reading a property directly from the main
Siteobject (site.wp_version). - Reading specific metadata keys like
space_quotawithclient.sites.get_meta(). - Updating a metadata key (
default_php_conns) withclient.sites.update_meta(). - Verifying the change and reverting it in a
finallyblock for cleanup.
- Reading a property directly from the main
- Run:
python examples/sites/05_manage_ssl.py - Shows:
- Fetching detailed SSL certificate information with
client.sites.get_ssl_info(). - Retrying a failed SSL provisioning attempt with
client.sites.retry_ssl_provisioning(). - Managing HSTS settings like
includeSubDomainswithclient.sites.set_hsts_subdomain().
- Fetching detailed SSL certificate information with
- Run:
python examples/custom_certificates/01_install_certificate.py --cert <file> --key <file> - Shows:
- Validating a certificate pair with
client.custom_certificates.validate(). - Staging and activating in one step with
client.custom_certificates.stage_and_activate().
- Validating a certificate pair with
- Run:
python examples/custom_certificates/02_manage_certificate.py list - Shows:
- Listing all certificates for a site.
- Getting the currently active certificate with
activesubcommand. - Subcommands for
deactivateanddeleteto manage specific certificate IDs.
- Run:
python examples/sites/06_get_phpmyadmin_url.py - Shows:
- Generating a secure, time-limited, single-use login URL for phpMyAdmin using
client.sites.get_phpmyadmin_url().
- Generating a secure, time-limited, single-use login URL for phpMyAdmin using
Learn how to create, list, download, and delete backups. Note that on-demand backup creation is a "fire-and-forget" operation; the API does not provide a way to poll its status.
- Run:
python examples/backups/01_create_and_list_backups.py - Shows:
- Listing all existing backups for a site with
client.backups.list(). - Requesting a new on-demand database backup with
client.backups.create(backup_type="db"). - Accessing the
request_idfrom the returnedBackupJobobject.
- Listing all existing backups for a site with
- Run:
python examples/backups/02_get_and_download_backup.py - Shows:
- Finding the most recent backup by sorting the list.
- Getting specific metadata for that backup with
client.backups.info(). - Downloading the raw backup file content as bytes with
client.backups.get(). - Saving the downloaded content to a local file.
- Run:
python examples/backups/99_delete_ondemand_backup.py - Shows:
- Finding a specific on-demand backup to delete from the list.
- Requesting its deletion with
client.backups.delete().
Learn the different methods for granting SSH and SFTP access.
- Run:
python examples/ssh/01_manage_site_ssh_users.py - Shows: How to add, list, update, and remove a standard SFTP/SSH user for a single site using password authentication.
- Run:
python examples/ssh/02_manage_public_keys.py - Shows: How to create a more secure, key-based user for a single site and disable password login.
- Run:
python examples/ssh/03_disconnect_users.py - Shows: How to forcefully terminate all active SSH and SFTP sessions for a site with
client.ssh.disconnect_all_users().
- Run:
python examples/ssh/04_manage_client_keys.py - Shows:
- Adding a powerful, account-wide key for automation using
client.ssh.add_client_key(). - The correct connection method for these keys:
<site-id>@client-ssh.atomicsites.net.
- Adding a powerful, account-wide key for automation using
- Run:
python examples/ssh/05_manage_aliasable_keys.py - Shows:
- Using the
client.ssh.alias_pkeysub-client to create a named, reusable public key (alias-pkey). - Updating the alias to point to a new public key.
- Verifying the key's fingerprint after each change.
- Using the
Learn how to query the powerful metrics endpoint. Remember that metrics have an ingestion delay, so it's best to query for a time window that ended ~30 minutes ago.
- Run:
python examples/metrics/01_query_site_metrics.py - Shows: A general overview of querying, including requests by HTTP status, average PHP response time, and summarized bandwidth.
- Run:
python examples/metrics/02_visitor_metrics.py - Shows: How to segment traffic by visitor country code, device type, browser, and operating system.
- Run:
python examples/metrics/03_php_metrics.py - Shows: How to check PHP performance, including average worker usage, CPU time, and request burst/limit percentages.
- Run:
python examples/metrics/04_uniques_and_views_metrics.py - Shows: How to query for daily aggregated unique visitors and page views.
- Run:
python examples/metrics/05_mysql_metrics.py - Shows: How to monitor database performance, including concurrent connections, slow queries, and rows read/written.
- Run:
python examples/metrics/06_cgroup_metrics.py - Shows: How to inspect low-level container resource usage, specifically CPU usage per second.
Execute an operation across many or all of your sites at once.
- Run:
python examples/tasks/01_run_bulk_software_task.py - Shows: Creating a task with
client.tasks.create(task_type="software")to install a plugin on all sites and monitoring its progress.
- Run:
python examples/tasks/02_run_bulk_find_files_task.py - Shows: Creating a
site-find-filestask to locate a specific file pattern across all sites.
- Run:
python examples/tasks/03_run_bulk_wp_cli_task.py - Shows: Creating a
run-wp-cli-commandtask to execute a WP-CLI command on all sites and get results via webhook.
- Run:
python examples/edge_cache/01_manage_cache.py - Shows: Using the
client.edge_cacheclient to check status, turn caching on/off, purge, and manage defensive (DDoS) mode.
- Run:
python examples/servers/01_get_server_info.py - Shows: Using
client.serversto list available datacenters and supported PHP versions on the platform.
- Run:
python examples/email/01_list_blocked_domains.py - Shows: Using
client.emailto retrieve a list of domains that have been blocked from sending email.
- Goal: Delete the test site created in the examples.
- Run:
python examples/sites/99_delete_site.py - Shows: A script that includes a safety prompt and then permanently deletes the test site from your account, waiting for the deletion job to complete.