pypi /

import urlparse

import requests

def purge_fastly_tags(domain, api_key, service_id, tags):
    session = requests.session()
    headers = {"X-Fastly-Key": api_key, "Accept": "application/json"}

    all_tags = set(tags)
    purges = {}

    for tag in set(all_tags):
        # Build the URL
        url_path = "/service/%s/purge/%s" % (service_id, tag)
        url = urlparse.urljoin(domain, url_path)

        # Issue the Purge
        resp =, headers=headers)

        # Store the Purge ID so we can track it later
        purges[tag] = resp.json()["id"]

    # for tag, purge_id in purges.iteritems():
    #     # Ensure that the purge completed successfully
    #     url = urlparse.urljoin(domain, "/purge")
    #     status = session.get(url, params={"id": purge_id})
    #     status.raise_for_status()

    #     # If the purge completely successfully remove the tag from
    #     #   our list.
    #     if status.json().get("results", {}).get("complete", None):
    #         all_tags.remove(tag)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.