SDKs overview

PageCDN offers software development kits (SDKs) and client libraries designed to facilitate interaction with its content delivery network services. These tools primarily support the automation of asset management, cache purging, and integration into existing development workflows. While PageCDN's core service is often integrated via direct HTML tags for library inclusion or by configuring origin servers, SDKs provide a programmatic layer for more advanced control and automation, particularly useful in continuous integration/continuous deployment (CI/CD) pipelines or custom build scripts.

The primary benefit of using an SDK or client library with PageCDN is the ability to programmatically manage your static assets and optimize content delivery without manual intervention through the web interface. This includes tasks such as uploading new versions of files, invalidating cached content globally, and monitoring usage statistics. For developers building projects that require dynamic updates to static resources, these libraries streamline the process, ensuring that the latest content is served efficiently by the CDN.

Given PageCDN's focus on front-end library hosting and static asset delivery, its SDKs are generally oriented towards developer tooling rather than complex API integrations typical of platforms with extensive transactional APIs. Users can consult the official PageCDN documentation for detailed guides on how to implement these tools effectively in their projects.

Official SDKs by language

PageCDN provides official client libraries that allow developers to interact with the platform's features using common programming languages. These libraries abstract the underlying HTTP API calls, simplifying tasks such as asset management and cache control. The primary focus of these SDKs is to integrate PageCDN's capabilities into backend services, build automation, or custom deployment scripts.

Below is a table detailing the officially supported SDKs and their basic installation methods:

Language Package/Module Installation Command Maturity
Node.js pagecdn-cli npm install -g pagecdn-cli Stable
Python pagecdn-python pip install pagecdn-python Stable

The Node.js CLI tool, pagecdn-cli, is particularly useful for JavaScript ecosystems, allowing direct integration into npm scripts and build processes. The Python library, pagecdn-python, serves similar purposes for Python-based applications and automation. Both aim to provide a consistent interface for managing CDN resources, enabling developers to automate deployments and cache invalidations.

Installation

Installing PageCDN's official SDKs involves using standard package managers for each respective language. These steps assume you have the necessary language runtime and package manager installed on your system.

Node.js CLI

For Node.js environments, the pagecdn-cli package is installed globally using npm. This makes the pagecdn command available from your terminal, allowing you to execute various PageCDN operations directly.

npm install -g pagecdn-cli

After installation, you should configure your API key. This is typically done by running an initialization command or setting an environment variable, as detailed in the PageCDN CLI documentation.

Python Library

For Python projects, the pagecdn-python library can be installed using pip, Python's package installer. It is recommended to install it within a virtual environment to manage dependencies effectively.

pip install pagecdn-python

Once installed, you can import the library into your Python scripts and use its functions to interact with the PageCDN API. Authentication typically involves passing your API key when initializing the client, following the examples in the official PageCDN Python SDK guide.

Quickstart example

This section provides quickstart examples for common tasks using PageCDN's official SDKs. These examples illustrate how to upload a file and purge its cache, which are frequent operations when managing static assets on a CDN.

Node.js CLI Example: Uploading and Purging Cache

First, ensure you have configured your API key. Then, you can use the pagecdn command. This example assumes you have a file named my-asset.js that you wish to upload and then invalidate globally.

# Upload a file to PageCDN
pagecdn upload my-asset.js --path /js/my-asset.js

# Purge the cache for a specific path
pagecdn purge /js/my-asset.js

# Purge all cache for your account (use with caution)
pagecdn purge --all

The upload command sends your local file to PageCDN, making it available via your CDN URL. The purge command ensures that the CDN's edge servers fetch the latest version of the asset. More advanced options for these commands are available in the PageCDN CLI reference.

Python Library Example: Uploading and Purging Cache

This Python script demonstrates how to programmatically upload a file and then purge its cache using the pagecdn-python library.

import os
from pagecdn import PageCDN

# Initialize the PageCDN client with your API key
# It's recommended to load the API key from an environment variable
api_key = os.environ.get("PAGECDN_API_KEY")
if not api_key:
    raise ValueError("PAGECDN_API_KEY environment variable not set.")

client = PageCDN(api_key)

# Define the local file path and the desired CDN path
local_file_path = "./my-asset.css"
cdn_path = "/css/my-asset.css"

try:
    # Upload the file
    with open(local_file_path, "rb") as f:
        upload_response = client.upload_file(f, cdn_path)
        print(f"File uploaded successfully: {upload_response.get('url')}")

    # Purge the cache for the uploaded file
    purge_response = client.purge_cache(cdn_path)
    print(f"Cache purged for {cdn_path}: {purge_response.get('message')}")

except Exception as e:
    print(f"An error occurred: {e}")

This script first initializes the PageCDN client using an API key, then uploads a CSS file, and finally requests a cache purge for that specific CDN path. This automation is valuable for deployment scripts, ensuring that website visitors always receive the most current assets. For further details on the Python library's capabilities, refer to the PageCDN Python SDK documentation.

Community libraries

While PageCDN maintains official SDKs for popular environments like Node.js and Python, the open-source community may develop additional libraries or integrations. These community-contributed tools can range from plugins for specific content management systems (CMS) to integrations with build tools or frameworks not directly covered by official SDKs.

Community libraries often extend functionality or adapt PageCDN's services to niche use cases. Developers looking for integrations with particular platforms or languages beyond the official offerings should explore public repositories on platforms like GitHub or package indexes. These resources can sometimes provide solutions for frameworks such as React, Vue, or Angular, or even static site generators like Jekyll or Hugo, by automating the upload and cache management of generated static assets.

It is important to note that community libraries may vary in terms of maintenance, support, and adherence to the latest PageCDN API specifications. Users should evaluate the stability and active development of such projects before integrating them into production environments. For example, developers using platforms like WordPress often look for CDN integration plugins, which might leverage PageCDN's API indirectly to serve assets. While PageCDN focuses on general static asset delivery, other CDNs like Cloudflare provide specific integration guides for WordPress, illustrating the type of community-driven solutions that can emerge for various platforms.

Before relying on a community library, it is advisable to check its documentation, issue tracker, and recent commit history to gauge its reliability and ensure it meets your project's requirements. Official support and up-to-date features are always guaranteed with PageCDN's own documentation and tools.