Purging PyPi CDN caches after package release

Immediately after releasing a Python package, it can happen that PyPi's CDN caches aren't up to date yet, and the package index doesn't list the new version yet, causing buildout to not find the new package version.

This is dependent on which exact backend of the package index is being hit - there's some DNS load balancing in place, and depending on which backend you hit, you might see different cached states:

$ dig +short pypi.org
151.101.128.223
151.101.0.223
151.101.192.223
151.101.64.223

However, it seems you can manually purge their Varnish caches. This snippet will look up all the IPs for pypi.org, and send a PURGE request to the package index listing for the given package (replace the package name in EGGNAME according to your needs - make sure to use the spelling with the dash (-) instead of dots though).

EGGNAME="plone-rest"; (for ip in $(dig +short pypi.org); do url="https://$ip/simple/${EGGNAME}/"; echo "Purging $url..."; curl -L -H 'Host: pypi.python.org' --insecure -XPURGE $url; done)

So if you're having issues with a just released package version not being visible, you might want to try this.

Here's my old bash snippet for that - not yet updated for the new infra changes:

function pypi-versions () {
records=()
records+=($(dig CNAME +short pypi.python.org))
records+=($(dig A +short pypi.python.org))
records+=($(dig AAAA +short pypi.python.org))
records=($(printf '%s\n' "${records[@]}" | sort -u))

for address in "${records[@]}"
do
        URL="https://$address/simple/$1/"
        curl -s -H 'Host: pypi.python.org' --insecure -XPURGE "$URL" &>/dev/null
done

URL="https://pypi.python.org/simple/$1/"
curl -s -L "$URL" | pup 'a text{}' | gsort -V | less
}

For macOS, depends on pup, depends on gnu coreutils.